Sound Familiar?

You open Claude Code, type in your request, and then… wait.

Explore(Explore /src/api/ structure)
  Done (24 tool uses · 40.0k tokens · 59s)
Explore(Explore /src/components/ structure)
  Done (32 tool uses · 57.0k tokens · 1m26s)
Explore(Explore /src/database/ structure)
  Done (18 tool uses · 33.0k tokens · 51s)

60 tool calls, 157,800 tokens, nearly 2 minutes – and it hasn’t even started doing real work yet.

It’s like taking a cab to work every morning, and the driver insists on driving down every street first to “get familiar with the area” before dropping you off. Didn’t you just drive this route yesterday? The driver shrugs: sorry, I lost my memory.

Claude Code is that amnesiac driver. Every new session, all the code understanding it built up gets wiped clean. Start over. Close the session? Tuition wasted.

Today I’m introducing a token optimization tool that puts a map in that driver’s pocket.

What Is CodeGraph: Drawing a Map of Your Codebase

CodeGraph’s idea is straightforward: instead of letting Claude Code grope around blindly every time, pre-build a “relationship graph” of your codebase and store it in a local database.

It uses tree-sitter to parse your source code, extracting everything that has a name – functions, classes, methods, interfaces, types, variables – then maps out the relationships between them:

  • Who calls whom (function A calls function B)
  • Who inherits from whom (class Dog extends class Animal)
  • Who implements whom (UserService implements IUserService)
  • Who imports whom (file A imports something from file B)

All these relationships get stored in a local SQLite database, with vector embeddings for semantic search. In short, it’s a code knowledge graph.

Think of it this way: your codebase is a city. Claude Code used to navigate on foot, feeling its way street by street. Now CodeGraph hands it a GPS.

Before vs After: Real Numbers

The original author Colby McHenry ran the same complex task 3 times on the same project:

MetricWithout CodeGraphWith CodeGraphChange
Explore Phase Tokens~130k~69.4k~30% reduction
Tool Calls~74~56~25% reduction
Exploration Time~2m16s~1m57sNoticeably faster

You might think 30% doesn’t sound like much. But this is a toll you pay on every single session. 10 sessions a day, 5 days a week – that adds up to real money over a month.

And the shorter the exploration phase, the more context window you have left for actual work. The context window is like your desk – if the map takes up the whole surface, where do you put your materials?

5-Minute Setup

Prerequisites: Node.js 18+ and Claude Code.

Step 1: Run the installer

npx @colbymchenry/codegraph

The interactive installer handles a few things for you:

  1. Configures the MCP server in ~/.claude.json
  2. Sets up auto-authorization for CodeGraph tools
  3. Asks if you want to initialize the current project

Step 2: Restart Claude Code, then initialize the project

codegraph init -i

The author’s project had 85 files and 542 code symbols. Indexing plus relationship mapping took half a second.

Step 3: There is no step 3

Seriously. Git hooks auto-sync the index on every commit. No maintenance on your end.

Remember: npx @colbymchenry/codegraph to install, codegraph init -i to initialize, git commit to auto-update. After that, just forget it exists.

How It Actually Works

CodeGraph does four things under the hood:

CodeGraph workflow: Parse, Store, Connect, Sync

1. Parse

Uses tree-sitter to turn source code into an AST (Abstract Syntax Tree), extracting “nodes” and “edges”:

  • Nodes: functions, classes, methods, interfaces, types, variables
  • Edges: call relationships, import relationships, inheritance, implementations, type references

2. Store

Everything goes into a local SQLite database:

  • FTS5 full-text search (find by name)
  • Vector embedding semantic search (find by meaning)
  • Graph traversal (find relationships)

3. Connect

Exposed to Claude Code via MCP (Model Context Protocol). When Claude needs to understand code, it queries the graph instead of scanning files one by one.

4. Sync

Git hooks automatically re-index after every commit. Code changes, the graph follows.

One sentence summary: build the map, query the map, the map updates itself.

How It Differs from DIY Approaches

Before CodeGraph came along, people had already tried various ways to deal with Claude Code’s session amnesia:

Approach 1: Stuffing information into CLAUDE.md

Write the codebase structure, architecture notes, and file lists into CLAUDE.md. Claude reads this file on startup – basically giving it handwritten notes.

The problem: notes are just notes. Claude is “reading documentation,” but it doesn’t actually understand call relationships between code. You tell it “UserService is under src/services/,” but it has no idea which 15 places call UserService.

Approach 2: Sub-agents + shared memory files

Have the exploration agent write its findings into shared markdown files for next time. More refined, but it’s still text at its core – still lacking structured relationship data.

Approach 3: Manually pasting relevant code into prompts

The dumbest but most effective method – you directly tell Claude “look at this code.” The problem is it doesn’t scale. You can’t manually hunt down the right code and paste it in every time.

The fundamental difference with CodeGraph: it doesn’t hand Claude a “reference document” – it gives Claude a structured database it can query directly. Like the difference between notes and a database – can you run SQL against your notes?

Notable Features

Semantic Search

Search for “authentication” and it finds login, validateToken, AuthService, even when naming conventions are completely different. Way better than grep’s literal matching.

Impact Analysis

Before modifying a function, check its blast radius – who calls it? Who depends on it? What breaks if you change it? Especially useful during large refactors.

16+ Language Support

TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, and even Shopify’s Liquid template language. It’s not picky.

Fully Local

No network calls, no API key, no external services. Just a local SQLite file sitting in your project. If you work with proprietary code or sensitive projects, you’ll appreciate this.

Gotchas

Gotcha 1: Large monorepo initialization can be slow

The author’s example was 85 files in half a second, but if your project has thousands of files, the first index takes longer. The good news is you only run it once – git hooks handle incremental updates after that.

Workaround: use .codegraphignore (if supported) or .gitignore to exclude node_modules, dist, vendor, and other directories that don’t need indexing.

Gotcha 2: MCP tool list context overhead

If you’ve already configured a bunch of MCP servers, the tool list itself eats into your context. Anthropic released MCP Tool Search in January 2026, which dynamically loads tools and compresses tool list overhead from 77K tokens to 8.7K. If you’re running a lot of MCP servers, turn this on too.

Gotcha 3: Don’t forget to restart Claude Code

After installing an MCP server, you need to restart Claude Code for it to take effect. I know this sounds obvious, but you will forget.

Summary

  1. CodeGraph uses tree-sitter to parse code, SQLite to store the relationship graph, and MCP to connect with Claude Code – letting the exploration agent query the graph instead of scanning files
  2. Real-world testing shows roughly 30% token reduction and 25% fewer tool calls, saving money on every session
  3. Runs locally, auto-updates via Git hooks, supports 16+ languages – install and forget

Quick reference you can copy:

# Install
npx @colbymchenry/codegraph

# Initialize project
codegraph init -i

# Manually rebuild index (usually not needed, git hooks auto-sync)
codegraph index

# Check index status
codegraph status

How Many Tokens Does Your Claude Code Burn on “Navigation”?

Seriously, pay attention next time you open a new session – check how many tokens the Explore phase eats. If your project has over 100 files, the number will probably shock you. Token optimization is something you’ll have to face sooner or later.

Next time we can talk about pairing CodeGraph with Context7 (another MCP tool that pulls real-time documentation), so Claude Code not only knows your code but can also look up the latest library docs on the fly. That’s Context Engineering in practice – two maps stacked together, double the effect.


If you’ve been annoyed by Claude Code’s “exploration tax,” share this with friends who also use Claude Code. Save them some money too.

Got questions, or found a better token optimization trick? Let’s talk in the comments.