How to Stop Burning Thousands of Dollars on Tokens When Working with AI Agents on Code
Sound familiar? You ask Claude Code or Cursor to fix a single twenty-line function in a legacy module. The agent opens a thousand-line file, reads a bunch of imports, peeks at neighboring files, and instantly burns through half the context window. We're paying neural network providers not for generating smart solutions, but for endlessly scrolling through source code.
A developer under the nickname jgravelle proposed a pragmatic approach: offload code structure analysis to a lightweight local parser, and feed the neural network only the relevant snippet. This is how the open-source project jCodeMunch MCP came about.
What's the core idea of the project
jCodeMunch MCP is an MCP (Model Context Protocol) server that indexes your codebase using the tree-sitter library. Instead of feeding AI agents entire files, the tool parses the AST tree and extracts specific symbols: functions, classes, methods, constants, and interfaces.
When an agent needs to look up a method's implementation, jCodeMunch returns just 30 lines of that specific function with byte offsets, rather than the entire 800-line source file. According to the author's benchmarks on popular repositories like FastAPI, Express, and Gin, this approach reduces token consumption for code reading by 95–99%.
The tool works with Claude Code, Cursor, Windsurf, VS Code, Codex CLI, Continue, and any other clients that support MCP.
Key features of jCodeMunch
Targeted AST search instead of brute force
A typical AI assistant searches for code via grep or requests files one by one. jCodeMunch indexes the project once and builds a symbol map. The agent can search by exact name match, fuzzy search, or a hybrid algorithm (BM25 combined with PageRank).
Context gathering in a single call
Instead of a long chain of queries like "find file -> read -> check imports -> read imports," jCodeMunch has a assemble_task_context tool. You pass a natural language task, and the server automatically determines the intent (debugging, refactoring, audit), extracts key symbols, and forms a compressed context bundle strictly within the specified token limit.
Questions grep can't answer
Static search doesn't understand relationships between components. jCodeMunch can build call graphs and answer specialized engineering questions:
find_importers: shows which files depend on the selected module.get_blast_radius: assesses the blast radius and risks when modifying a specific function.find_dead_code: finds unused symbols and orphaned files not connected to entry points.get_symbol_importance: ranks project components by architectural significance using the PageRank algorithm.get_untested_symbols: searches for functions not covered by existing tests.
Compact MUNCH transfer format
Regular JSON is overly verbose and eats up context on its own. On top of code extraction, jCodeMunch can apply its own MUNCH compression. Repeated paths are interned, and lists are packed into compact CSV strings while preserving types. This delivers another 40–50% savings in data volume transferred.
Under the hood
The project is written in Python and runs entirely locally. By default, all indices are stored in the ~/.code-index/ directory. It uses tree-sitter bindings to parse over 70 programming languages.
Context assembly relies on BM25 full-text search and import graph analysis with PageRank calculation. If you need proper semantic search by meaning, you can install the optional [local-embed] package. It downloads a local ONNX model all-MiniLM-L6-v2 of about 23 MB once. After that, vectorization works without calling external APIs and without code leaking onto the network.
How to try it out
The fastest way to deploy the server is to use pip or uvx:
pip install jcodemunch-mcp
jcodemunch-mcp init
The init utility will automatically find MCP clients installed on your machine (Claude Code, Cursor, Windsurf, VS Code), write the configuration, and suggest adding an instruction to CLAUDE.md or the agent's system prompts so the model starts using symbol search instead of the usual file scrolling.
Example of manual connection to Claude Code via CLI:
claude mcp add -s user jcodemunch uvx jcodemunch-mcp
If you want to track costs, the built-in get_session_stats tool will show tool call statistics, actual token savings per session, and query accuracy.
Who really needs this
The tool is unlikely to change your life if you write small scripts or pet projects with a couple of files. But when working with large monorepos in TypeScript, Python, Go, or Java, jCodeMunch delivers a noticeable effect.
The agent stops getting stuck scrolling through thousands of lines of boilerplate, model responses come back faster, and the bills for neural network API usage drop noticeably. The personal use license is completely free, so you can test the approach on your own codebase without extra costs.
Related projects