
A fresh Claude Code session spent tokens reading through an HTML prototype before it could improve it, showing how unfamiliar code can fill the context window. In a walkthrough by AI LABS, semantic search and the free Serena MCP offer a more focused way to retrieve project code, while a terminal monitor shows how usage changes as work proceeds. Learn how focused retrieval and usage monitoring can help you make more of a session.
Keep Irrelevant Code Out of Context
TL;DR Key Takeaways :
- Unnecessary file reads consume tokens and crowd Claude’s context.
- Serena uses semantic search to retrieve relevant code from supported projects.
- Install the MCP server separately in each directory where it is needed.
- The terminal usage monitor shows messages, tokens, cost and reset timing.
- An HTML-only project probably will not work with Serena indexing.
When Claude starts without knowledge of a codebase, even finding a login component or diagnosing an error in a larger Next.js project can involve listing directories and reading several files. Those reads consume tokens, and retaining unnecessary files in the context window can make it harder to identify what matters and degrade performance.
A CLAUDE.md file can document a codebase and reduce the need to read every source file. It still has to be read, though, so information that is not needed for the task can enter the context window. Claude Code project context can be useful, but the material supplied to a session deserves attention as well.
Semantic search takes a different approach by retrieving relevant pieces instead of searching through all the text available to an agent. Context7 MCP uses it for current library documentation: for a Next.js feature, it finds the library first and retrieves documentation relevant to the issue. Keeping unrelated information out of context is intended to make retrieval faster and more accurate.
Use Serena to Retrieve Project Code
Serena MCP applies a retrieval-augmented generation, or RAG, approach to the codebase itself. It uses semantic search to bring relevant code into Claude’s context rather than having the agent explore the entire project blindly. For an editing task involving Python files and a UI, that focused retrieval is intended to save tokens and improve response speed and accuracy.
Serena is free and also works with MCP clients including Cursor and Windsurf. Cursor provides a set amount of model usage before moving users to pay-as-you-go usage, so focused context can be useful there too. Claude Code gives models their full context windows, while Cursor limits the window to 120,000 tokens rather than the full 200,000.
Check the project’s language before indexing: Serena supports only certain programming languages. A Next.js project using TypeScript and the demonstrated Python app are suitable, while an HTML-only project probably will not work and does not need indexing.
Install Serena and Index a Project
Serena is installed for the directory where you intend to use it, so repeat the installation for each directory that needs the server. The indexing command below applies when you installed the MCP server using UV rather than running it locally.
- In Serena’s documentation, scroll to the Claude Code section and copy the second of the two commands shown there.
- In a terminal, go to the directory where you want to use Serena and paste the command. It adds the MCP server to Claude Code’s settings for that directory.
- Launch Claude Code and open its MCP section. Serena MCP should appear with a check mark showing that the connection is valid.
- Use Serena’s dashboard to inspect server logs or select shutdown to stop the server cleanly. After shutdown, Serena appears with a cross in the MCP section; to restart it, exit Claude Code and launch it again in the same directory, which also starts the dashboard.
- To index the project, first exit Claude Code. In Serena’s documentation, copy the first of the two indexing commands if the server was installed using UV.
- Return to the folder where you installed the MCP server and run the copied command. The command worked in the walkthrough but produced a deprecation error recommending another command; indexing commands are also available in the GitHub documentation.
- After indexing, type Claude to start Claude Code and give it instructions on using the MCP. In the walkthrough, Claude read those instructions and identified the available tools and principles for using them.
- To add usage monitoring, copy the installation command from the Claude Code usage monitor’s GitHub page into the terminal, then launch it with the documented command. A prerequisite must already be installed, although its name is not specified in the walkthrough.
Watch Usage as a Session Progresses
The Claude Code usage monitor runs in a terminal and displays cost, token and message usage, a reset timer and model distribution. Those readings can help you adjust your workflow as you approach a message limit. One option is to keep the monitor in a separate terminal tab while working in Claude Code.
During the walkthrough, the Claude Pro plan used 5-hour usage windows, with 2 hours and 53 minutes remaining until reset. Message usage increased while Claude Code was in use, and the model distribution was 100% Sonnet. These readings show what was happening in that session rather than establishing a saving for every project.
AI LABS found that CC usage did not track messages and usage correctly, while the Claude Code usage monitor worked well for them. A separate terminal tab is also the preferred arrangement over interfaces built on Claude Code, such as Claudia or the Claude Code web UI.
Our view is that Serena is most worth trying on a supported project where Claude would otherwise read through several files to find the relevant code. Pairing it with the terminal monitor gives you a way to watch usage while you work, but the example does not establish a fixed reduction in cost. Check the language support first, and use the dashboard connection status and indexing output to see whether the setup is working.
A cleaner context window helped the walkthrough’s creator get more done within the message limit during a 5-hour window. For an HTML-only project, indexing probably is not the right tool; for a supported codebase, focused retrieval offers a way to keep unrelated files out of the session.
More on Claude:
- How Claude Code Routing Could Cut AI Model Costs
- 13 Ways to Customize Claude Code for Everyday Projects
- How to Install Claude Code in 5 minutes : Mac & Windows
- Why Some Developers Prefer Claude Code to Cursor
Media Credit: AI LABS
Disclosure: Some of our articles include affiliate links. If you buy something through one of these links, Geeky Gadgets may earn an affiliate commission. Learn about our Disclosure Policy.