Try free

Last updated 13 October 2026

Using the search command inside Claude Code

Finding code patterns across your project

You are often looking for a specific function name, a hardcoded string, or a variable definition in a massive repository. Manual searching through folders is slow and interrupts your focus. Standard terminal commands like grep or find are powerful but require you to remember complex flags and manually parse the results. When you work with Claude Code, you can locate these patterns by describing what you need in plain English instead of crafting a perfect regex string yourself.

The agent simplifies the discovery process by taking your natural language request and translating it into a series of tool calls. It does not rely on its training data to guess where your code is. Instead, it looks at your local file system in real time to provide accurate locations. This approach ensures that you get the current state of your codebase, which is essential when you are working on a rapidly changing project or a legacy system you did not write.

How the agent uses the Grep tool

The primary way the agent finds text strings is through the Grep tool. When you ask it to find all occurrences of a specific login handler, the agent decides to run this tool against your directory. It scans the content of every file it has permission to access and returns a list of file paths along with the specific line numbers where the matches were found. This raw data allows the agent to navigate your project with high precision without you needing to provide the paths yourself.

This tool is particularly useful for identifying where specific constants or error messages are defined. If you provide a snippet of an error log, the agent can use the Grep tool to find the exact line in your source code where that error is thrown. Because the tool is managed by the agent, it can handle large volumes of matches by summarizing them for you, which prevents your terminal output from becoming an unreadable wall of text.

Filtering search areas with the Glob tool

Searching an entire repository can be wasteful if you already know the general area where the code should be. The agent uses the Glob tool to narrow down the search space based on your instructions. You can tell the agent to search only within your backend directory or to look for files that have a specific extension like .ts or .json. This filtering happens before the agent reads the file contents, which saves significant time and computing resources during the search process.

By combining the Glob tool with your search request, you ensure that the agent ignores irrelevant files like build artifacts, documentation, or style sheets. For example, if you are searching for a database query, you can instruct the agent to ignore the tests folder. This precision keeps the results focused on your actual logic and prevents the agent from being distracted by mock data or test configurations that might contain similar strings.

Managing context volume with the compact command

Every search result the agent reads is added to the context window of your current session. If you perform several broad searches that touch dozens of files, the session history can grow very quickly. A large context window can make the agent slower and increases the cost of your session. You can monitor your current spend and resource usage at any time by using the /cost or /usage commands within your active terminal session.

To keep your environment efficient, use the /compact command after you have finished a major search task. This slash command tells the agent to summarize the conversation so far and remove the full text of the files it has read. The agent retains the important information it discovered but frees up space in its memory for your next set of instructions. This is a vital habit for developers who run long sessions and want to maintain a high level of performance from the agent.

Using the clear command for new investigations

If you have completed a search and debugging session and want to move on to a completely different part of the project, the /clear command is the best way to reset. This command wipes the entire conversation history within the same folder without requiring you to quit the claude command and restart. It provides a blank slate for the agent while keeping your terminal environment and project path exactly where they are.

Starting a fresh session with /clear ensures that the agent does not get confused by previous search results or file summaries that are no longer relevant to your new task. It is a faster alternative to using Ctrl+C to quit and then running the claude command again. Keeping your sessions clean and focused on a single problem at a time is one of the most effective ways to avoid errors and get the most useful answers from the agent.

Defining search behavior in CLAUDE.md files

You can customize how the agent searches your project by adding instructions to a CLAUDE.md file. This file should sit in your repository root and contains guidelines that the agent reads at the beginning of every session. You can use it to tell the agent to always ignore certain directories during searches or to prioritize specific modules when looking for architectural patterns. This ensures that every search the agent performs is tailored to the specific needs of your project.

If your project has a complex structure, you can also place a CLAUDE.md file in subdirectories to provide localized instructions. The agent respects these files as it navigates the tree, applying the rules found in the subdirectory to only that part of the project. This hierarchical setup allows you to manage different search preferences for your frontend and backend code within the same repository, making the search tool more intelligent and project-aware.

Adjusting permission modes for faster searching

When the agent finds matches across many different files, it may ask for your permission before it reads them. This is the default behavior to ensure you have control over which parts of your system the agent accesses. If you are conducting a very broad search and do not want to approve every file individually, you can change the permission mode. Pressing Shift+Tab inside the session cycles through modes like plan, acceptEdits, and bypassPermissions.

Switching to bypassPermissions allows the agent to read and search through your files without stopping to ask for your consent every time. This is useful for deep investigations where you trust the agent to scan the entire tree. You can also define these permissions more permanently in your .claude/settings.json file. By setting specific tools to be allowed by default, you can streamline your workflow and allow the agent to complete complex search tasks with fewer interruptions.

Handling multiple search sessions with adhdTerminal

Managing multiple search tasks at once can become overwhelming in a single terminal window. If you are tracking down several bugs across different microservices, adhdTerminal is the honest answer for keeping your workspace organized. This native app for macOS and Windows, created by MINDBALANCER OU, allows you to run many Claude Code sessions side by side as tiles on a wall. You can dedicate one tile to searching your API logic and another to investigating your UI components.

Each tile in adhdTerminal has its own color, number, and name, which helps you identify your search sessions at a glance. The interface shows whether a session is working, idle, or waiting for your input, so you never lose track of a search that is running in the background. Because tiles reopen in the same place after a restart and resume the same session, you can pick up your investigation exactly where you left off without needing to re-run your search prompts.

Running searches from shell history and flags

You can use standard terminal features to speed up your interactions with the agent. Pressing Ctrl+R in your shell allows you to search through your command history to find prompts that worked well in the past. If you have a complex search request that you use frequently, this is often faster than typing it out again. You can also use the claude -p flag to run a search prompt and print the answer directly to your terminal output without entering the interactive interface.

When you need to carry on a search session from earlier in the day, the claude --continue command is the fastest way to resume. If you need to find a specific session from a longer list, use claude --resume to see your recent history and pick the right one. For developers who are always on the move, the free iPhone app from adhdTerminal mirrors your wall over an end to end encrypted link. It allows you to check the status of a long running search or send the next task to the agent directly from your phone.

Questions people ask

Can I search for regex patterns with the agent?

Yes, you can ask the agent to find strings using regular expressions. The agent will then format the proper command for its Grep tool to locate those patterns. This is helpful for finding complex strings like UUIDs or specific architectural decorators across your files.

Does searching respect my git ignore settings?

The agent respects your .gitignore file by default when it performs a search. It will not look inside ignored directories like node_modules or build folders unless you explicitly tell it to search those areas. This keeps your results relevant to the code you actually manage.

How do I stop a search that is taking too long?

You can press the Escape key once to interrupt what the agent is doing if a search is taking too long or returning too many results. If you need to go back and change your prompt after an interruption, pressing Escape twice will allow you to navigate back through your previous messages.

Read next

More on claude code basics·All posts