@GitTrend0x: Claude Code 工具调用砍 94% 本地代码知识图谱神器 https://github.com/Jakedismo/codegraph-rust… 这就是 CodeGraph-Rust,MCP 服务器直接把你的整个代码库提前索引成…
摘要
CodeGraph-Rust 是一个基于 MCP 协议的工具,能将代码库索引为本地知识图谱,声称可减少 Claude Code 等 AI 代理 94% 的工具调用次数,显著提升速度并节省 Token。
查看缓存全文
缓存时间: 2026/05/13 10:18
Claude Code 工具调用砍 94% 本地代码知识图谱神器 https://github.com/Jakedismo/codegraph-rust… 这就是 CodeGraph-Rust,MCP 服务器直接把你的整个代码库提前索引成本地知识图谱的神器! 一句话干翻 Claude Code / Cursor / 所有 Agent:提前建图,后续查询直接走图谱,不再每次都全量扫文件,工具调用数量暴降 94%,速度起飞、Token 狂省、体验直接起飞! 用了就回不去了
Jakedismo/codegraph-rust
Source: https://github.com/Jakedismo/codegraph-rust

CodeGraph
Your codebase, understood.
CodeGraph transforms your entire codebase into a semantically searchable knowledge graph that AI agents can actually reason about—not just grep through.
Ready to get started? Jump to the Installation Guide for step-by-step setup instructions.
Already set up? See the Usage Guide for tips on getting the most out of CodeGraph with your AI assistant.
The Problem
AI coding assistants are powerful, but they’re flying blind. They see files one at a time, grep for patterns, and burn tokens trying to understand your architecture. Every conversation starts from zero.
What if your AI assistant already knew your codebase?
What CodeGraph Does Differently
1. Graph + Embeddings = True Understanding
Most semantic search tools create embeddings and call it a day. CodeGraph builds a real knowledge graph:
Your Code → Build Context → AST + FastML → LSP Resolution → Enrichment → Graph + Embeddings
↓ ↓ ↓ ↓ ↓ ↓
Packages Nodes/edges Type-aware API surface Graph Semantic
Features Fast patterns linking Module graph traversal search
Targets Spans Definitions Dataflow/Docs (hybrid)
When you search, you don’t just get “similar code”—you get code with its relationships intact. The function that matches your query, plus what calls it, what it depends on, and where it fits in the architecture.
Indexing enrichment adds:
- Module nodes and module-level import/containment edges for cross-file navigation
- Rust-local dataflow edges (
defines,uses,flows_to,returns,mutates) for impact analysis - Document/spec nodes linked to backticked symbols in
README.md,docs/**/*.md, andschema/**/*.surql - Architecture signals (package cycles + optional boundary violations)
Indexing tiers (speed vs richness)
Indexing is tiered so you can choose between speed/storage and graph richness. The default is fast.
| Tier | What it enables | Typical use |
|---|---|---|
fast | AST nodes + core edges only (no LSP or enrichment) | Quick indexing, low storage |
balanced | LSP symbols + docs/enrichment + module linking | Good agentic results without full cost |
full | All analyzers + LSP definitions + dataflow + architecture | Maximum accuracy/richness |
Tier behavior details:
fast: disables build context, LSP, enrichment, module linking, dataflow, docs/contracts, and architecture; filters outUses/Referencesedges.balanced: enables build context, LSP symbols, enrichment, module linking, and docs/contracts; filters outReferencesedges.full: enables all analyzers and LSP definitions; no edge filtering.
Configure the tier:
- CLI:
codegraph index --index-tier balanced - Env:
CODEGRAPH_INDEX_TIER=balanced - Config:
[indexing] tier = "balanced"
Indexing prerequisites (LSP-enabled tiers)
When the tier enables LSP (balanced/full), indexing fails fast if required external tools are missing.
Required tools by language:
- Rust:
rust-analyzer - TypeScript/JavaScript:
nodeandtypescript-language-server - Python:
nodeandpyright-langserver - Go:
gopls - Java:
jdtls - C/C++:
clangd
If indexing appears to stall during LSP resolution, you can adjust the per-request timeout:
CODEGRAPH_LSP_REQUEST_TIMEOUT_SECS(default600, minimum5)
If LSP resolution fails immediately and the error includes something like Unknown binary 'rust-analyzer' in official toolchain ..., your rust-analyzer is a rustup shim without an installed binary. Install a runnable rust-analyzer (e.g. via brew install rust-analyzer or by switching to a toolchain that provides it).
Optional architecture boundary rules
If you want CodeGraph to flag forbidden package dependencies, add codegraph.boundaries.toml at the project root:
[[deny]]
from = "your_crate"
to = "forbidden_crate"
reason = "explain the boundary"
Indexing will emit violates_boundary edges when a depends_on relationship matches a deny rule.
2. Agentic Tools, Not Just Search
CodeGraph doesn’t return a list of files and wish you luck. It ships 4 consolidated agentic tools that do the thinking:
| Tool | What It Actually Does |
|---|---|
agentic_context | Gathers the context you need—searches code, builds comprehensive context, answers semantic questions |
agentic_impact | Maps change impact—dependency chains, call flows, what breaks if you touch something |
agentic_architecture | The big picture—system structure, API surfaces, architectural patterns |
agentic_quality | Risk assessment—complexity hotspots, coupling metrics, refactoring priorities |
Each tool accepts an optional focus parameter for precision when needed:
| Tool | Focus Values | Default Behavior |
|---|---|---|
agentic_context | "search", "builder", "question" | Auto-selects based on query |
agentic_impact | "dependencies", "call_chain" | Analyzes both |
agentic_architecture | "structure", "api_surface" | Provides both |
agentic_quality | "complexity", "coupling", "hotspots" | Comprehensive assessment |
Each tool runs a reasoning agent that plans, searches, analyzes graph relationships, and synthesizes an answer. Not a search result—an answer.
View Agent Context Gathering Flow - Interactive diagram showing how agents use graph tools to gather context.

Agent Architectures
CodeGraph implements agents using Rig the default and recommended choice (legacy react and lats implemented with autoagents still work). Selectable at runtime via CODEGRAPH_AGENT_ARCHITECTURE=rig:
Why Rig is Default: The Rig-based backend delivers the best performance with modern thinking and reasoning models. It is a native Rust implementation that supports internal sub-architectures and provides features like True Token Streaming and Automatic Recovery.
Internal Rig Sub-Architectures:
When using the rig backend, the system automatically maps the consolidated agentic tools to the most effective reasoning strategy:
- LATS (Tree Search): Deep multi-path exploration for complex, non-linear tasks.
- Automatically used for:
agentic_architecture(structure),agentic_quality, andagentic_context(question).
- Automatically used for:
- ReAct (Linear): High-speed, focused reasoning for direct data lookups.
- Automatically used for:
agentic_context(search/builder),agentic_impact, andagentic_architecture(api_surface).
- Automatically used for:
- Reflexion (Auto-Recovery): A self-correcting fallback that kicks in automatically if the primary strategy fails to find an answer. It analyzes the failure and retries with a refined plan.
Agent Bootstrap Context
Agents can start with lightweight project context so their first tool calls are not blind. Enable via env:
CODEGRAPH_ARCH_BOOTSTRAP=true— includes a brief directory/structure bootstrap + contents of README.md and CLAUDE.md+AGENTS.md or GEMINI.md (if present) in the agent’s initial context.CODEGRAPH_ARCH_PRIMER="<primer text>"— optional custom primer injected into startup instructions (e.g., areas to focus on).
Why? Faster, more relevant early steps, fewer wasted graph/semantic queries, and better architecture answers on large repos.
Notes:
- Bootstrap is small (top directories summary), not a replacement for graph queries.
- Uses the same project selection as indexing (
CODEGRAPH_PROJECT_IDor current working directory).
# Use Rig for best performance with thinking and reasoning models (recommended)
CODEGRAPH_AGENT_ARCHITECTURE=rig ./codegraph start stdio
# Use default ReAct for traditional instruction models
./codegraph start stdio
# Use LATS for complex analysis
CODEGRAPH_AGENT_ARCHITECTURE=lats ./codegraph start stdio
All architectures use the same 4 consolidated agentic tools (backed by 6 internal graph analysis tools) and tier-aware prompting—only the reasoning strategy differs.
3. Tier-Aware Intelligence
Here’s something clever: CodeGraph automatically adjusts its behavior based on the LLM’s context window that you configured for the codegraph agent.
Running a small local model? Get focused, efficient queries.
Using GPT-5.1 or Claude with 200K context? Get comprehensive, exploratory analysis.
Using grok-4-1-fast-reasoning with 2M context? Get detailed analysis with intelligent result management.
The Agent only uses the amount of steps that it requires to produce the answer so tool execution times vary based on the query and amount of data indexed in the database.
During development the agent used 3-6 steps on average to produce answers for test scenarios.
The Agent is stateless it only has conversational memory for the span of tool execution it does not accumulate context/memory over multiple chained tool calls this is already handled by your client of choice, it accumulates that context so codegraph needs to just provide answers.
| Your Model | CodeGraph’s Behavior |
|---|---|
| < 50K tokens | Terse prompts, max 3 steps |
| 50K-150K | Balanced analysis, max 5 steps |
| 150K-500K | Detailed exploration, max 6 steps |
| > 500K (Grok, etc.) | Comprehensive analysis, max 8 steps |
Hard cap: Maximum 8 steps regardless of tier (10 with env override). This prevents runaway costs and context overflow while still allowing thorough analysis.
Same tool, automatically optimized for your setup.
4. Context Overflow Protection
CodeGraph includes multi-layer protection against context overflow—preventing expensive failures when tool results exceed your model’s limits.
Per-Tool Result Truncation:
- Each tool result is limited based on your configured context window
- Large results (e.g., dependency trees with 1000+ nodes) are intelligently truncated
- Truncated results include
_truncated: truemetadata so the agent knows data was cut - Array results keep the most relevant items that fit within limits
Context Accumulation Guard:
- Monitors total accumulated context across multi-step reasoning
- Fails fast with clear error message if accumulated tool results exceed safe threshold
- Threshold: 80% of context window × 4 (conservative estimate for token overhead)
Configure via environment:
# CRITICAL: Set this to match your agent's LLM context window
CODEGRAPH_CONTEXT_WINDOW=128000 # Default: 128K
# Per-tool result limit derived automatically: context_window × 2 bytes
# Accumulation limit derived automatically: context_window × 4 × 0.8 bytes
Why this matters: Without these guards, a single agentic_impact query on a large codebase could return 6M+ tokens—far exceeding most models’ limits and causing expensive failures.
5. Hybrid Search That Actually Works
We don’t pick sides in the “embeddings vs keywords” debate. CodeGraph combines:
- 70% vector similarity (semantic understanding)
- 30% lexical search (exact matches matter)
- Graph traversal (relationships and context)
- Optional reranking (cross-encoder precision)
The result? You find handleUserAuth when you search for “login logic”—but also when you search for “handleUserAuth”.
Quick Start
1. Install
# Clone and build with all features
git clone https://github.com/yourorg/codegraph-rust
cd codegraph-rust
./install-codegraph-full-features.sh
macOS faster builds (LLVM lld)
If you develop on macOS, you can opt into LLVM’s lld linker for faster linking:
# Install LLVM so ld64.lld is on PATH (Homebrew)
brew install llvm
# Use the repo-provided Makefile targets
make build-llvm
make test-llvm
2. Start SurrealDB
# Local persistent storage
surreal start --bind 0.0.0.0:3004 --user root --pass root file://$HOME/.codegraph/surreal.db
3. Apply Schema
cd schema && ./apply-schema.sh
4. Index Your Code
codegraph index /path/to/project -r -l rust,typescript,python
🔒 Security Note: Indexing automatically respects
.gitignoreand filters out common secrets patterns (.env,credentials.json,*.pem, API keys, etc.). Your secrets won’t be embedded or exposed to the agent.
5. Connect to Claude Code
Add to your MCP config:
{
"mcpServers": {
"codegraph": {
"command": "/full/path/to/codegraph",
"args": ["start", "stdio", "--watch"]
}
}
}
That’s it. Your AI now understands your codebase.
The Architecture
View Interactive Architecture Diagram - Explore the full workspace structure with clickable components and layer filtering.
┌─────────────────────────────────────────────────────────────────┐
│ Claude Code / MCP Client │
└─────────────────────────────────┬───────────────────────────────┘
│ MCP Protocol
▼
┌─────────────────────────────────────────────────────────────────┐
│ CodeGraph MCP Server │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ Agentic Tools Layer │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────────┐ │ │
│ │ │ Rig │ │ ReAct │ │ LATS │ │ Tool Execution │ │ │
│ │ │ Agent │ │ Agent │ │ Agent │ │ Pipeline │ │ │
│ │ └────┬────┘ └────┬────┘ └────┬────┘ └────────┬────────┘ │ │
│ └───────┼───────────┼───────────┼───────────────┼───────────┘ │
│ └───────────┴───────────┴───────────────┘ │
│ │ │
│ ┌───────────────────────────┼───────────────────────────────┐ │
│ │ Inner Graph Tools │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │ │
│ │ │ Transitive │ │ Call │ │ Coupling │ │ │
│ │ │ Dependencies │ │ Chains │ │ Metrics │ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────────┘ │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │ │
│ │ │ Reverse │ │ Cycle │ │ Hub │ │ │
│ │ │ Deps │ │ Detection │ │ Nodes │ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────────┘ │ │
│ └───────────────────────────┬───────────────────────────────┘ │
└──────────────────────────────┼──────────────────────────────────┘
│
┌──────────────────────────────┼──────────────────────────────────┐
│ SurrealDB │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ Nodes │ │ Edges │ │ Chunks + Embeddings │ │
│ │ (AST + │ │ (calls, │ │ (HNSW vector index) │ │
│ │ FastML) │ │ imports) │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ SurrealQL Graph Functions │ │
│ │ fn::semantic_search_nodes_via_chunks │ │
│ │ fn::semantic_search_chunks_with_context │ │
│ │ fn::get_transitive_dependencies │ │
│ │ fn::trace_call_chain │ │
│ │ fn::calculate_coupling_metrics │ │
│ └────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Key insight: The agentic tools don’t just call one function. They reason about which graph operations to perform, chain them together, and synthesize results. A single agentic_impact call might:
- Search for the target component semantically
- Get its direct dependencies
- Trace transitive dependencies
- Check for circular dependencies
- Calculate coupling metrics
- Identify hub nodes that might be affected
- Synthesize all findings into an actionable answer
Supported Languages
CodeGraph uses tree-sitter for initial parsing and enhances results with FastML algorithms and supports:
Rust • Python • TypeScript • JavaScript • Go • Java • C++ • C • Swift • Kotlin • C# • Ruby • PHP • Dart
Provider Flexibility
Embeddings
Use any model with dimensions 384-4096:
- Local: Ollama, LM Studio, ONNX Runtime
- Cloud: OpenAI, Jina AI
LLM (for agentic reasoning)
- Local: Ollama, LM Studio
- Cloud: Anthropic Claude, OpenAI, xAI Grok, OpenAI Compliant
Database
- SurrealDB with HNSW vector index (2-5ms queries)
- Free cloud tier available at surrealdb.com/cloud
Configuration
Global config in ~/.codegraph/config.toml:
[embedding]
provider = "ollama"
model = "qwen3-embedding:0.6b"
dimension = 1024
[llm]
provider = "anthropic"
model = "claude-sonnet-4"
[database.surrealdb]
connection = "ws://localhost:3004"
namespace = "ouroboros"
database = "codegraph"
See INSTALLATION_GUIDE.md for complete configuration options.
Experimental graph schema (optional)
CodeGraph can run against an experimental SurrealDB graphdb-style schema (schema/codegraph_graph_experimental.surql) that is interoperable with the existing CodeGraph tools and indexing pipeline.
Compared to the relational/vanilla schema (schema/codegraph.surql), the experimental schema is designed for faster and more efficient graph-query operations (traversals, neighborhood expansion, and tool-driven graph analytics) on large codebases.
To use it:
- Load the schema into a dedicated database (once):
# Example (SurrealDB CLI)
surreal sql --conn ws://localhost:3004 --ns ouroboros --db codegraph_experimental < schema/codegraph_graph_experimental.surql
- Point CodeGraph at that database:
CODEGRAPH_USE_GRAPH_SCHEMA=true
CODEGRAPH_GRAPH_DB_DATABASE=codegraph_experimental
Notes:
- The schema file defines HNSW indexes for multiple embedding dimensions (384–4096) so you can switch embedding models without reworking the DB.
- Schema loading is not currently performed automatically at runtime; you must apply the
.surqlfile to the target database before indexing. CODEGRAPH_GRAPH_DB_DATABASEcontrols which Surreal database indexing/tools use whenCODEGRAPH_USE_GRAPH_SCHEMA=true.
Daemon Mode
Keep your index fresh automatically:
# With MCP server (recommended)
codegraph start stdio --watch
# Standalone daemon
codegraph daemon start /path/to/project --languages rust,typescript
Changes are detected, debounced, and re-indexed in the background.
What’s Next
- More language support
- Cross-repository analysis
- Custom graph schemas
- Plugin system for custom analyzers
Philosophy
CodeGraph exists because we believe AI coding assistants should be augmented, not replaced. The best AI-human collaboration happens when the AI has deep context about what you’re working with.
We’re not trying to replace your IDE, your type checker, or your tests. We’re giving your AI the context it needs to actually help.
Your codebase is a graph. Let your AI see it that way.
License
MIT
Links
- Installation Guide
- SurrealDB Cloud (free tier)
- Jina AI (free API tokens)
- Ollama (local models)

相似文章
@GitTrend0x: Claude Code 代码库智能大脑 27×省 Token 杀手级开源神器 https://github.com/repowise-dev/repowise… 这就是 Repowise,专为 AI 辅助工程团队打造的代码库智能平台!它把…
Repowise is an open-source tool that indexes codebases into four intelligence layers (dependency graph, git history, auto-documentation, architectural decisions) and exposes them via seven MCP tools to AI coding agents like Claude Code, achieving up to 27× token savings while maintaining answer quality.
@justloveabit: https://x.com/justloveabit/status/2055263377006747820
介绍Claude Code 2.1.142新版本与CodeGraph、MCP的组合使用,通过本地语义知识图谱大幅提升大型代码库的探索效率,tool call减少92%,速度提升71%。
@GitHub_Daily: 用 Claude Code 开发项目,代码库一大,每次探索代码结构都要扫一堆文件,工具调用多、速度慢,token 也跟着烧。 于是找到 CodeGraph 这个开源工具,给代码库预建一张语义知识图谱,让 Claude Code 直接查图而…
CodeGraph 是一个开源工具,为代码库预建语义知识图谱,让 Claude Code 直接查图而不是逐文件扫描,从而大幅减少工具调用次数(减少 92%)并提升探索速度(提升 71%),支持 19 种编程语言和 13 个框架。
@HowToAI_: 现在只需一条命令,您就能将 Claude Code 的工具调用次数削减94%。这个 MCP 服务器将您的代码库索引到…
一个新的 MCP 服务器通过将代码库索引到本地知识图谱中,将 Claude Code 的工具调用减少94%,使代理能够查询图谱而不是扫描文件。
colbymchenry/codegraph
CodeGraph 是一个开源工具,为代码库创建预索引的知识图谱,使 Claude Code 的探索代理能够即时查询符号关系和调用图,将工具调用次数减少高达 96%,探索时间减少 77%。