You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently Claude Code can burn a lot of tokens when trying to review/search for something.
Would be great if there Claude Code had a codebase indexing feature to help conserve the amount of tokens used.
Reacted by Toma Tacescu, muhammadanas-spur, Jac0bsad, Andrej Rankovski, Anton Lvovych, Andrea Maioli, Rob Percival, kk-jomiyamoto, DRON4eg, Davide Bontempelli and 59 more
You've hit on a crucial aspect of working effectively with code agents: managing token consumption, especially during intensive tasks like codebase analysis and review. While a built-in persistent indexing feature is an interesting idea for the future, there's a powerful existing mechanism in Claude Code designed to solve this exact problem: sub-agents.
The key benefit is that each sub-agent operates in its own isolated context window. This means you can delegate the "heavy lifting" of searching and reading through files to a specialized agent without polluting your main conversation's context and burning tokens. The main agent only receives the final, concise result.
Recommendation: Create a code-searcher Sub-agent
I'd recommend creating a dedicated sub-agent for this workflow. You can think of this as building your own specialized "indexer" or "reviewer" for your project.
Here's how you can set one up using the /agents command:
Run /agents in your Claude Code terminal.
Select "Create New Agent".
Define the agent with a configuration like this:
---
name: code-searcherdescription: A specialized agent for efficiently searching the codebase, finding relevant files, and summarizing code. Use this for any task that involves locating specific functions, classes, or logic.tools: Read, Grep, Glob, Ls
---
You are an expert code searcher and analyst. Your goal is to answer questions about the codebase as efficiently as possible.1. **Understand the User's Goal:** Clarify what the user is looking for.2. **Plan Your Search:** Use `Glob` and `Grep` to locate relevant files and code snippets.3. **Read and Analyze:** Read only the most relevant files to understand the context.4. **Synthesize and Summarize:** Provide a concise answer. **Do not** output the full contents of large files unless specifically asked. Instead, provide file paths, function names, and a brief summary of the relevant logic.
How to Use Your New Agent
Once created, you can delegate tasks to it explicitly:
> Use the code-searcher agent to find all functions related to user authentication and list the files where they are defined.
Claude Code will then spin up the code-searcher in a separate context. That agent will perform all the necessary Grep, Glob, and Read operations. The tokens used for reading those files will be contained within the sub-agent's context.
Finally, the sub-agent will return only the summarized result (e.g., a list of files and function names) to your main conversation, keeping your primary context clean and your token usage low.
This approach gives you a powerful, reusable pattern for any task that requires deep, but temporary, context. You can create other agents for different workflows, like a test-runner or a security-reviewer.
I'd recommend creating a dedicated sub-agent for this workflow. You can think of this as building your own specialized "indexer" or "reviewer" for your project.
That keeps your context clean, but doesn't do anything to reduce token consumption - if anything it increases it, as that new agent has even less context then your current chat does.
The benefit of true indexing like cursor (or even Gemini Chat Assist!) is when a user asks Claude "Can you help me write a new back-end migration", the codebase is queried based on that question and returns relevant code snippets + the original prompt to Claude in one shot. That way Claude doesn't have to do 10 iterations of "Hmm, let me see, ls -a, rg, oops, looks like I'm in the wrong dir, cd && rg <**>....." etc.
And in a system like cursors where the index is in the cloud, the other benefit is that there's way more compute to query it with. If your codebase is in a local Elasticsearch docker image that's limited to half a gig of ram, you won't be able to query it as fast or accurately compared to some beefy kb server.
A plugin or mcp is a decent solution, but then that's just one more service running in the background, more mcp tools clogging up the context, etc.
Reacted by William Rufino, Nico Bailon, Truc Tran, Túlio Santos, Vlad Toie, Felix Isaac Lim, daniel lee, Jaswanth Sai Sattenapalli, Petre, Rost Zhuravsky and 8 more
I'm hitting serious code search performance issues with Claude Code on large repositories. When compared with GitHub Copilot in VSCode or Cursor, Claude Code easily takes between 2x and 2.5x longer on average to analyze the code and produce the response for the exact same question. I'm talking 1 minute versus over 2 minutes here.
Both GitHub Copilot and Cursor have built-in code search capabilities that are really good, why is Claude Code still doing simple grepping of files? GitHub Copilot has remote workspace indexing for GitHub repositories - it doesn't even have to perform local indexing, saving a lot of local compute resources. As for Cursor, I didn't do anything special, it just worked out of the box with search capabilities similar to GitHub Copilot.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
"Early versions of Claude Code used RAG + a local vector db, but we found pretty quickly that agentic search generally works better. It is also simpler and doesn’t have the same issues around security, privacy, staleness, and reliability."
from Claude code creator Boris
I would like to use Claude Code in Cursor because I prefer their limits policy, but when I tried to use Claude Code, the results disappointed me, the Antropic models in Cursor seem to work better, perhaps this is due to the indexing of the codebase or the system's promptness is better, I don't know
Interesting that Boris mentioned they tried RAG + vector DB early on but moved to agentic search. That makes sense for general use, but for larger codebases the agentic grep approach has real limits: it burns context window pulling in irrelevant files, and it completely misses conceptual matches where the naming doesn't align with what you're searching for.
I actually built a plugin that fills this gap. It indexes your codebase with embeddings and does hybrid search: semantic similarity combined with BM25 keyword matching and identifier boosting. So when you search "authentication flow" it finds login_handler, verify_token, session_middleware even though none of those strings match literally.
The key insight was that you don't need to replace agentic search, you just need to give the agent better search tools. Claude Code's plugin system makes this straightforward: it hooks into lifecycle events so the index auto updates as you edit files.
Runs fully local with Ollama, stores everything in SQLite, no API keys needed for the default setup. In my testing it cuts context pollution by about 60% on codebases over 50k lines.
This gives Claude a map of your codebase structure and key exports on every session start, reducing the need to re-scan the same files. The index rebuilds automatically when stale.
Activity
coygeek commentedon Jul 28, 2025
Try this:
GitHub Issue Response
You've hit on a crucial aspect of working effectively with code agents: managing token consumption, especially during intensive tasks like codebase analysis and review. While a built-in persistent indexing feature is an interesting idea for the future, there's a powerful existing mechanism in Claude Code designed to solve this exact problem: sub-agents.
The key benefit is that each sub-agent operates in its own isolated context window. This means you can delegate the "heavy lifting" of searching and reading through files to a specialized agent without polluting your main conversation's context and burning tokens. The main agent only receives the final, concise result.
Recommendation: Create a
code-searcherSub-agentI'd recommend creating a dedicated sub-agent for this workflow. You can think of this as building your own specialized "indexer" or "reviewer" for your project.
Here's how you can set one up using the
/agentscommand:Run
/agentsin your Claude Code terminal.Select "Create New Agent".
Define the agent with a configuration like this:
How to Use Your New Agent
Once created, you can delegate tasks to it explicitly:
> Use the code-searcher agent to find all functions related to user authentication and list the files where they are defined.Claude Code will then spin up the
code-searcherin a separate context. That agent will perform all the necessaryGrep,Glob, andReadoperations. The tokens used for reading those files will be contained within the sub-agent's context.Finally, the sub-agent will return only the summarized result (e.g., a list of files and function names) to your main conversation, keeping your primary context clean and your token usage low.
This approach gives you a powerful, reusable pattern for any task that requires deep, but temporary, context. You can create other agents for different workflows, like a
test-runneror asecurity-reviewer.You can learn more in the official documentation:
Let us know how this works for you
codingjaguar commentedon Aug 16, 2025
Does a code search plugin help? https://github.com/zilliztech/claude-context
alliecatowo commentedon Oct 1, 2025
That keeps your context clean, but doesn't do anything to reduce token consumption - if anything it increases it, as that new agent has even less context then your current chat does.
The benefit of true indexing like cursor (or even Gemini Chat Assist!) is when a user asks Claude "Can you help me write a new back-end migration", the codebase is queried based on that question and returns relevant code snippets + the original prompt to Claude in one shot. That way Claude doesn't have to do 10 iterations of "Hmm, let me see,
ls -a,rg, oops, looks like I'm in the wrong dir,cd && rg <**>....." etc.And in a system like cursors where the index is in the cloud, the other benefit is that there's way more compute to query it with. If your codebase is in a local Elasticsearch docker image that's limited to half a gig of ram, you won't be able to query it as fast or accurately compared to some beefy kb server.
A plugin or mcp is a decent solution, but then that's just one more service running in the background, more mcp tools clogging up the context, etc.
williamhrs commentedon Oct 5, 2025
that would be a great addition. there are mcps that do that, but native is aways better I guess
antonlvovych commentedon Oct 8, 2025
@williamhrs what mcps do you know for indexing?
I just found:
https://github.com/zilliztech/claude-context
https://github.com/bartolli/codanna
williamhrs commentedon Oct 9, 2025
yeah, specific for code there isn't many.. (just found this new ones below)
https://github.com/johnhuang316/code-index-mcp
https://github.com/casualjim/breeze
https://github.com/qodo-ai/open-aware
I wanted to use claude context, but didn't want to use the proprietary vector, so doesn't work well for me...
but kilo code, roo, etc have it native and seens to work nice
mamoreau-devolutions commentedon Nov 11, 2025
I'm hitting serious code search performance issues with Claude Code on large repositories. When compared with GitHub Copilot in VSCode or Cursor, Claude Code easily takes between 2x and 2.5x longer on average to analyze the code and produce the response for the exact same question. I'm talking 1 minute versus over 2 minutes here.
Both GitHub Copilot and Cursor have built-in code search capabilities that are really good, why is Claude Code still doing simple grepping of files? GitHub Copilot has remote workspace indexing for GitHub repositories - it doesn't even have to perform local indexing, saving a lot of local compute resources. As for Cursor, I didn't do anything special, it just worked out of the box with search capabilities similar to GitHub Copilot.
Here's a side-by-side video showing how major the difference in performance is between GitHub Copilot and Claude Code: https://bsky.app/profile/awakecoding.com/post/3m5f2bvvbl227
Even if cost wasn't an issue, performance certainly is.
apatel369 commentedon Nov 24, 2025
Perhaps for this reason, they haven't added it yet?
https://cline.bot/blog/why-cline-doesnt-index-your-codebase-and-why-thats-a-good-thing
mamoreau-devolutions commentedon Dec 13, 2025
@apatel369 there are definitely a lot of ways code indexing can fail to perform, but what I see is GitHub Copilot doing an excellent job at it, while Claude Code remains in the stone age with basic grepping and background agents that take twice longer to complete. Why isn't Anthropic putting effort where the competition is obviously succeeding?
https://github.blog/news-insights/product-news/copilot-new-embedding-model-vs-code/
github-actions commentedon Jan 13, 2026
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
loganrosen commentedon Jan 25, 2026
This feature request is still relevant.
apatel369 commentedon Feb 4, 2026
"Early versions of Claude Code used RAG + a local vector db, but we found pretty quickly that agentic search generally works better. It is also simpler and doesn’t have the same issues around security, privacy, staleness, and reliability."
from Claude code creator Boris
https://x.com/bcherny/status/2017824286489383315?s=20
interhin commentedon Feb 6, 2026
I would like to use Claude Code in Cursor because I prefer their limits policy, but when I tried to use Claude Code, the results disappointed me, the Antropic models in Cursor seem to work better, perhaps this is due to the indexing of the codebase or the system's promptness is better, I don't know
sagarmk commentedon Mar 9, 2026
Interesting that Boris mentioned they tried RAG + vector DB early on but moved to agentic search. That makes sense for general use, but for larger codebases the agentic grep approach has real limits: it burns context window pulling in irrelevant files, and it completely misses conceptual matches where the naming doesn't align with what you're searching for.
I actually built a plugin that fills this gap. It indexes your codebase with embeddings and does hybrid search: semantic similarity combined with BM25 keyword matching and identifier boosting. So when you search "authentication flow" it finds login_handler, verify_token, session_middleware even though none of those strings match literally.
The key insight was that you don't need to replace agentic search, you just need to give the agent better search tools. Claude Code's plugin system makes this straightforward: it hooks into lifecycle events so the index auto updates as you edit files.
Runs fully local with Ollama, stores everything in SQLite, no API keys needed for the default setup. In my testing it cuts context pollution by about 60% on codebases over 50k lines.
https://github.com/sagarmk/beacon-plugin
yurukusa commentedon Mar 29, 2026
A hook-based approach can provide lightweight codebase indexing by building a project map on session start:
Inject the index into context:
This gives Claude a map of your codebase structure and key exports on every session start, reducing the need to re-scan the same files. The index rebuilds automatically when stale.
charanjit-singh commentedon Aug 23, 2026
Any udpdates on this??