@colbymchenry/codegraph 0.6.6 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -502
- package/dist/bin/codegraph.d.ts +0 -5
- package/dist/bin/codegraph.d.ts.map +1 -1
- package/dist/bin/codegraph.js +217 -263
- package/dist/bin/codegraph.js.map +1 -1
- package/dist/bin/uninstall.d.ts +0 -1
- package/dist/bin/uninstall.d.ts.map +1 -1
- package/dist/bin/uninstall.js +3 -29
- package/dist/bin/uninstall.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/context/index.d.ts +3 -5
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +497 -46
- package/dist/context/index.js.map +1 -1
- package/dist/db/migrations.d.ts +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +10 -1
- package/dist/db/migrations.js.map +1 -1
- package/dist/db/queries.d.ts +53 -0
- package/dist/db/queries.d.ts.map +1 -1
- package/dist/db/queries.js +244 -24
- package/dist/db/queries.js.map +1 -1
- package/dist/db/schema.sql +1 -16
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -7
- package/dist/errors.js.map +1 -1
- package/dist/extraction/dfm-extractor.d.ts +31 -0
- package/dist/extraction/dfm-extractor.d.ts.map +1 -0
- package/dist/extraction/dfm-extractor.js +151 -0
- package/dist/extraction/dfm-extractor.js.map +1 -0
- package/dist/extraction/grammars.d.ts +9 -1
- package/dist/extraction/grammars.d.ts.map +1 -1
- package/dist/extraction/grammars.js +34 -2
- package/dist/extraction/grammars.js.map +1 -1
- package/dist/extraction/index.d.ts +7 -1
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +373 -29
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/languages/c-cpp.d.ts +4 -0
- package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
- package/dist/extraction/languages/c-cpp.js +126 -0
- package/dist/extraction/languages/c-cpp.js.map +1 -0
- package/dist/extraction/languages/csharp.d.ts +3 -0
- package/dist/extraction/languages/csharp.d.ts.map +1 -0
- package/dist/extraction/languages/csharp.js +72 -0
- package/dist/extraction/languages/csharp.js.map +1 -0
- package/dist/extraction/languages/dart.d.ts +3 -0
- package/dist/extraction/languages/dart.d.ts.map +1 -0
- package/dist/extraction/languages/dart.js +192 -0
- package/dist/extraction/languages/dart.js.map +1 -0
- package/dist/extraction/languages/go.d.ts +3 -0
- package/dist/extraction/languages/go.d.ts.map +1 -0
- package/dist/extraction/languages/go.js +58 -0
- package/dist/extraction/languages/go.js.map +1 -0
- package/dist/extraction/languages/index.d.ts +10 -0
- package/dist/extraction/languages/index.d.ts.map +1 -0
- package/dist/extraction/languages/index.js +43 -0
- package/dist/extraction/languages/index.js.map +1 -0
- package/dist/extraction/languages/java.d.ts +3 -0
- package/dist/extraction/languages/java.d.ts.map +1 -0
- package/dist/extraction/languages/java.js +64 -0
- package/dist/extraction/languages/java.js.map +1 -0
- package/dist/extraction/languages/javascript.d.ts +3 -0
- package/dist/extraction/languages/javascript.d.ts.map +1 -0
- package/dist/extraction/languages/javascript.js +90 -0
- package/dist/extraction/languages/javascript.js.map +1 -0
- package/dist/extraction/languages/kotlin.d.ts +3 -0
- package/dist/extraction/languages/kotlin.d.ts.map +1 -0
- package/dist/extraction/languages/kotlin.js +253 -0
- package/dist/extraction/languages/kotlin.js.map +1 -0
- package/dist/extraction/languages/pascal.d.ts +3 -0
- package/dist/extraction/languages/pascal.d.ts.map +1 -0
- package/dist/extraction/languages/pascal.js +66 -0
- package/dist/extraction/languages/pascal.js.map +1 -0
- package/dist/extraction/languages/php.d.ts +3 -0
- package/dist/extraction/languages/php.d.ts.map +1 -0
- package/dist/extraction/languages/php.js +107 -0
- package/dist/extraction/languages/php.js.map +1 -0
- package/dist/extraction/languages/python.d.ts +3 -0
- package/dist/extraction/languages/python.d.ts.map +1 -0
- package/dist/extraction/languages/python.js +56 -0
- package/dist/extraction/languages/python.js.map +1 -0
- package/dist/extraction/languages/ruby.d.ts +3 -0
- package/dist/extraction/languages/ruby.d.ts.map +1 -0
- package/dist/extraction/languages/ruby.js +114 -0
- package/dist/extraction/languages/ruby.js.map +1 -0
- package/dist/extraction/languages/rust.d.ts +3 -0
- package/dist/extraction/languages/rust.d.ts.map +1 -0
- package/dist/extraction/languages/rust.js +109 -0
- package/dist/extraction/languages/rust.js.map +1 -0
- package/dist/extraction/languages/swift.d.ts +3 -0
- package/dist/extraction/languages/swift.d.ts.map +1 -0
- package/dist/extraction/languages/swift.js +91 -0
- package/dist/extraction/languages/swift.js.map +1 -0
- package/dist/extraction/languages/typescript.d.ts +3 -0
- package/dist/extraction/languages/typescript.d.ts.map +1 -0
- package/dist/extraction/languages/typescript.js +129 -0
- package/dist/extraction/languages/typescript.js.map +1 -0
- package/dist/extraction/liquid-extractor.d.ts +52 -0
- package/dist/extraction/liquid-extractor.d.ts.map +1 -0
- package/dist/extraction/liquid-extractor.js +313 -0
- package/dist/extraction/liquid-extractor.js.map +1 -0
- package/dist/extraction/parse-worker.d.ts +8 -0
- package/dist/extraction/parse-worker.d.ts.map +1 -0
- package/dist/extraction/parse-worker.js +57 -0
- package/dist/extraction/parse-worker.js.map +1 -0
- package/dist/extraction/svelte-extractor.d.ts +47 -0
- package/dist/extraction/svelte-extractor.d.ts.map +1 -0
- package/dist/extraction/svelte-extractor.js +230 -0
- package/dist/extraction/svelte-extractor.js.map +1 -0
- package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
- package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
- package/dist/extraction/tree-sitter-helpers.js +103 -0
- package/dist/extraction/tree-sitter-helpers.js.map +1 -0
- package/dist/extraction/tree-sitter-types.d.ts +179 -0
- package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
- package/dist/extraction/tree-sitter-types.js +10 -0
- package/dist/extraction/tree-sitter-types.js.map +1 -0
- package/dist/extraction/tree-sitter.d.ts +67 -125
- package/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.js +1052 -1860
- package/dist/extraction/tree-sitter.js.map +1 -1
- package/dist/graph/traversal.d.ts.map +1 -1
- package/dist/graph/traversal.js +20 -2
- package/dist/graph/traversal.js.map +1 -1
- package/dist/index.d.ts +29 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -117
- package/dist/index.js.map +1 -1
- package/dist/installer/claude-md-template.d.ts +1 -1
- package/dist/installer/claude-md-template.d.ts.map +1 -1
- package/dist/installer/claude-md-template.js +15 -15
- package/dist/installer/config-writer.d.ts +2 -13
- package/dist/installer/config-writer.d.ts.map +1 -1
- package/dist/installer/config-writer.js +4 -87
- package/dist/installer/config-writer.js.map +1 -1
- package/dist/installer/index.d.ts +3 -4
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +118 -127
- package/dist/installer/index.js.map +1 -1
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +25 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tools.d.ts +33 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +405 -26
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/transport.d.ts.map +1 -1
- package/dist/mcp/transport.js +0 -2
- package/dist/mcp/transport.js.map +1 -1
- package/dist/resolution/frameworks/csharp.js +29 -84
- package/dist/resolution/frameworks/csharp.js.map +1 -1
- package/dist/resolution/frameworks/express.js +44 -48
- package/dist/resolution/frameworks/express.js.map +1 -1
- package/dist/resolution/frameworks/go.js +34 -70
- package/dist/resolution/frameworks/go.js.map +1 -1
- package/dist/resolution/frameworks/java.js +29 -87
- package/dist/resolution/frameworks/java.js.map +1 -1
- package/dist/resolution/frameworks/laravel.js +6 -6
- package/dist/resolution/frameworks/laravel.js.map +1 -1
- package/dist/resolution/frameworks/python.js +33 -98
- package/dist/resolution/frameworks/python.js.map +1 -1
- package/dist/resolution/frameworks/react.js +53 -76
- package/dist/resolution/frameworks/react.js.map +1 -1
- package/dist/resolution/frameworks/ruby.js +12 -24
- package/dist/resolution/frameworks/ruby.js.map +1 -1
- package/dist/resolution/frameworks/rust.js +26 -66
- package/dist/resolution/frameworks/rust.js.map +1 -1
- package/dist/resolution/frameworks/svelte.js +11 -31
- package/dist/resolution/frameworks/svelte.js.map +1 -1
- package/dist/resolution/frameworks/swift.js +42 -160
- package/dist/resolution/frameworks/swift.js.map +1 -1
- package/dist/resolution/index.d.ts +19 -6
- package/dist/resolution/index.d.ts.map +1 -1
- package/dist/resolution/index.js +300 -144
- package/dist/resolution/index.js.map +1 -1
- package/dist/resolution/name-matcher.d.ts +5 -0
- package/dist/resolution/name-matcher.d.ts.map +1 -1
- package/dist/resolution/name-matcher.js +148 -8
- package/dist/resolution/name-matcher.js.map +1 -1
- package/dist/resolution/types.d.ts +1 -1
- package/dist/resolution/types.d.ts.map +1 -1
- package/dist/search/query-utils.d.ts +26 -1
- package/dist/search/query-utils.d.ts.map +1 -1
- package/dist/search/query-utils.js +209 -9
- package/dist/search/query-utils.js.map +1 -1
- package/dist/sync/index.d.ts +2 -4
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +4 -3
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/watcher.d.ts +81 -0
- package/dist/sync/watcher.d.ts.map +1 -0
- package/dist/sync/watcher.js +184 -0
- package/dist/sync/watcher.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/shimmer-progress.d.ts +11 -0
- package/dist/ui/shimmer-progress.d.ts.map +1 -0
- package/dist/ui/shimmer-progress.js +90 -0
- package/dist/ui/shimmer-progress.js.map +1 -0
- package/dist/ui/shimmer-worker.d.ts +2 -0
- package/dist/ui/shimmer-worker.d.ts.map +1 -0
- package/dist/ui/shimmer-worker.js +112 -0
- package/dist/ui/shimmer-worker.js.map +1 -0
- package/dist/ui/types.d.ts +17 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +3 -0
- package/dist/ui/types.js.map +1 -0
- package/dist/vectors/embedder.js +1 -1
- package/dist/vectors/embedder.js.map +1 -1
- package/dist/visualizer/server.d.ts.map +1 -1
- package/dist/visualizer/server.js +3 -11
- package/dist/visualizer/server.js.map +1 -1
- package/package.json +7 -12
- package/scripts/postinstall.js +0 -68
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# CodeGraph
|
|
4
4
|
|
|
5
5
|
### Supercharge Claude Code with Semantic Code Intelligence
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**94% fewer tool calls · 77% faster exploration · 100% local**
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/@colbymchenry/codegraph)
|
|
10
10
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -28,132 +28,88 @@ npx @colbymchenry/codegraph
|
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
31
|
-
##
|
|
31
|
+
## Why CodeGraph?
|
|
32
32
|
|
|
33
|
-
When
|
|
33
|
+
When Claude Code explores a codebase, it spawns **Explore agents** that scan files with grep, glob, and Read — consuming tokens on every tool call.
|
|
34
34
|
|
|
35
|
-
**CodeGraph gives those agents a
|
|
35
|
+
**CodeGraph gives those agents a pre-indexed knowledge graph** — symbol relationships, call graphs, and code structure. Agents query the graph instantly instead of scanning files.
|
|
36
36
|
|
|
37
|
-
###
|
|
37
|
+
### Benchmark Results
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Tested across 6 real-world codebases comparing Claude Code's Explore agent **with** and **without** CodeGraph:
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
|
44
|
-
|
|
45
|
-
| **
|
|
46
|
-
| **
|
|
41
|
+
> **Average: 92% fewer tool calls · 71% faster**
|
|
42
|
+
|
|
43
|
+
| Codebase | With CG | Without CG | Improvement |
|
|
44
|
+
|----------|---------|------------|-------------|
|
|
45
|
+
| **VS Code** · TypeScript | 3 calls, 17s | 52 calls, 1m 37s | **94% fewer · 82% faster** |
|
|
46
|
+
| **Excalidraw** · TypeScript | 3 calls, 29s | 47 calls, 1m 45s | **94% fewer · 72% faster** |
|
|
47
|
+
| **Claude Code** · Python + Rust | 3 calls, 39s | 40 calls, 1m 8s | **93% fewer · 43% faster** |
|
|
48
|
+
| **Claude Code** · Java | 1 call, 19s | 26 calls, 1m 22s | **96% fewer · 77% faster** |
|
|
49
|
+
| **Alamofire** · Swift | 3 calls, 22s | 32 calls, 1m 39s | **91% fewer · 78% faster** |
|
|
50
|
+
| **Swift Compiler** · Swift/C++ | 6 calls, 35s | 37 calls, 2m 8s | **84% fewer · 73% faster** |
|
|
47
51
|
|
|
48
52
|
<details>
|
|
49
|
-
<summary><strong>Full benchmark
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
|
55
|
-
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
|
65
|
-
|
|
53
|
+
<summary><strong>Full benchmark details</strong></summary>
|
|
54
|
+
|
|
55
|
+
All tests used Claude Opus 4.6 (1M context) with Claude Code v2.1.91. Each test spawned a single Explore agent with the same question.
|
|
56
|
+
|
|
57
|
+
**Queries used:**
|
|
58
|
+
| Codebase | Query |
|
|
59
|
+
|----------|-------|
|
|
60
|
+
| VS Code | "How does the extension host communicate with the main process?" |
|
|
61
|
+
| Excalidraw | "How does collaborative editing and real-time sync work?" |
|
|
62
|
+
| Claude Code (Python+Rust) | "How does tool execution work end to end?" |
|
|
63
|
+
| Claude Code (Java) | "How does tool execution work end to end?" |
|
|
64
|
+
| Alamofire | "Trace how a request flows from Session.request() through to the URLSession layer" |
|
|
65
|
+
| Swift Compiler | "How does the Swift compiler handle error diagnostics?" |
|
|
66
|
+
|
|
67
|
+
**With CodeGraph — the agent uses `codegraph_explore` and stops:**
|
|
68
|
+
| Codebase | Files Indexed | Nodes | Tool Uses | Tokens | Time | File Reads |
|
|
69
|
+
|----------|--------------|-------|-----------|--------|------|------------|
|
|
70
|
+
| VS Code (TypeScript) | 4,002 | 59,377 | 3 | 56.6k | 17s | 0 |
|
|
71
|
+
| Excalidraw (TypeScript) | 626 | 9,859 | 3 | 57.1k | 29s | 0 |
|
|
72
|
+
| Claude Code (Python+Rust) | 115 | 3,080 | 3 | 67.1k | 39s | 0 |
|
|
73
|
+
| Claude Code (Java) | — | — | 1 | 40.8k | 19s | 0 |
|
|
74
|
+
| Alamofire (Swift) | 102 | 2,624 | 3 | 57.3k | 22s | 0 |
|
|
75
|
+
| Swift Compiler (Swift/C++) | 25,874 | 272,898 | 6 | 77.4k | 35s | 0 |
|
|
76
|
+
|
|
77
|
+
**Without CodeGraph — the agent uses grep, find, ls, and Read extensively:**
|
|
78
|
+
| Codebase | Tool Uses | Tokens | Time | File Reads |
|
|
79
|
+
|----------|-----------|--------|------|------------|
|
|
80
|
+
| VS Code (TypeScript) | 52 | 89.4k | 1m 37s | ~15 |
|
|
81
|
+
| Excalidraw (TypeScript) | 47 | 77.9k | 1m 45s | ~20 |
|
|
82
|
+
| Claude Code (Python+Rust) | 40 | 69.3k | 1m 8s | ~15 |
|
|
83
|
+
| Claude Code (Java) | 26 | 73.3k | 1m 22s | ~15 |
|
|
84
|
+
| Alamofire (Swift) | 32 | 52.4k | 1m 39s | ~10 |
|
|
85
|
+
| Swift Compiler (Swift/C++) | 37 | 99.1k | 2m 8s | ~20 |
|
|
86
|
+
|
|
87
|
+
**Key observations:**
|
|
88
|
+
- With CodeGraph, the agent **never fell back to reading files** — it trusted the codegraph_explore results completely
|
|
89
|
+
- Without CodeGraph, agents spent most of their time on discovery (find, ls, grep) before they could even start reading relevant code
|
|
90
|
+
- The Java codebase needed only **1 codegraph_explore call** to answer the entire question
|
|
91
|
+
- Cross-language queries (Python+Rust) worked seamlessly — CodeGraph's graph traversal found connections across language boundaries
|
|
92
|
+
- The Swift benchmark (Alamofire) traced a **9-step call chain** from `Session.request()` to `URLSession.dataTask()` — CodeGraph's graph traversal at depth 3 captured the full chain in one explore call
|
|
93
|
+
- The **Swift Compiler** benchmark is the largest codebase tested (**25,874 files, 272,898 nodes**) — CodeGraph indexed it in under 4 minutes and the agent answered a complex cross-cutting question with **6 explore calls and zero file reads** in 35 seconds
|
|
66
94
|
|
|
67
95
|
</details>
|
|
68
96
|
|
|
69
|
-
### 🔄 How It Works
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
73
|
-
│ Claude Code │
|
|
74
|
-
│ │
|
|
75
|
-
│ "Implement user authentication" │
|
|
76
|
-
│ │ │
|
|
77
|
-
│ ▼ │
|
|
78
|
-
│ ┌─────────────────┐ ┌─────────────────┐ │
|
|
79
|
-
│ │ Explore Agent │ ──── │ Explore Agent │ │
|
|
80
|
-
│ └────────┬────────┘ └────────┬────────┘ │
|
|
81
|
-
│ │ │ │
|
|
82
|
-
└───────────┼────────────────────────┼─────────────────────────────┘
|
|
83
|
-
│ │
|
|
84
|
-
▼ ▼
|
|
85
|
-
┌───────────────────────────────────────────────────────────────────┐
|
|
86
|
-
│ CodeGraph MCP Server │
|
|
87
|
-
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
88
|
-
│ │ Search │ │ Callers │ │ Context │ │
|
|
89
|
-
│ │ "auth" │ │ "login()" │ │ for task │ │
|
|
90
|
-
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
|
|
91
|
-
│ │ │ │ │
|
|
92
|
-
│ └────────────────┼────────────────┘ │
|
|
93
|
-
│ ▼ │
|
|
94
|
-
│ ┌───────────────────────┐ │
|
|
95
|
-
│ │ SQLite Graph DB │ │
|
|
96
|
-
│ │ • 387 symbols │ │
|
|
97
|
-
│ │ • 1,204 edges │ │
|
|
98
|
-
│ │ • Instant lookups │ │
|
|
99
|
-
│ └───────────────────────┘ │
|
|
100
|
-
└───────────────────────────────────────────────────────────────────┘
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**Without CodeGraph:** Explore agents use `grep`, `glob`, and `Read` to scan files → many API calls, high token usage
|
|
104
|
-
|
|
105
|
-
**With CodeGraph:** Explore agents query the graph via MCP tools → instant results, local processing, fewer tokens
|
|
106
|
-
|
|
107
97
|
---
|
|
108
98
|
|
|
109
|
-
##
|
|
110
|
-
|
|
111
|
-
<table>
|
|
112
|
-
<tr>
|
|
113
|
-
<td width="33%" valign="top">
|
|
114
|
-
|
|
115
|
-
### 🧠 Smart Context Building
|
|
116
|
-
One tool call returns everything Claude needs—entry points, related symbols, and code snippets. No more expensive exploration agents.
|
|
117
|
-
|
|
118
|
-
</td>
|
|
119
|
-
<td width="33%" valign="top">
|
|
120
|
-
|
|
121
|
-
### 🔍 Semantic Search
|
|
122
|
-
Find code by meaning, not just text. Search for "authentication" and find `login`, `validateToken`, `AuthService`—even with different naming conventions.
|
|
123
|
-
|
|
124
|
-
</td>
|
|
125
|
-
<td width="33%" valign="top">
|
|
126
|
-
|
|
127
|
-
### 📈 Impact Analysis
|
|
128
|
-
Know exactly what breaks before you change it. Trace callers, callees, and the full impact radius of any symbol.
|
|
99
|
+
## Key Features
|
|
129
100
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Dart, Svelte, Liquid, Pascal/Delphi
|
|
137
|
-
|
|
138
|
-
</td>
|
|
139
|
-
<td width="33%" valign="top">
|
|
140
|
-
|
|
141
|
-
### 🔒 100% Local
|
|
142
|
-
No data leaves your machine. No API keys. No external services. Everything runs on your local SQLite database.
|
|
143
|
-
|
|
144
|
-
</td>
|
|
145
|
-
<td width="33%" valign="top">
|
|
146
|
-
|
|
147
|
-
### ⚡ Always Fresh
|
|
148
|
-
Claude Code hooks automatically sync the index as you work. Your code intelligence is always up to date.
|
|
149
|
-
|
|
150
|
-
</td>
|
|
151
|
-
</tr>
|
|
152
|
-
</table>
|
|
101
|
+
| | |
|
|
102
|
+
|---|---|
|
|
103
|
+
| **Smart Context Building** | One tool call returns entry points, related symbols, and code snippets — no expensive exploration agents |
|
|
104
|
+
| **Full-Text Search** | Find code by name instantly across your entire codebase, powered by FTS5 |
|
|
105
|
+
| **Impact Analysis** | Trace callers, callees, and the full impact radius of any symbol before making changes |
|
|
106
|
+
| **Always Fresh** | File watcher uses native OS events (FSEvents/inotify/ReadDirectoryChangesW) with debounced auto-sync — the graph stays current as you code, zero config |
|
|
107
|
+
| **19+ Languages** | TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Dart, Svelte, Liquid, Pascal/Delphi |
|
|
108
|
+
| **100% Local** | No data leaves your machine. No API keys. No external services. SQLite database only |
|
|
153
109
|
|
|
154
110
|
---
|
|
155
111
|
|
|
156
|
-
##
|
|
112
|
+
## Quick Start
|
|
157
113
|
|
|
158
114
|
### 1. Run the Installer
|
|
159
115
|
|
|
@@ -161,13 +117,11 @@ Claude Code hooks automatically sync the index as you work. Your code intelligen
|
|
|
161
117
|
npx @colbymchenry/codegraph
|
|
162
118
|
```
|
|
163
119
|
|
|
164
|
-
The
|
|
165
|
-
- Prompt to install `codegraph` globally (needed for
|
|
120
|
+
The installer will:
|
|
121
|
+
- Prompt to install `codegraph` globally (needed for the MCP server)
|
|
166
122
|
- Configure the MCP server in `~/.claude.json`
|
|
167
123
|
- Set up auto-allow permissions for CodeGraph tools
|
|
168
|
-
-
|
|
169
|
-
- Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
|
|
170
|
-
- Install Claude Code hooks for automatic index syncing
|
|
124
|
+
- Add global instructions to `~/.claude/CLAUDE.md`
|
|
171
125
|
- Optionally initialize your current project
|
|
172
126
|
|
|
173
127
|
### 2. Restart Claude Code
|
|
@@ -176,20 +130,16 @@ Restart Claude Code for the MCP server to load.
|
|
|
176
130
|
|
|
177
131
|
### 3. Initialize Projects
|
|
178
132
|
|
|
179
|
-
For each project you want to use CodeGraph with:
|
|
180
|
-
|
|
181
133
|
```bash
|
|
182
134
|
cd your-project
|
|
183
135
|
codegraph init -i
|
|
184
136
|
```
|
|
185
137
|
|
|
186
|
-
That's it! Claude Code will
|
|
138
|
+
That's it! Claude Code will use CodeGraph tools automatically when a `.codegraph/` directory exists.
|
|
187
139
|
|
|
188
140
|
<details>
|
|
189
141
|
<summary><strong>Manual Setup (Alternative)</strong></summary>
|
|
190
142
|
|
|
191
|
-
If you prefer manual configuration:
|
|
192
|
-
|
|
193
143
|
**Install globally:**
|
|
194
144
|
```bash
|
|
195
145
|
npm install -g @colbymchenry/codegraph
|
|
@@ -231,7 +181,7 @@ npm install -g @colbymchenry/codegraph
|
|
|
231
181
|
<details>
|
|
232
182
|
<summary><strong>Global Instructions Reference</strong></summary>
|
|
233
183
|
|
|
234
|
-
The installer automatically adds these instructions to `~/.claude/CLAUDE.md
|
|
184
|
+
The installer automatically adds these instructions to `~/.claude/CLAUDE.md`:
|
|
235
185
|
|
|
236
186
|
```markdown
|
|
237
187
|
## CodeGraph
|
|
@@ -240,26 +190,25 @@ CodeGraph builds a semantic knowledge graph of codebases for faster, smarter cod
|
|
|
240
190
|
|
|
241
191
|
### If `.codegraph/` exists in the project
|
|
242
192
|
|
|
243
|
-
**
|
|
193
|
+
**NEVER call `codegraph_explore` or `codegraph_context` directly in the main session.** These tools return large amounts of source code that fills up main session context. Instead, ALWAYS spawn an Explore agent for any exploration question (e.g., "how does X work?", "explain the Y system", "where is Z implemented?").
|
|
244
194
|
|
|
245
|
-
|
|
246
|
-
|------|---------|
|
|
247
|
-
| `codegraph_search` | Find symbols by name (functions, classes, types) |
|
|
248
|
-
| `codegraph_context` | Get relevant code context for a task |
|
|
249
|
-
| `codegraph_callers` | Find what calls a function |
|
|
250
|
-
| `codegraph_callees` | Find what a function calls |
|
|
251
|
-
| `codegraph_impact` | See what's affected by changing a symbol |
|
|
252
|
-
| `codegraph_node` | Get details + source code for a symbol |
|
|
253
|
-
| `codegraph_files` | Get project file structure from the index |
|
|
195
|
+
**When spawning Explore agents**, include this instruction in the prompt:
|
|
254
196
|
|
|
255
|
-
|
|
197
|
+
> This project has CodeGraph initialized (.codegraph/ exists). Use `codegraph_explore` as your PRIMARY tool — it returns full source code sections from all relevant files in one call.
|
|
198
|
+
>
|
|
199
|
+
> **Rules:**
|
|
200
|
+
> 1. Follow the explore call budget in the `codegraph_explore` tool description — it scales automatically based on project size.
|
|
201
|
+
> 2. Do NOT re-read files that codegraph_explore already returned source code for. The source sections are complete and authoritative.
|
|
202
|
+
> 3. Only fall back to grep/glob/read for files listed under "Additional relevant files" if you need more detail, or if codegraph returned no results.
|
|
256
203
|
|
|
257
|
-
|
|
204
|
+
**The main session may only use these lightweight tools directly** (for targeted lookups before making edits, not for exploration):
|
|
258
205
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
206
|
+
| Tool | Use For |
|
|
207
|
+
|------|---------|
|
|
208
|
+
| `codegraph_search` | Find symbols by name |
|
|
209
|
+
| `codegraph_callers` / `codegraph_callees` | Trace call flow |
|
|
210
|
+
| `codegraph_impact` | Check what's affected before editing |
|
|
211
|
+
| `codegraph_node` | Get a single symbol's details |
|
|
263
212
|
|
|
264
213
|
### If `.codegraph/` does NOT exist
|
|
265
214
|
|
|
@@ -272,399 +221,164 @@ At the start of a session, ask the user if they'd like to initialize CodeGraph:
|
|
|
272
221
|
|
|
273
222
|
---
|
|
274
223
|
|
|
275
|
-
##
|
|
276
|
-
|
|
277
|
-
- Node.js >= 18.0.0
|
|
278
|
-
|
|
279
|
-
---
|
|
280
|
-
|
|
281
|
-
## 💻 CLI Usage
|
|
282
|
-
|
|
283
|
-
```bash
|
|
284
|
-
codegraph # Run interactive installer
|
|
285
|
-
codegraph install # Run interactive installer (explicit)
|
|
286
|
-
codegraph init [path] # Initialize in a project
|
|
287
|
-
codegraph uninit [path] # Remove CodeGraph from a project
|
|
288
|
-
codegraph index [path] # Full index
|
|
289
|
-
codegraph sync [path] # Incremental update
|
|
290
|
-
codegraph status [path] # Show statistics
|
|
291
|
-
codegraph query <search> # Search symbols
|
|
292
|
-
codegraph files [path] # Show project file structure
|
|
293
|
-
codegraph context <task> # Build context for AI
|
|
294
|
-
codegraph affected [files] # Find test files affected by changes
|
|
295
|
-
codegraph serve --mcp # Start MCP server
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
## 📖 CLI Commands
|
|
299
|
-
|
|
300
|
-
### `codegraph` / `codegraph install`
|
|
301
|
-
|
|
302
|
-
Run the interactive installer for Claude Code integration. Configures MCP server and permissions automatically.
|
|
303
|
-
|
|
304
|
-
```bash
|
|
305
|
-
codegraph # Run installer (when no args)
|
|
306
|
-
codegraph install # Run installer (explicit)
|
|
307
|
-
npx @colbymchenry/codegraph # Run via npx (no global install needed)
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
The installer will:
|
|
311
|
-
1. Prompt to install `codegraph` globally (needed for hooks & MCP server)
|
|
312
|
-
2. Ask for installation location (global `~/.claude` or local `./.claude`)
|
|
313
|
-
3. Optionally set up auto-allow permissions
|
|
314
|
-
4. Ask about [anonymous error reporting](#-telemetry) (opt-out available)
|
|
315
|
-
5. Configure the MCP server in `claude.json`
|
|
316
|
-
6. Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
|
|
317
|
-
7. Install Claude Code hooks for automatic index syncing
|
|
318
|
-
8. For local installs: initialize and index the current project
|
|
319
|
-
|
|
320
|
-
### `codegraph init [path]`
|
|
321
|
-
|
|
322
|
-
Initialize CodeGraph in a project directory. Creates a `.codegraph/` directory with the database and configuration.
|
|
323
|
-
|
|
324
|
-
```bash
|
|
325
|
-
codegraph init # Initialize in current directory
|
|
326
|
-
codegraph init /path/to/project # Initialize in specific directory
|
|
327
|
-
codegraph init --index # Initialize and immediately index
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
### `codegraph uninit [path]`
|
|
224
|
+
## How It Works
|
|
331
225
|
|
|
332
|
-
Remove CodeGraph from a project. Deletes the `.codegraph/` directory and all indexed data.
|
|
333
|
-
|
|
334
|
-
```bash
|
|
335
|
-
codegraph uninit # Remove from current directory
|
|
336
|
-
codegraph uninit --force # Skip confirmation prompt
|
|
337
226
|
```
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
227
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
228
|
+
│ Claude Code │
|
|
229
|
+
│ │
|
|
230
|
+
│ "Implement user authentication" │
|
|
231
|
+
│ │ │
|
|
232
|
+
│ ▼ │
|
|
233
|
+
│ ┌─────────────────┐ ┌─────────────────┐ │
|
|
234
|
+
│ │ Explore Agent │ ──── │ Explore Agent │ │
|
|
235
|
+
│ └────────┬────────┘ └────────┬────────┘ │
|
|
236
|
+
│ │ │ │
|
|
237
|
+
└───────────┼────────────────────────┼─────────────────────────────┘
|
|
238
|
+
│ │
|
|
239
|
+
▼ ▼
|
|
240
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
241
|
+
│ CodeGraph MCP Server │
|
|
242
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
243
|
+
│ │ Search │ │ Callers │ │ Context │ │
|
|
244
|
+
│ │ "auth" │ │ "login()" │ │ for task │ │
|
|
245
|
+
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
|
|
246
|
+
│ │ │ │ │
|
|
247
|
+
│ └────────────────┼────────────────┘ │
|
|
248
|
+
│ ▼ │
|
|
249
|
+
│ ┌───────────────────────┐ │
|
|
250
|
+
│ │ SQLite Graph DB │ │
|
|
251
|
+
│ │ • 387 symbols │ │
|
|
252
|
+
│ │ • 1,204 edges │ │
|
|
253
|
+
│ │ • Instant lookups │ │
|
|
254
|
+
│ └───────────────────────┘ │
|
|
255
|
+
└───────────────────────────────────────────────────────────────────┘
|
|
364
256
|
```
|
|
365
257
|
|
|
366
|
-
|
|
367
|
-
- Files indexed, nodes, edges
|
|
368
|
-
- Nodes by kind (functions, classes, methods, etc.)
|
|
369
|
-
- Files by language
|
|
370
|
-
- Pending changes (if any)
|
|
371
|
-
|
|
372
|
-
### `codegraph query <search>`
|
|
258
|
+
1. **Extraction** — [tree-sitter](https://tree-sitter.github.io/) parses source code into ASTs. Language-specific queries extract nodes (functions, classes, methods) and edges (calls, imports, extends, implements).
|
|
373
259
|
|
|
374
|
-
|
|
260
|
+
2. **Storage** — Everything goes into a local SQLite database (`.codegraph/codegraph.db`) with FTS5 full-text search.
|
|
375
261
|
|
|
376
|
-
|
|
377
|
-
codegraph query "authenticate" # Search for symbols
|
|
378
|
-
codegraph query "User" --kind class # Filter by kind
|
|
379
|
-
codegraph query "process" --limit 20 # Limit results
|
|
380
|
-
codegraph query "validate" --json # Output as JSON
|
|
381
|
-
```
|
|
262
|
+
3. **Resolution** — After extraction, references are resolved: function calls → definitions, imports → source files, class inheritance, and framework-specific patterns.
|
|
382
263
|
|
|
383
|
-
|
|
264
|
+
4. **Auto-Sync** — The MCP server watches your project using native OS file events. Changes are debounced (2-second quiet window), filtered to source files only, and incrementally synced. The graph stays fresh as you code — no configuration needed.
|
|
384
265
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
```bash
|
|
388
|
-
codegraph files # Show file tree
|
|
389
|
-
codegraph files --format flat # Simple list
|
|
390
|
-
codegraph files --format grouped # Group by language
|
|
391
|
-
codegraph files --filter src/components # Filter by directory
|
|
392
|
-
codegraph files --pattern "*.test.ts" # Filter by glob pattern
|
|
393
|
-
codegraph files --max-depth 2 # Limit tree depth
|
|
394
|
-
codegraph files --no-metadata # Hide language/symbol counts
|
|
395
|
-
codegraph files --json # Output as JSON
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
### `codegraph context <task>`
|
|
266
|
+
---
|
|
399
267
|
|
|
400
|
-
|
|
268
|
+
## CLI Reference
|
|
401
269
|
|
|
402
270
|
```bash
|
|
403
|
-
codegraph
|
|
404
|
-
codegraph
|
|
405
|
-
codegraph
|
|
271
|
+
codegraph # Run interactive installer
|
|
272
|
+
codegraph install # Run installer (explicit)
|
|
273
|
+
codegraph init [path] # Initialize in a project (--index to also index)
|
|
274
|
+
codegraph uninit [path] # Remove CodeGraph from a project (--force to skip prompt)
|
|
275
|
+
codegraph index [path] # Full index (--force to re-index, --quiet for less output)
|
|
276
|
+
codegraph sync [path] # Incremental update
|
|
277
|
+
codegraph status [path] # Show statistics
|
|
278
|
+
codegraph query <search> # Search symbols (--kind, --limit, --json)
|
|
279
|
+
codegraph files [path] # Show file structure (--format, --filter, --max-depth, --json)
|
|
280
|
+
codegraph context <task> # Build context for AI (--format, --max-nodes)
|
|
281
|
+
codegraph affected [files...] # Find test files affected by changes (see below)
|
|
282
|
+
codegraph serve --mcp # Start MCP server
|
|
406
283
|
```
|
|
407
284
|
|
|
408
|
-
### `codegraph affected
|
|
285
|
+
### `codegraph affected`
|
|
409
286
|
|
|
410
|
-
|
|
287
|
+
Traces import dependencies transitively to find which test files are affected by changed source files.
|
|
411
288
|
|
|
412
289
|
```bash
|
|
413
290
|
codegraph affected src/utils.ts src/api.ts # Pass files as arguments
|
|
414
291
|
git diff --name-only | codegraph affected --stdin # Pipe from git diff
|
|
415
|
-
codegraph affected --stdin --json < changed.txt # JSON output
|
|
416
292
|
codegraph affected src/auth.ts --filter "e2e/*" # Custom test file pattern
|
|
417
|
-
codegraph affected src/lib.ts --depth 3 --quiet # Shallow search, paths only
|
|
418
293
|
```
|
|
419
294
|
|
|
420
|
-
**Options:**
|
|
421
|
-
|
|
422
295
|
| Option | Description | Default |
|
|
423
296
|
|--------|-------------|---------|
|
|
424
|
-
| `--stdin` | Read file list from stdin
|
|
297
|
+
| `--stdin` | Read file list from stdin | `false` |
|
|
425
298
|
| `-d, --depth <n>` | Max dependency traversal depth | `5` |
|
|
426
299
|
| `-f, --filter <glob>` | Custom glob to identify test files | auto-detect |
|
|
427
300
|
| `-j, --json` | Output as JSON | `false` |
|
|
428
|
-
| `-q, --quiet` | Output file paths only
|
|
429
|
-
| `-p, --path <path>` | Project path | auto-detect |
|
|
430
|
-
|
|
431
|
-
**How it works:**
|
|
432
|
-
|
|
433
|
-
1. For each changed file, BFS-traverses its transitive dependents (files that import from it, directly or indirectly)
|
|
434
|
-
2. Filters results to test files using common conventions (`*.spec.*`, `*.test.*`, `e2e/`, `tests/`, `__tests__/`) or a custom `--filter` glob
|
|
435
|
-
3. Changed files that are themselves test files are always included
|
|
301
|
+
| `-q, --quiet` | Output file paths only | `false` |
|
|
436
302
|
|
|
437
|
-
**
|
|
303
|
+
**CI/hook example:**
|
|
438
304
|
|
|
439
305
|
```bash
|
|
440
306
|
#!/usr/bin/env bash
|
|
441
|
-
# In a pre-commit hook or CI step:
|
|
442
307
|
AFFECTED=$(git diff --name-only HEAD | codegraph affected --stdin --quiet)
|
|
443
308
|
if [ -n "$AFFECTED" ]; then
|
|
444
|
-
echo "Running affected tests..."
|
|
445
309
|
npx vitest run $AFFECTED
|
|
446
310
|
fi
|
|
447
311
|
```
|
|
448
312
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
Start CodeGraph as an MCP server for AI assistants.
|
|
452
|
-
|
|
453
|
-
```bash
|
|
454
|
-
codegraph serve # Show MCP configuration help
|
|
455
|
-
codegraph serve --mcp # Start MCP server (stdio)
|
|
456
|
-
codegraph serve --mcp --path /project # Specify project path
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
## 🔌 MCP Tools Reference
|
|
460
|
-
|
|
461
|
-
When running as an MCP server, CodeGraph exposes these tools to AI assistants. **These tools are designed to be used by Claude's Explore agents** for faster, more efficient codebase exploration.
|
|
462
|
-
|
|
463
|
-
### `codegraph_context`
|
|
464
|
-
|
|
465
|
-
Build context for a specific task. Good for focused queries.
|
|
466
|
-
|
|
467
|
-
```
|
|
468
|
-
codegraph_context(task: "fix checkout validation bug", maxNodes: 20)
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
### `codegraph_search`
|
|
472
|
-
|
|
473
|
-
Quick symbol search by name. Returns locations only.
|
|
474
|
-
|
|
475
|
-
```
|
|
476
|
-
codegraph_search(query: "UserService", kind: "class", limit: 10)
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
### `codegraph_callers` / `codegraph_callees`
|
|
480
|
-
|
|
481
|
-
Find what calls a function, or what a function calls.
|
|
482
|
-
|
|
483
|
-
```
|
|
484
|
-
codegraph_callers(symbol: "validatePayment", limit: 20)
|
|
485
|
-
codegraph_callees(symbol: "processOrder", limit: 20)
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
### `codegraph_impact`
|
|
489
|
-
|
|
490
|
-
Analyze what code would be affected by changing a symbol.
|
|
491
|
-
|
|
492
|
-
```
|
|
493
|
-
codegraph_impact(symbol: "UserService", depth: 2)
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
### `codegraph_node`
|
|
497
|
-
|
|
498
|
-
Get details about a specific symbol. Use `includeCode: true` only when needed.
|
|
499
|
-
|
|
500
|
-
```
|
|
501
|
-
codegraph_node(symbol: "authenticate", includeCode: true)
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
### `codegraph_files`
|
|
505
|
-
|
|
506
|
-
Get the project file structure from the index. Faster than filesystem scanning.
|
|
507
|
-
|
|
508
|
-
```
|
|
509
|
-
codegraph_files(path: "src/components", format: "tree", includeMetadata: true)
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
### `codegraph_status`
|
|
513
|
-
|
|
514
|
-
Check index health and statistics.
|
|
515
|
-
|
|
516
|
-
### How It Works With Claude Code
|
|
313
|
+
---
|
|
517
314
|
|
|
518
|
-
|
|
315
|
+
## MCP Tools
|
|
519
316
|
|
|
520
|
-
|
|
521
|
-
|-------------------|----------------|---------|
|
|
522
|
-
| `grep -r "auth"` | `codegraph_search("auth")` | Instant symbol lookup |
|
|
523
|
-
| Multiple `Read` calls | `codegraph_context(task)` | Related code in one call |
|
|
524
|
-
| Manual file tracing | `codegraph_callers/callees` | Call graph traversal |
|
|
525
|
-
| Guessing impact | `codegraph_impact(symbol)` | Know what breaks |
|
|
526
|
-
| `Glob`/`find` scanning | `codegraph_files(path)` | Indexed file structure |
|
|
317
|
+
When running as an MCP server, CodeGraph exposes these tools to Claude Code:
|
|
527
318
|
|
|
528
|
-
|
|
319
|
+
| Tool | Purpose |
|
|
320
|
+
|------|---------|
|
|
321
|
+
| `codegraph_search` | Find symbols by name across the codebase |
|
|
322
|
+
| `codegraph_context` | Build relevant code context for a task |
|
|
323
|
+
| `codegraph_callers` | Find what calls a function |
|
|
324
|
+
| `codegraph_callees` | Find what a function calls |
|
|
325
|
+
| `codegraph_impact` | Analyze what code is affected by changing a symbol |
|
|
326
|
+
| `codegraph_node` | Get details about a specific symbol (optionally with source code) |
|
|
327
|
+
| `codegraph_files` | Get indexed file structure (faster than filesystem scanning) |
|
|
328
|
+
| `codegraph_status` | Check index health and statistics |
|
|
529
329
|
|
|
530
|
-
|
|
330
|
+
---
|
|
531
331
|
|
|
532
|
-
|
|
332
|
+
## Library Usage
|
|
533
333
|
|
|
534
334
|
```typescript
|
|
535
335
|
import CodeGraph from '@colbymchenry/codegraph';
|
|
536
336
|
|
|
537
|
-
// Initialize a new project
|
|
538
337
|
const cg = await CodeGraph.init('/path/to/project');
|
|
338
|
+
// Or: const cg = await CodeGraph.open('/path/to/project');
|
|
539
339
|
|
|
540
|
-
// Or open an existing one
|
|
541
|
-
const cg = await CodeGraph.open('/path/to/project');
|
|
542
|
-
|
|
543
|
-
// Index with progress callback
|
|
544
340
|
await cg.indexAll({
|
|
545
|
-
onProgress: (
|
|
546
|
-
console.log(`${progress.phase}: ${progress.current}/${progress.total}`);
|
|
547
|
-
}
|
|
341
|
+
onProgress: (p) => console.log(`${p.phase}: ${p.current}/${p.total}`)
|
|
548
342
|
});
|
|
549
343
|
|
|
550
|
-
// Search for symbols
|
|
551
344
|
const results = cg.searchNodes('UserService');
|
|
345
|
+
const callers = cg.getCallers(results[0].node.id);
|
|
346
|
+
const context = await cg.buildContext('fix login bug', { maxNodes: 20, includeCode: true, format: 'markdown' });
|
|
347
|
+
const impact = cg.getImpactRadius(results[0].node.id, 2);
|
|
552
348
|
|
|
553
|
-
//
|
|
554
|
-
|
|
555
|
-
const callers = cg.getCallers(node.id);
|
|
556
|
-
|
|
557
|
-
// Build context for a task
|
|
558
|
-
const context = await cg.buildContext('fix login bug', {
|
|
559
|
-
maxNodes: 20,
|
|
560
|
-
includeCode: true,
|
|
561
|
-
format: 'markdown'
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
// Get impact radius
|
|
565
|
-
const impact = cg.getImpactRadius(node.id, 2);
|
|
566
|
-
|
|
567
|
-
// Sync changes
|
|
568
|
-
const syncResult = await cg.sync();
|
|
569
|
-
|
|
570
|
-
// Clean up
|
|
349
|
+
cg.watch(); // auto-sync on file changes
|
|
350
|
+
cg.unwatch(); // stop watching
|
|
571
351
|
cg.close();
|
|
572
352
|
```
|
|
573
353
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
### 1. Extraction
|
|
577
|
-
|
|
578
|
-
CodeGraph uses [tree-sitter](https://tree-sitter.github.io/) to parse source code into ASTs. Language-specific queries (`.scm` files) extract:
|
|
579
|
-
|
|
580
|
-
- **Nodes**: Functions, methods, classes, interfaces, types, variables
|
|
581
|
-
- **Edges**: Calls, imports, extends, implements, returns_type
|
|
582
|
-
|
|
583
|
-
Each node gets a unique ID based on its kind, file path, name, and line number.
|
|
584
|
-
|
|
585
|
-
### 2. Storage
|
|
586
|
-
|
|
587
|
-
All data is stored in a local SQLite database (`.codegraph/codegraph.db`):
|
|
588
|
-
|
|
589
|
-
- **nodes** table: All code entities with metadata
|
|
590
|
-
- **edges** table: Relationships between nodes
|
|
591
|
-
- **files** table: File tracking for incremental updates
|
|
592
|
-
- **unresolved_refs** table: References pending resolution
|
|
593
|
-
- **vectors** table: Embeddings stored as BLOBs for semantic search
|
|
594
|
-
- **nodes_fts**: FTS5 virtual table for full-text search
|
|
595
|
-
- **schema_versions** table: Schema version tracking
|
|
596
|
-
- **project_metadata** table: Project-level key-value metadata
|
|
597
|
-
|
|
598
|
-
### 3. Reference Resolution
|
|
599
|
-
|
|
600
|
-
After extraction, CodeGraph resolves references:
|
|
601
|
-
|
|
602
|
-
1. Match function calls to function definitions
|
|
603
|
-
2. Resolve imports to their source files
|
|
604
|
-
3. Link class inheritance and interface implementations
|
|
605
|
-
4. Apply framework-specific patterns (Express routes, etc.)
|
|
606
|
-
|
|
607
|
-
### 4. Semantic Search
|
|
608
|
-
|
|
609
|
-
CodeGraph uses local embeddings (via [@xenova/transformers](https://github.com/xenova/transformers.js)) to enable semantic search:
|
|
610
|
-
|
|
611
|
-
1. Code symbols are embedded using a transformer model
|
|
612
|
-
2. Queries are embedded and compared using cosine similarity
|
|
613
|
-
3. Results are ranked by relevance
|
|
614
|
-
|
|
615
|
-
### 5. Graph Queries
|
|
616
|
-
|
|
617
|
-
The graph structure enables powerful queries:
|
|
618
|
-
|
|
619
|
-
- **Callers/Callees**: Direct call relationships
|
|
620
|
-
- **Impact Radius**: BFS traversal to find all potentially affected code
|
|
621
|
-
- **Dependencies**: What a symbol depends on
|
|
622
|
-
- **Dependents**: What depends on a symbol
|
|
623
|
-
|
|
624
|
-
### 6. Context Building
|
|
625
|
-
|
|
626
|
-
When you request context for a task:
|
|
627
|
-
|
|
628
|
-
1. Semantic search finds relevant entry points
|
|
629
|
-
2. Graph traversal expands to related code
|
|
630
|
-
3. Code snippets are extracted
|
|
631
|
-
4. Results are formatted for AI consumption
|
|
354
|
+
---
|
|
632
355
|
|
|
633
|
-
##
|
|
356
|
+
## Configuration
|
|
634
357
|
|
|
635
|
-
The `.codegraph/config.json` file controls indexing
|
|
358
|
+
The `.codegraph/config.json` file controls indexing:
|
|
636
359
|
|
|
637
360
|
```json
|
|
638
361
|
{
|
|
639
362
|
"version": 1,
|
|
640
363
|
"languages": ["typescript", "javascript"],
|
|
641
|
-
"exclude": [
|
|
642
|
-
"node_modules/**",
|
|
643
|
-
"dist/**",
|
|
644
|
-
"build/**",
|
|
645
|
-
"*.min.js"
|
|
646
|
-
],
|
|
364
|
+
"exclude": ["node_modules/**", "dist/**", "build/**", "*.min.js"],
|
|
647
365
|
"frameworks": [],
|
|
648
366
|
"maxFileSize": 1048576,
|
|
649
367
|
"extractDocstrings": true,
|
|
650
|
-
"trackCallSites": true
|
|
651
|
-
"enableEmbeddings": false
|
|
368
|
+
"trackCallSites": true
|
|
652
369
|
}
|
|
653
370
|
```
|
|
654
371
|
|
|
655
|
-
### Options
|
|
656
|
-
|
|
657
372
|
| Option | Description | Default |
|
|
658
373
|
|--------|-------------|---------|
|
|
659
374
|
| `languages` | Languages to index (auto-detected if empty) | `[]` |
|
|
660
375
|
| `exclude` | Glob patterns to ignore | `["node_modules/**", ...]` |
|
|
661
376
|
| `frameworks` | Framework hints for better resolution | `[]` |
|
|
662
377
|
| `maxFileSize` | Skip files larger than this (bytes) | `1048576` (1MB) |
|
|
663
|
-
| `extractDocstrings` |
|
|
664
|
-
| `trackCallSites` |
|
|
665
|
-
| `enableEmbeddings` | Enable semantic search embeddings | `false` |
|
|
378
|
+
| `extractDocstrings` | Extract docstrings from code | `true` |
|
|
379
|
+
| `trackCallSites` | Track call site locations | `true` |
|
|
666
380
|
|
|
667
|
-
##
|
|
381
|
+
## Supported Languages
|
|
668
382
|
|
|
669
383
|
| Language | Extension | Status |
|
|
670
384
|
|----------|-----------|--------|
|
|
@@ -679,60 +393,24 @@ The `.codegraph/config.json` file controls indexing behavior:
|
|
|
679
393
|
| Ruby | `.rb` | Full support |
|
|
680
394
|
| C | `.c`, `.h` | Full support |
|
|
681
395
|
| C++ | `.cpp`, `.hpp`, `.cc` | Full support |
|
|
682
|
-
| Swift | `.swift` |
|
|
683
|
-
| Kotlin | `.kt`, `.kts` |
|
|
396
|
+
| Swift | `.swift` | Full support |
|
|
397
|
+
| Kotlin | `.kt`, `.kts` | Full support |
|
|
684
398
|
| Dart | `.dart` | Full support |
|
|
685
399
|
| Svelte | `.svelte` | Full support (script extraction, Svelte 5 runes, SvelteKit routes) |
|
|
686
400
|
| Liquid | `.liquid` | Full support |
|
|
687
401
|
| Pascal / Delphi | `.pas`, `.dpr`, `.dpk`, `.lpr` | Full support (classes, records, interfaces, enums, DFM/FMX form files) |
|
|
688
402
|
|
|
689
|
-
##
|
|
690
|
-
|
|
691
|
-
### "CodeGraph not initialized"
|
|
403
|
+
## Troubleshooting
|
|
692
404
|
|
|
693
|
-
Run `codegraph init` in your project directory first.
|
|
405
|
+
**"CodeGraph not initialized"** — Run `codegraph init` in your project directory first.
|
|
694
406
|
|
|
695
|
-
|
|
407
|
+
**Indexing is slow** — Check that `node_modules` and other large directories are excluded. Use `--quiet` to reduce output overhead.
|
|
696
408
|
|
|
697
|
-
|
|
698
|
-
- Use `--quiet` flag to reduce console output overhead
|
|
699
|
-
- Consider increasing `maxFileSize` if you have large files to skip
|
|
409
|
+
**MCP server not connecting** — Ensure the project is initialized/indexed, verify the path in your MCP config, and check that `codegraph serve --mcp` works from the command line.
|
|
700
410
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
1. Ensure the project is initialized and indexed
|
|
704
|
-
2. Check the path in your MCP configuration is correct
|
|
705
|
-
3. Verify `codegraph serve --mcp` works from the command line
|
|
706
|
-
4. Check Claude Code logs for connection errors
|
|
707
|
-
|
|
708
|
-
### Missing symbols in search
|
|
709
|
-
|
|
710
|
-
- Run `codegraph sync` to pick up recent changes
|
|
711
|
-
- Check if the file's language is supported
|
|
712
|
-
- Verify the file isn't excluded by config patterns
|
|
713
|
-
|
|
714
|
-
## 📡 Telemetry
|
|
715
|
-
|
|
716
|
-
CodeGraph collects anonymous error reports via [Sentry](https://sentry.io) to help diagnose and fix bugs. This is **enabled by default** in production environments (disabled in development/test).
|
|
717
|
-
|
|
718
|
-
**What is collected:**
|
|
719
|
-
- Error type, message, and stack trace (includes local file paths in the trace)
|
|
720
|
-
- CodeGraph version and process name (CLI or MCP server)
|
|
721
|
-
|
|
722
|
-
**What is NOT collected:**
|
|
723
|
-
- Source code contents
|
|
724
|
-
- File contents or repository data
|
|
725
|
-
- Personal information or environment variables
|
|
726
|
-
|
|
727
|
-
**To opt out**, set the environment variable before running CodeGraph:
|
|
728
|
-
|
|
729
|
-
```bash
|
|
730
|
-
export CODEGRAPH_TELEMETRY=off
|
|
731
|
-
```
|
|
732
|
-
|
|
733
|
-
---
|
|
411
|
+
**Missing symbols** — The MCP server auto-syncs on save (wait a couple seconds). Run `codegraph sync` manually if needed. Check that the file's language is supported and isn't excluded by config patterns.
|
|
734
412
|
|
|
735
|
-
##
|
|
413
|
+
## License
|
|
736
414
|
|
|
737
415
|
MIT
|
|
738
416
|
|
|
@@ -740,7 +418,7 @@ MIT
|
|
|
740
418
|
|
|
741
419
|
<div align="center">
|
|
742
420
|
|
|
743
|
-
**Made for the Claude Code community**
|
|
421
|
+
**Made for the Claude Code community**
|
|
744
422
|
|
|
745
423
|
[Report Bug](https://github.com/colbymchenry/codegraph/issues) · [Request Feature](https://github.com/colbymchenry/codegraph/issues)
|
|
746
424
|
|