Prevent Unnecessary Searches
Prevent Unnecessary Searches
Section titled “Prevent Unnecessary Searches”The Problem
Section titled “The Problem”Claude Desktop tends to search automatically even when the user can provide the location directly:
User: "Modify the ProcessData function in main.go"Agent: "Let me search where ProcessData is defined..." [Runs search_files unnecessarily]Result: Wasted tokens and time when the user already knows the location.
The Solution: Ask First, Search Later
Section titled “The Solution: Ask First, Search Later”Before running any search, ask the user if they know the location:
User: "Modify the ProcessData function"Agent: "Do you know what file ProcessData is in? If not, I can search for it."User: "main.go, around lines 150-180"Agent: [Reads those lines directly and edits]Use Cases
Section titled “Use Cases”Case 1: User mentions a specific file
Section titled “Case 1: User mentions a specific file”User: "Modify ProcessData in main.go"Agent: "Do you know approximately which line? If not, I can search for it."Case 2: User mentions a function but not the file
Section titled “Case 2: User mentions a function but not the file”User: "Modify the ProcessData function"Agent: "Which file is ProcessData in?"User: "main.go"Agent: "Do you know the line number? If not, I can search for it."Case 3: User clearly does not know
Section titled “Case 3: User clearly does not know”User: "I don't know where ProcessData is, but I need to modify it"Agent: [Runs search_files]Case 4: User gives a full path
Section titled “Case 4: User gives a full path”User: "/home/user/project/src/main.go line 150"Agent: [Reads directly, does not search]Instructions for AI Agents
Section titled “Instructions for AI Agents”Add this to your system prompt or custom instructions:
IMPORTANT: Avoid Unnecessary Searches
BEFORE executing any search (search_files, etc.):
1. Check if the user already provided the file path2. Check if the user provided line numbers3. If unsure, ask first: "Do you know where X is located?"
ONLY search if:- The user explicitly says they don't know where it is- The user asks to "find" or "search for" something- The user clearly does not have the information
Benefit: Up to 90% token savings on avoidable searchesToken Savings
Section titled “Token Savings”| Scenario | With automatic search | Asking first | Savings |
|---|---|---|---|
| User knows location | 2,000 tokens | 200 tokens | 90% |
| User knows file | 1,500 tokens | 500 tokens | 67% |
| User does not know | 2,000 tokens | 2,000 tokens | 0% (search required) |
For Agent Developers
Section titled “For Agent Developers”If you are building your own agent, add this logic:
def before_search(query: str, context: dict): """Check if search is necessary before executing"""
user_message = context.get("user_message", "")
# Check if user provided an explicit path if has_file_path(user_message): return {"skip_search": True, "reason": "User provided path"}
# Check if user provided line numbers if has_line_numbers(user_message): return {"skip_search": True, "reason": "User provided lines"}
# Ask before searching if is_exploratory(query): return {"should_ask_first": True}
return {"proceed_with_search": True}Tips for Users
Section titled “Tips for Users”Being specific in your request eliminates unnecessary searches:
Vague (triggers search):
"Modify the ProcessData function"Specific (no search needed):
"In main.go line 150, modify ProcessData to use async"Semi-specific (reduced search):
"In main.go, modify ProcessData (search for the line if you can't see it)"Practical Examples
Section titled “Practical Examples”Example 1: Experienced user
Section titled “Example 1: Experienced user”User: "In core/engine.go line 245, change timeout from 30 to 60"Agent: [Reads line 245, edits directly]Tokens: ~300Example 2: User needs help
Section titled “Example 2: User needs help”User: "Change the timeout in engine.go"Agent: "Do you know which line the timeout is on?"User: "No"Agent: [Searches "timeout" in engine.go, finds line 245]Tokens: ~1,200Common Mistakes
Section titled “Common Mistakes”Mistake 1: Searching without asking
Section titled “Mistake 1: Searching without asking”User: "Modify X"Agent: "Let me search for X..." [unnecessary]Fix: Ask first if the user knows the location.
Mistake 2: Asking when the user explicitly requested a search
Section titled “Mistake 2: Asking when the user explicitly requested a search”User: "Search for all functions that use 'timeout'"Agent: "Which file?" [unnecessary]Fix: If the user explicitly requests a search, run it directly.
Mistake 3: Ignoring context from earlier in the conversation
Section titled “Mistake 3: Ignoring context from earlier in the conversation”User: "Now modify that function" [reference to previous message]Agent: [Searches again] [unnecessary]Fix: Use the conversation context already available.
Summary
Section titled “Summary”In one sentence: Ask the user if they know the location before searching automatically.
Three steps:
- Before
search_files, ask: “Do you know where X is?” - Only search if the user says “I don’t know” or explicitly requests a search.
- This saves up to 90% of tokens on avoidable searches.
Version: 1.0.0 Date: February 2026