Skip to content

Claude Code Tool Search: Grep vs Glob, Read, Explore and MCP

Grep finds text inside files; Glob finds files by name. On macOS, Linux and WSL, Claude Code 2.1.117+ runs both as grep and find in Bash; Windows keeps the tools.

•••22 min read•Claude Code
Claude Code Grep vs Glob: Grep finds text inside files, Glob matches file names and paths; since 2.1.117 macOS, Linux and WSL run grep and find in Bash

Grep searches what is inside files; Glob matches file names and paths. Ask "which file calls handleAuth?" and the answer comes from Grep. Ask "where are all the *.test.ts files?" and the answer comes from Glob. One thing changed in 2026: since Claude Code 2.1.117, macOS, Linux and WSL sessions no longer get the Glob and Grep tools by default. Claude runs find and grep through the Bash tool instead, backed by embedded bfs and ugrep. Windows keeps both tools. Claude Code's other search tools are Read for opening files, the Explore subagent for multi-step exploration, and MCP tool search (the ToolSearch tool) for loading MCP tools on demand. Each is covered below, with the parameters and limits documented as of November 15, 2026.

Grep vs Glob in Claude Code: Contents vs File Paths

Grep answers "where does this text appear?"; Glob answers "which files match this name?". Glob never opens a file, so it cannot find a function caller. Grep reads file contents, so it cannot list files that match a naming pattern unless the pattern also appears inside them. The Claude Code tools reference puts it in one line: "Where Glob finds files by name, Grep finds lines inside them."

GlobGrepRead
SearchesFile names and pathsText inside filesOne file you already know
Pattern typeGlob wildcards: *, **, {json,yaml}Regex, in ripgrep syntax (not POSIX grep)None, takes a path
Main inputspattern, pathpattern, path, glob, type, output_modefile_path, offset, limit, pages
ReturnsUp to 100 paths, newest firstFile paths by default; matching lines or counts on requestFile content, image, PDF pages or notebook cells
.gitignoreNot respected by defaultRespectedReads any path it is given
Use it for"Find every *.test.ts", "where is the config file?""Who calls handleAuth?", "where is this error string thrown?"Reading the file Glob or Grep pointed to

The same job done with Glob and with Grep

Two tasks show where each tool stops working:

# Task 1: find all test files (a question about names)
Glob(pattern="**/*.test.ts")
# Grep cannot do this unless every test file happens to contain a shared string

# Task 2: find every caller of handleAuth (a question about contents)
Grep(pattern="handleAuth\\(", output_mode="content", "-n"=true)
# Glob cannot do this: no file path contains the caller

Most real searches chain them: Glob or Grep narrows the list, then Read opens one or two files. That keeps the context small, because Glob and Grep return paths or single lines instead of whole files.

Grep's own glob parameter is a file filter, not the Glob tool

The Grep tool has a parameter called glob, and it causes most of the confusion. Grep(pattern="FIXME", glob="**/*.tsx") still searches file contents; the glob value only limits which files are opened, the same way type="py" limits the search to Python files. The Glob tool, by contrast, returns file paths and never looks inside them. If a file filter alone answers your question, use Glob; if you need a match inside those files, use Grep with glob or type.

How Glob and Grep relate to grep, find and shell wildcards

The names come from the Unix tools, and the split is the same: shell globbing (src/*.py) matches file names, while the grep command matches text inside files. The symbols also mean different things. In a glob, * matches any run of characters and . is a literal dot; in a regex, * repeats the previous character and . matches any character. That is why *.ts is a valid Glob pattern but a poor Grep pattern, where you would write \.ts$ instead.

The Claude Code tools are not the shell commands, though. The Grep tool is built on ripgrep and uses ripgrep's regex syntax, so \w+ and (a|b)? work without extra flags. Glob behaves like a recursive find -name with ** support, sorted by modification time.

Are Glob and Grep Still Tools in Claude Code? Not by Default on macOS and Linux

On macOS, Linux and WSL, a current Claude Code session has no Glob or Grep tool unless you ask for them. The 2.1.117 changelog entry says: "Native builds on macOS and Linux: the Glob and Grep tools are replaced by embedded bfs and ugrep available through the Bash tool". The tools reference now marks both tools "Absent by default on macOS, Linux, and WSL" and explains that the searches "reach your hooks and permission rules as Bash calls". On Windows both tools are still part of the default set.

The change confused many users, because for months the docs still listed both tools with no caveat (issue #51781, April 2026). A Claude Code maintainer called the missing tools "intended behavior, not a tool-search bug" in issue #52121 (August 2026). The changelog says npm-installed builds were unchanged, but a maintainer explained in issue #86229 that the npm package started shipping the same native binary around version 2.1.154, so installing through npm no longer keeps the old tools on macOS or Linux.

Your setup (Claude Code 2.1.117 or later)Content search runs asFile-name search runs as
WindowsGrep tool (ripgrep)Glob tool
macOS, Linux, WSL, defaultgrep in Bash → embedded ugrepfind in Bash → embedded bfs
macOS, Linux, WSL, started with --allowedTools naming Glob or GrepGrep toolGlob tool
Bash denied or removed (--disallowedTools, --restricted)Grep toolGlob tool
A subagent whose tools list includes Glob or Grep but not BashGrep tool (that subagent only)Glob tool (that subagent only)

How to check what your session uses

Ask Claude to run type grep and grep --version. In a Claude Code 2.1.325 desktop session on macOS on November 15, 2026, type grep reported a shell function installed by Claude Code's shell snapshot, grep --version printed ugrep 7.8.4, and find --version printed bfs 4.1.1. That session's tool list contained Bash, Read, Edit, Write and Agent, but no Glob or Grep. It is one environment, so treat it as an example of what to look for rather than a guarantee for every install.

The regex trap when grep runs in Bash

The Grep tool and Bash grep read patterns differently. In the session above, Claude's grep wrapper started ugrep with -G, which means basic regular expressions: +, ?, (, ) and | are literal characters unless you add -E. The same pattern that works in the Grep tool returned nothing in Bash:

bash
# Works in the Grep tool and in rg (ripgrep syntax)
rg -n 'export (async )?function get[A-Z]\w+' src/lib

# Returns nothing in Claude's Bash grep: basic regex treats ( ) ? + as text
grep -rn 'export (async )?function get[A-Z]\w+' src/lib

# Works: -E switches to extended regex
grep -rnE 'export (async )?function get[A-Z]\w+' src/lib

The same wrapper also added --ignore-files, --hidden, -I (skip binary files) and excluded .git, .svn, .hg and similar folders. If a search Claude runs in Bash finds nothing you know is there, ask for -E, a --include='*.ts' filter instead of --type, or a direct rg call when ripgrep is installed.

How to get the Glob and Grep tools back

There is no environment variable or settings key for this. The tools reference lists three routes that do work on macOS, Linux and WSL:

  1. Start the session with claude --allowedTools "Glob" "Grep" (naming either one restores both), or list the exact tool set with --tools. An allow rule in settings.json does not have this effect.
  2. Remove Bash from the session with a deny rule, --disallowedTools Bash or --restricted.
  3. Give a subagent tools: Glob, Grep, Read without Bash in its definition. Only that subagent gets them, unless you run it as the main agent with --agent.

The Bash route is also why hooks written for Grep or Glob stopped firing for many users: on default macOS and Linux sessions the searches arrive as Bash calls, so a PreToolUse hook has to match Bash and inspect the command. A request for an opt-out from the embedded grep and find wrappers, issue #69736, was still open on November 15, 2026.

Key Takeaways

Before diving into the details, here are the essential points you need to know about Claude Code's search tools:

  • Glob finds files by name pattern (**/*.ts, src/**/*.tsx) and returns up to 100 paths sorted by modification time
  • Grep is built on ripgrep and searches file contents with regex; its default output is a list of matching files
  • On macOS, Linux and WSL, Claude Code 2.1.117 and later replaces both with find (embedded bfs) and grep (embedded ugrep) in Bash; Windows keeps the tools
  • Read is your tool for viewing file contents, supporting images, PDFs, and Jupyter notebooks
  • The Explore subagent, launched through the Agent tool (formerly Task), handles multi-step exploration in its own context window
  • MCP tool search is on by default in Claude Code; on the Claude API, Anthropic measured an 85% cut in tool-definition tokens (~77K to ~8.7K) in its November 2025 test

The key principle: ask a name question with Glob or find, a content question with Grep or grep, open the result with Read, hand open-ended exploration to Explore, and leave MCP tool search on when you connect many MCP servers.

Understanding Claude Code Search Tools

Claude Code is Anthropic's terminal-native AI coding assistant that understands your entire codebase. Unlike traditional code editors that require manual file navigation, Claude Code uses search tools to find what it needs before it reads or edits anything. Knowing which tool it reaches for helps you phrase requests and read its transcript.

The search tools fall into two groups. The first group finds and reads code: Glob, Grep and Read on Windows, and find, grep and Read on default macOS, Linux and WSL sessions. These handle the majority of everyday search tasks—finding files, searching content, and reading file contents—and need no configuration.

The second group handles larger jobs. The Agent tool (called Task before version 2.1.63) launches subagents such as Explore, which run many searches in a separate context window and return a summary. Tool search, exposed as the ToolSearch tool, loads MCP tool definitions only when Claude needs them, so a large set of MCP servers does not fill the context window before you start.

Why several tools instead of one universal search? Each answers a different question. Glob returns paths sorted by modification time, which puts recently changed files first. Grep uses ripgrep, which searches thousands of files quickly and skips gitignored ones. Read opens text, images, PDFs and notebooks.

When you ask Claude Code a question like "where is the authentication logic?", it selects the tools itself. Naming the search still helps: "search file contents for calls to handleAuth" leads to one targeted content search, while "look for authentication code" may take several rounds of searching and reading.

The tools also differ in how much context they consume. Glob and Grep return file paths or matched lines without loading entire files. Read loads file contents, which is necessary for understanding code but uses more context. Subagents work in their own context window and return only their summary. Tool search keeps MCP tool definitions out of the context until they are needed.

Glob, Grep, Read, Agent and ToolSearch: Parameter Reference

This section lists the parameters each tool accepts. Parameter names come from the Agent SDK type definitions; behavior comes from the tools reference. On default macOS, Linux and WSL sessions, Glob and Grep apply only when you restore them as described above.

Where a Claude Code search runs by platform since 2.1.117: on Windows the Grep tool and the Glob tool; on default macOS, Linux and WSL sessions grep in Bash with embedded ugrep and find in Bash with embedded bfs

Glob: File Pattern Matching

Glob matches file paths against a pattern and returns the matches sorted by modification time, capped at 100 files. When the cap is hit, Claude sees a truncation flag and can narrow the pattern.

Parameters:

ParameterRequiredDescription
patternYesGlob pattern like **/*.ts or src/**/*.tsx
pathNoDirectory to search in (defaults to current directory)

Common patterns:

**/*.ts          # All TypeScript files
src/**/*.tsx     # React components in src
**/test*.js      # Test files anywhere
*.{json,yaml}    # JSON and YAML files in the current directory
config.*         # Config files with any extension

Glob does not respect .gitignore by default, so it also returns ignored files such as build output. Set CLAUDE_CODE_GLOB_NO_IGNORE=false before launching Claude Code to make it skip them. Its search time limit defaults to 20 seconds (60 on WSL) and can be changed with CLAUDE_CODE_GLOB_TIMEOUT_SECONDS.

When to use Glob: Finding files by extension, locating configuration files, identifying test files, or searching for files matching a naming convention.

Grep: Content Search with Ripgrep

Grep searches file contents with regex and is built on ripgrep, using ripgrep's syntax rather than POSIX grep. Metacharacters need escaping: finding interface{} takes the pattern interface\{\}.

Parameters:

ParameterRequiredDescription
patternYesRegex pattern to search for
pathNoFile or directory to search
globNoOnly search files whose path matches this pattern (e.g., *.js); it filters files, it does not list them
typeNoFile type filter (js, py, rust, etc.)
output_modeNofiles_with_matches (default), content, or count
-iNoCase-insensitive search
-nNoShow line numbers in content mode
-A, -B, -C / contextNoContext lines after/before/both
-oNoPrint only the matched part (needs content mode)
head_limit, offsetNoReturn only the first N entries, or skip N entries first
multilineNoLet a pattern match across line breaks

Example searches:

pattern: "function\\s+handle\\w+"     # Functions starting with "handle"
pattern: "TODO|FIXME"                  # Find todo comments
pattern: "import.*from ['\"]react"    # React imports

Grep skips gitignored files; to search one, Claude passes its path directly. A pattern that ripgrep rejects now returns ripgrep's error message; before version 2.1.208 it was reported as No files found, so an empty result from an older version did not prove the text was absent. In count mode the total covers every match even when head_limit trims the per-file list.

When to use Grep: Searching for function definitions, finding where variables are used, locating FIXME comments, or identifying import statements.

Read: File Reading

Read retrieves file contents from the local filesystem. It supports various file formats including images, PDFs, and Jupyter notebooks.

Parameters:

ParameterRequiredDescription
file_pathYesAbsolute path to the file
offsetNoStarting line number
limitNoNumber of lines to read
pagesNoPage range for PDFs, such as "1-5"

Supported formats:

  • Text files (any programming language)
  • Images (PNG, JPEG, GIF, WebP) - displayed visually
  • PDF files - short PDFs whole; longer than 10 pages in ranges of up to 20 pages
  • Jupyter notebooks (.ipynb) - cells with outputs

By default one Read call returns at most 25,000 tokens and refuses a whole file over 256 KB, so large files are read in sections with offset and limit.

When to use Read: Viewing specific file contents, examining configuration files, reading documentation, or analyzing notebook outputs.

The tool that launches Explore is now called Agent: the subagents docs say "In version 2.1.63, the Task tool was renamed to Agent", and Task(...) still works as an alias in settings and agent definitions. Explore is the built-in read-only subagent "optimized for searching and analyzing codebases". It can search and read but cannot write or edit, and it returns a summary instead of every search result.

Parameters (Agent tool):

ParameterRequiredDescription
descriptionYesShort description (3-5 words)
promptYesWhat the subagent should find or answer
subagent_typeNo"Explore" for search tasks; "Plan" and "general-purpose" are the other built-ins
model, effortNoOverride the subagent's model or effort
run_in_backgroundNoRun without blocking the main conversation
isolationNo"worktree" or "remote"

Example usage:

json
{
  "prompt": "Find all API endpoints and their authentication requirements",
  "subagent_type": "Explore",
  "description": "Explore API auth"
}

Claude picks a thoroughness level when it calls Explore: quick for targeted lookups, medium for balanced exploration, or very thorough for comprehensive analysis. Explore ran on Haiku when it was introduced; since version 2.1.198 it uses the main conversation's model.

When to use Task/Explore: Understanding how a feature works, investigating unfamiliar codebases, finding all related files for a concept, or answering architectural questions.

Tool Search: MCP Tool Discovery

Tool search lets Claude work with hundreds or thousands of tools by loading their definitions on demand. Instead of placing every tool definition in the context at the start, Claude sees the tool names, searches when it needs a capability, and loads only the matching definitions.

Key facts:

  • In Claude Code it is on by default and appears as the ToolSearch tool; MCP tools are deferred and discovered on demand
  • On the Claude API it is the tool search tool, with two variants: regex (tool_search_tool_regex_20251119) and BM25 natural-language search (tool_search_tool_bm25_20251119)
  • The API accepts up to 10,000 deferred tools per request, and each search returns up to 5 matching tools by default
  • Anthropic measured tool-definition tokens falling from ~77K to ~8.7K, an 85% reduction, in its November 2025 test

In that same internal test on MCP evaluations, Claude Opus 4 went from 49% to 74% accuracy and Claude Opus 4.5 from 79.5% to 88.1% with tool search enabled. Anthropic has not published equivalent figures for newer models.

When to use Tool Search: Working with multiple MCP servers (Jira, Slack, GitHub, databases), managing large tool libraries, or optimizing context window usage.

How to Choose the Right Tool

Selecting the right search tool can significantly impact your productivity. This decision guide helps you quickly identify the best tool for any scenario.

Which Claude Code search tool answers which question: Grep for text inside files, Glob for file names and paths, Read for a known path, Explore for multi-step questions, tool search for many MCP servers

Start by identifying your primary goal. Ask yourself: what am I trying to accomplish? The answer usually points directly to the right tool.

If you need to find files, Glob is almost always the answer (or find on default macOS and Linux sessions). The question then becomes whether you know the file pattern. If you know you're looking for TypeScript files, React components, or configuration files, use Glob with the appropriate pattern. For example, searching for all test files becomes Glob("**/*.test.ts"). If you don't know the exact pattern but can describe what you're looking for ("find the main entry point" or "locate config files"), Explore can help by understanding your intent and using multiple searches.

If you need to search content, Grep is your primary tool (or grep in Bash on default macOS and Linux sessions). When you know the search term—a function name, error message, or specific code pattern—a regex search gives fast, accurate results. The -C parameter adds context lines, which helps understand matches without reading entire files. However, if you're exploring conceptually ("how does authentication work here?"), Explore is better because it can follow the code flow across multiple files.

If you need to read file contents, use Read directly when you know the file path. If you're not sure which file contains what you need, combine Glob or Grep to locate the file first, then Read to examine it.

If you're working with MCP tools in Claude Code, you usually do not need to choose: tool search is on by default and defers MCP tools until Claude needs them. On the Claude API, Anthropic recommends tool search once you have about 10 or more tools or definitions over 10K tokens. As Anthropic's documentation describes, a GitHub, Slack, Sentry, Grafana and Splunk setup comes to 58 tools and approximately 55K tokens before the conversation starts.

The decision flowchart simplifies to this: Glob for file finding, Grep for content searching, Read for file viewing, Explore for multi-step exploration, and tool search for large MCP tool libraries.

Here's a practical example that demonstrates this decision process. Imagine you're debugging an authentication error. You might start with Grep("AuthenticationError") to find where the error is thrown. This returns a file path. You then use Read on that file to understand the context. If the error handling involves multiple files, you might use Glob("**/auth*.ts") to find all authentication-related files, then Explore to understand how they interact. Throughout this process, if you're using MCP tools for Jira tickets or GitHub issues, tool search keeps those tool definitions out of the context until Claude calls one.

MCP Tool Search: On by Default in Claude Code, Opt-In on the API

In Claude Code, tool search is on by default: the MCP docs say "MCP tools are deferred and discovered on demand" and "Only tool names and server instructions load at session start". Before tool search, connecting several MCP servers could use tens of thousands of tokens in tool definitions before any work began.

The problem was real. Developer Scott Spence wrote in September 2025 that his MCP tools were consuming "66,000+ tokens of context before I even started a conversation". Anthropic's engineering team reported that with many similar tools, "the most common failures are wrong tool selection and incorrect parameters", especially for tools with near-identical names.

Here is how it works in Claude Code today:

  1. Deferral: MCP tool definitions are held back; Claude starts with the tool names and server instructions
  2. Search: When Claude needs a capability, it calls ToolSearch with a query
  3. Loading: The matching tool definitions are loaded into the context, and Claude calls the tool
  4. Control: ENABLE_TOOL_SEARCH sets the behavior
ENABLE_TOOL_SEARCH valueWhat happens
Unset or trueAll MCP tools deferred and loaded on demand (the default)
autoTools load upfront while their definitions total under 10% of the context window; at 10% or more, tool search turns on
auto:NSame as auto with your own percentage (0–100)
falseAll MCP tools load upfront

The old rule of thumb, "tool search starts when MCP tool descriptions exceed 10K tokens", described the January 2026 behavior. Version 2.1.7 made the 10%-of-context auto mode the default; today auto is only one option and full deferral is the default. You can also disable tool search with a "permissions": {"deny": ["ToolSearch"]} rule, or keep one server's tools always loaded with alwaysLoad: true in its MCP config. Claude Code uses tool search on Claude Opus 4, Claude Sonnet 4, Claude Haiku 4.5 and later models; on earlier models it loads all MCP tools upfront.

On the Claude API you add tool search yourself. Two search variants serve different needs. The regex variant (tool_search_tool_regex) takes Python re.search() patterns of up to 200 characters, matched case-insensitively—useful when you know exact tool names. The BM25 variant (tool_search_tool_bm25) takes natural-language queries of up to 500 characters—better when you're describing what you want to accomplish. Since February 17, 2026 the tool search tool no longer needs a beta header, according to the API release notes.

Configuration example:

python
tools=[
    {
        "type": "tool_search_tool_regex_20251119",
        "name": "tool_search_tool_regex"
    },
    {
        "name": "get_weather",
        "description": "Get weather for a location",
        "input_schema": {
            "type": "object",
            "properties": {"location": {"type": "string"}},
            "required": ["location"]
        },
        "defer_loading": True
    }
]

The tool search tool itself must never be deferred, and a deferred tool cannot also carry cache_control. For MCP servers connected through the API's MCP connector, set defer_loading once in the mcp_toolset entry's default_config instead of on each tool. The tool search docs list support for Claude Opus 4.5, Haiku 4.5 and newer models; "Claude Opus 4.1 and earlier models don't support the tool search tool."

The performance impact is substantial. In Anthropic's November 2025 test, a library of 50+ MCP tools took about 77K tokens of context before any work began; with tool search, the upfront cost was about 8.7K tokens (roughly 500 for the search tool plus about 3K for the 3–5 tools actually loaded), an 85% reduction. Measured against a 200K-token window, that left 191,300 tokens free instead of 122,800. Accuracy also improved, as listed above, because Claude chooses from a short list of relevant tools.

Best practices for Tool Search include writing clear tool descriptions (searches match tool names, descriptions, argument names and argument descriptions), keeping your 3–5 most frequently used tools non-deferred, and adding MCP server instructions that help Claude know when to search for specific tools.

For teams working with complex MCP setups, Tool Search is essential. If you're interested in learning more about MCP configuration, check out our MCP plugin configuration guide for detailed setup instructions.

Optimizing Search Performance

Efficient search isn't just about choosing the right tool—it's about using each tool optimally. These strategies help you minimize token usage while maximizing search effectiveness.

Start specific, then broaden if needed. Begin with the most targeted search possible. If you're looking for a function called handleUserAuth, start with Grep("handleUserAuth") rather than Grep("auth"). The specific search is faster and produces fewer irrelevant results. Only broaden your search if the specific query returns nothing.

Use output modes strategically. Grep's default files_with_matches mode returns only file paths—perfect when you need to know where something exists but don't need the actual matches yet. Switch to content mode with context lines (-C 3) when you need to understand the matches. Use count mode when you need statistics about pattern frequency.

Leverage file filters. Grep can limit a search with type: "ts" or glob: "**/*.ts", and Glob patterns can include the extension directly. Searching only TypeScript files is faster than searching everything and filtering afterwards, and it avoids matching the same text in markdown documentation. In Bash, the equivalent is grep -rn --include='*.ts'.

Combine tools efficiently. A common pattern is Glob → Read or Grep → Read. First, locate files with Glob or identify matches with Grep, then Read specific files for detailed analysis. This two-step approach consumes less context than reading multiple files upfront.

Use Explore for exploratory work. When you're not sure what you're looking for, the Explore subagent is more efficient than multiple manual searches. It keeps its own context, performing many searches without filling your main conversation window. Describe your goal clearly: "Find all files related to user authentication and explain how they interact" is better than multiple vague queries.

For MCP users, leave tool search on. It is the default in Claude Code; if you or a script set ENABLE_TOOL_SEARCH=false, every MCP tool definition loads upfront again.

Monitor your token usage. Run /context in Claude Code to see what fills the context window. If tool definitions take a large share, check whether tool search is turned off or a server uses alwaysLoad. If file reading dominates, use the offset and limit parameters to read only the relevant sections.

For developers who want to try Claude Code, our free trial guide explains how to get started without commitment.

Real-World Search Workflows

Theory becomes practical through real examples. These workflows demonstrate how experienced developers combine search tools to solve actual problems. They use the Glob and Grep tool syntax; on default macOS and Linux sessions Claude runs the same steps with find and grep in Bash.

Workflow 1: Debugging an Error

You encounter an error: "UserAuthenticationError: Invalid token format". Here's the systematic approach:

# Step 1: Find where the error is defined
Grep("UserAuthenticationError", output_mode="files_with_matches")
# Returns: src/errors/auth-errors.ts

# Step 2: Find where the error is thrown
Grep("throw.*UserAuthenticationError", type="ts")
# Returns: src/services/auth.ts:142, src/middleware/auth.ts:38

# Step 3: Read the relevant section
Read("src/services/auth.ts", offset=135, limit=20)
# Shows the token validation logic

# Step 4: Find related tests
Glob("**/auth*.test.ts")
# Returns: src/__tests__/auth.test.ts, src/services/__tests__/auth.test.ts

Workflow 2: Understanding a New Codebase

You've joined a project and need to understand its structure:

# Step 1: Use the Explore subagent for high-level understanding
Agent(
  description="Map project architecture",
  prompt="Explain the overall architecture of this project.
          What are the main directories and their purposes?",
  subagent_type="Explore"
)

# Step 2: Find entry points
Glob("**/index.ts")
Glob("**/main.ts")
Glob("**/app.ts")

# Step 3: Understand key configurations
Read("package.json")
Read("tsconfig.json")

# Step 4: Explore specific subsystems
Grep("export.*function", glob="src/services/*.ts")

Workflow 3: Refactoring a Function

You need to rename getUserData to fetchUserProfile across the codebase:

# Step 1: Find all usages
Grep("getUserData", output_mode="count")
# Returns: 47 matches in 12 files

# Step 2: See the distribution
Grep("getUserData", output_mode="files_with_matches")
# Lists all 12 files

# Step 3: Check for test coverage
Grep("getUserData", glob="**/*.test.ts")
# Returns: 8 matches in test files

# Step 4: Identify the definition
Grep("export.*function getUserData", output_mode="content", "-C"=2)
# Shows the function definition with context

Workflow 4: MCP Tool Integration

You're working with Jira, Slack, and GitHub tools through the Claude API:

python
# Configure tool search to avoid context pollution
tools = [
    {"type": "tool_search_tool_bm25_20251119", "name": "tool_search_tool_bm25"},
    # All MCP tools marked for deferred loading
    {"name": "jira_create_issue", "defer_loading": True, ...},
    {"name": "slack_send_message", "defer_loading": True, ...},
    {"name": "github_create_pr", "defer_loading": True, ...},
    # ... 50+ more tools
]

# When you need to create a Jira ticket, tool search finds the right tool
# Only jira_create_issue is loaded, not all 50+ tools

In Claude Code you skip this configuration: add the servers with claude mcp add, and tool search defers their tools automatically. For more advanced MCP workflows, see our comprehensive MCP guide.

Glob, Grep and Tool Search FAQ

What's the difference between Glob and Grep?

Glob searches file names and paths using patterns like **/*.ts, returning up to 100 matching file paths sorted by modification time. Grep searches file contents using regex patterns, returning matching file paths by default, or the matching lines or counts when asked. Use Glob when you know the file naming pattern but not the location; use Grep when you know what's inside the file but not which file contains it. On macOS, Linux and WSL, Claude Code 2.1.117 and later does the same two jobs with find and grep in Bash.

What are Grep and Glob in Claude Code?

They are Claude Code's two built-in search tools: Grep for text inside files (built on ripgrep) and Glob for file names and paths. On Windows they are in the default tool set. On macOS, Linux and WSL they are absent by default, and Claude uses embedded ugrep and bfs through the Bash tool instead.

Why doesn't my Claude Code session have Glob or Grep tools?

Because you are on macOS, Linux or WSL with Claude Code 2.1.117 or later, where both tools are left out of the default tool set on purpose. Searches still work through Bash. To restore the tools, start Claude Code with --allowedTools naming Glob or Grep, or use a subagent that lists them without Bash.

When should I use Task/Explore instead of Grep?

Use the Explore subagent when your question requires multiple steps to answer, when you're exploring conceptually ("how does X work?"), or when you want to preserve your main conversation context. Explore makes many searches and reads on its own and returns a summary. Grep is better for targeted searches where you know exactly what pattern to match. The tool that launches Explore is called Agent since version 2.1.63; Task still works as an alias.

How does Tool Search save 85% of tokens?

Without tool search, every tool definition is loaded into context upfront: about 72K tokens for 50+ MCP tools in Anthropic's November 2025 test, or about 77K in total. With tool search, only the search tool (~500 tokens) and the 3–5 tools Claude actually needs (~3K tokens) are loaded, about 8.7K in total. That difference is the 85%. The saving depends on how many tools you connect and how long their descriptions are.

Can I use multiple search tools in one request?

Yes, Claude Code can invoke multiple tools in a single response when the operations are independent. For example, it might run two Grep searches in parallel if they don't depend on each other. However, when tools have dependencies (Glob → Read), they run sequentially. Running independent searches together saves round trips.

What's the best way to search large codebases?

Start with the most specific search possible to avoid overwhelming results. Use file type filters (type: "ts") to narrow scope. Leverage Glob's modification-time sorting to find recently changed files first. For complex exploration, use the Explore subagent, which keeps its own context and can perform many searches without filling your main conversation. For symbol-level navigation (definitions, references, call hierarchies), the LSP tool is more precise than text search once a code intelligence plugin is installed; semantic code search MCP servers such as claude-context are another option.

Which Claude Code Search Tool to Use

Claude Code's search tools split the work cleanly. Glob handles file name matching, Grep handles content search with ripgrep, Read opens files, Explore takes on multi-step exploration, and tool search keeps large MCP tool libraries out of the context until they are needed.

The key to mastery is matching the right tool to each situation. Start with a name search or a content search for most everyday tasks—they're fast and consume little context. On macOS, Linux and WSL, expect those searches to show up as find and grep in Bash rather than as Glob and Grep calls, and use -E when a regex returns nothing. Escalate to Explore when questions require multiple steps or conceptual understanding. Leave tool search on whenever you connect many MCP servers.

For teams looking to optimize their AI development workflow, combining Claude Code with efficient API access can significantly reduce costs. For more information on API options and pricing, check the documentation at docs.laozhang.ai.

The search tools keep changing: Task became Agent, Explore moved off Haiku, Glob and Grep left the default tool set on macOS and Linux, and tool search went from a beta to the default. The split between name search and content search has stayed the same throughout.

Found an error, or hit a problem this article does not cover? Send the article URL and what you saw to hi@laozhang.ai. We check it and update the article.