Reduce Claude Code token usage by 95-99% for code navigation tasks!
A generic MCP server for efficient code navigation across any repository (Linux kernel, libcamera, your projects, etc.) without reading full files.
# 1. Clone the repo
git clone https://github.com/Balki01/code-nav-mcp.git
cd code-nav-mcp
# 2. Run installer
./install.sh
# 3. Add to Claude Code .mcp.json
# See Installation section below- Symbol Lookup: Find function/struct/macro definitions instantly (ctags-based)
- Cross-References: Find all usages of a symbol (ripgrep-based)
- Caller Analysis: See who calls a function
- Git Integration: Blame functions, show commit history
- Multi-Repo: Index and search multiple repos simultaneously
- Smart Grep: Structured grep output without full file reads
# Python MCP SDK
pip install mcp
# System tools (if not already installed)
sudo apt install universal-ctags ripgrepchmod +x server.pyOption A: Project-level (Recommended)
Create .mcp.json in your project root:
{
"mcpServers": {
"code-nav": {
"command": "/absolute/path/to/code-nav-mcp/run_server.sh"
}
}
}Option B: Global settings
Add to ~/.claude/settings.json - NOT RECOMMENDED, see MCP configuration docs
After adding the MCP server configuration, restart Claude Code to load the new server.
First, add and index the repos you want to navigate:
# Add Linux kernel
add_repo(name="linux", path="/home/administrator/SRC/linux", branch="balki/isc-6.18-fixes")
# Add libcamera
add_repo(name="libcamera", path="/work5/balki/SRC_BUILD/libcamera", branch="mchp-next-v2-v0.6.0")
Indexing takes 30-60 seconds for large repos like the kernel (one-time cost).
find_symbol(symbol="isc_awb_work", kind="function")
Output:
Found 1 definition(s) for 'isc_awb_work':
[linux] drivers/media/platform/microchip/microchip-isc-base.c:1503
Kind: function
Code: static void isc_awb_work(struct work_struct *w)
Token savings: Instead of reading 2000+ line file, you get just the location!
find_references(symbol="V4L2_CID_AUTO_WHITE_BALANCE", repo="linux")
Returns all locations where the symbol is used with surrounding context.
find_callers(function="isc_update_awb_ctrls", repo="linux")
Shows all call sites without reading full files.
git_blame_function(function="isc_s_awb_ctrl", repo="linux")
Shows who last modified the function and when.
git_show_symbol(symbol="isc_awb_work", repo="linux")
Shows recent commits that touched this symbol.
smart_grep(pattern="V4L2_CTRL_FLAG_INACTIVE", file_type="c", repo="linux", context=3)
Structured grep with file:line:content output.
Traditional approach (high token usage):
- Read entire microchip-isc-base.c (2000+ lines)
- Read header files
- Re-read after each discovery
- Total: ~10,000+ lines = ~100K tokens
With Code Nav MCP (low token usage):
1. find_symbol("isc_s_awb_ctrl", kind="function")
→ drivers/media/platform/microchip/microchip-isc-base.c:1706
2. find_references("V4L2_CTRL_FLAG_INACTIVE", repo="linux")
→ Shows all checks with context
3. find_callers("isc_update_awb_ctrls")
→ See who calls this function
4. git_blame_function("isc_s_awb_ctrl", repo="linux")
→ Who last changed it
Total: ~400 lines read, 95% token savings!
- Index repos once - Indexing is a one-time cost
- Use
find_symbolfirst - Get exact locations before reading - Use
repoparameter - Narrow searches to specific repos - Combine with Claude's Read tool - After finding the location, read just that function:
find_symbol("isc_awb_work") → Found at line 1503 Read microchip-isc-base.c lines 1503-1600
When using find_symbol, you can filter by kind:
function- Function definitionsstruct- Struct definitionsmacro- #define macrosvariable- Global variablestypedef- Type definitionsmember- Struct/class members
- Indexing: 30-120 seconds per repo (one-time)
- Symbol lookup: <100ms (instant)
- References: 1-5 seconds (depends on repo size)
- Git operations: <1 second
sudo apt install universal-ctags
# NOT 'exuberant-ctags' - that's outdated# Re-run indexing
add_repo(name="linux", path="/home/administrator/SRC/linux")sudo apt install ripgrep- ctags: Generates symbol index (definitions)
- ripgrep: Fast full-text search (references)
- git: History and blame integration
- MCP: Exposes tools to Claude Code
The server maintains in-memory repo registry and delegates to command-line tools for actual work.
Created while debugging Linux kernel camera drivers (microchip-isc). Typical investigation that would use 750K-1.5M tokens now uses 7.5K-15K tokens.
From the creator:
"I was spending hundreds of thousands of tokens just finding where functions were defined in the kernel. This tool paid for itself in a single debugging session."
- Cscope integration for call graphs
- Semantic search with embeddings
- Cache frequently accessed symbols
- Support for LSP integration
- Cross-repo symbol resolution
Contributions welcome! See CONTRIBUTING.md for guidelines.
MIT - See LICENSE file for details.
Built for developers debugging complex codebases. Inspired by real-world kernel development workflows.