@colbymchenry/codegraph 0.6.8 → 0.7.3
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 +179 -476
- package/dist/bin/codegraph.d.ts +0 -5
- package/dist/bin/codegraph.d.ts.map +1 -1
- package/dist/bin/codegraph.js +217 -237
- 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/context/index.d.ts +3 -5
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +531 -52
- 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 -14
- package/dist/db/queries.js.map +1 -1
- package/dist/db/schema.sql +1 -16
- 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 -22
- 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 +56 -0
- package/dist/extraction/svelte-extractor.d.ts.map +1 -0
- package/dist/extraction/svelte-extractor.js +272 -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 -1855
- package/dist/extraction/tree-sitter.js.map +1 -1
- package/dist/graph/traversal.d.ts.map +1 -1
- package/dist/graph/traversal.js +27 -3
- 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 -114
- 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 +1 -10
- package/dist/installer/config-writer.d.ts.map +1 -1
- package/dist/installer/config-writer.js +0 -79
- 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 -116
- 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 -1
- 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 +432 -21
- package/dist/mcp/tools.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 -141
- 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 -0
- package/dist/types.d.ts.map +1 -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/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.
|
|
99
|
+
## Key Features
|
|
123
100
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
<tr>
|
|
133
|
-
<td width="33%" valign="top">
|
|
134
|
-
|
|
135
|
-
### 🌍 19+ Languages
|
|
136
|
-
TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Dart, Svelte, Liquid, Pascal/Delphi—all with the same API.
|
|
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,12 +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
|
-
- Add global instructions to `~/.claude/CLAUDE.md`
|
|
169
|
-
- Install Claude Code hooks for automatic index syncing
|
|
124
|
+
- Add global instructions to `~/.claude/CLAUDE.md`
|
|
170
125
|
- Optionally initialize your current project
|
|
171
126
|
|
|
172
127
|
### 2. Restart Claude Code
|
|
@@ -175,20 +130,16 @@ Restart Claude Code for the MCP server to load.
|
|
|
175
130
|
|
|
176
131
|
### 3. Initialize Projects
|
|
177
132
|
|
|
178
|
-
For each project you want to use CodeGraph with:
|
|
179
|
-
|
|
180
133
|
```bash
|
|
181
134
|
cd your-project
|
|
182
135
|
codegraph init -i
|
|
183
136
|
```
|
|
184
137
|
|
|
185
|
-
That's it! Claude Code will
|
|
138
|
+
That's it! Claude Code will use CodeGraph tools automatically when a `.codegraph/` directory exists.
|
|
186
139
|
|
|
187
140
|
<details>
|
|
188
141
|
<summary><strong>Manual Setup (Alternative)</strong></summary>
|
|
189
142
|
|
|
190
|
-
If you prefer manual configuration:
|
|
191
|
-
|
|
192
143
|
**Install globally:**
|
|
193
144
|
```bash
|
|
194
145
|
npm install -g @colbymchenry/codegraph
|
|
@@ -230,7 +181,7 @@ npm install -g @colbymchenry/codegraph
|
|
|
230
181
|
<details>
|
|
231
182
|
<summary><strong>Global Instructions Reference</strong></summary>
|
|
232
183
|
|
|
233
|
-
The installer automatically adds these instructions to `~/.claude/CLAUDE.md
|
|
184
|
+
The installer automatically adds these instructions to `~/.claude/CLAUDE.md`:
|
|
234
185
|
|
|
235
186
|
```markdown
|
|
236
187
|
## CodeGraph
|
|
@@ -239,26 +190,25 @@ CodeGraph builds a semantic knowledge graph of codebases for faster, smarter cod
|
|
|
239
190
|
|
|
240
191
|
### If `.codegraph/` exists in the project
|
|
241
192
|
|
|
242
|
-
**
|
|
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?").
|
|
243
194
|
|
|
244
|
-
|
|
245
|
-
|------|---------|
|
|
246
|
-
| `codegraph_search` | Find symbols by name (functions, classes, types) |
|
|
247
|
-
| `codegraph_context` | Get relevant code context for a task |
|
|
248
|
-
| `codegraph_callers` | Find what calls a function |
|
|
249
|
-
| `codegraph_callees` | Find what a function calls |
|
|
250
|
-
| `codegraph_impact` | See what's affected by changing a symbol |
|
|
251
|
-
| `codegraph_node` | Get details + source code for a symbol |
|
|
252
|
-
| `codegraph_files` | Get project file structure from the index |
|
|
195
|
+
**When spawning Explore agents**, include this instruction in the prompt:
|
|
253
196
|
|
|
254
|
-
|
|
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.
|
|
255
203
|
|
|
256
|
-
|
|
204
|
+
**The main session may only use these lightweight tools directly** (for targeted lookups before making edits, not for exploration):
|
|
257
205
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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 |
|
|
262
212
|
|
|
263
213
|
### If `.codegraph/` does NOT exist
|
|
264
214
|
|
|
@@ -271,377 +221,147 @@ At the start of a session, ask the user if they'd like to initialize CodeGraph:
|
|
|
271
221
|
|
|
272
222
|
---
|
|
273
223
|
|
|
274
|
-
##
|
|
275
|
-
|
|
276
|
-
- Node.js >= 18.0.0
|
|
277
|
-
|
|
278
|
-
---
|
|
279
|
-
|
|
280
|
-
## 💻 CLI Usage
|
|
224
|
+
## How It Works
|
|
281
225
|
|
|
282
|
-
```bash
|
|
283
|
-
codegraph # Run interactive installer
|
|
284
|
-
codegraph install # Run interactive installer (explicit)
|
|
285
|
-
codegraph init [path] # Initialize in a project
|
|
286
|
-
codegraph uninit [path] # Remove CodeGraph from a project
|
|
287
|
-
codegraph index [path] # Full index
|
|
288
|
-
codegraph sync [path] # Incremental update
|
|
289
|
-
codegraph status [path] # Show statistics
|
|
290
|
-
codegraph query <search> # Search symbols
|
|
291
|
-
codegraph files [path] # Show project file structure
|
|
292
|
-
codegraph context <task> # Build context for AI
|
|
293
|
-
codegraph affected [files] # Find test files affected by changes
|
|
294
|
-
codegraph serve --mcp # Start MCP server
|
|
295
226
|
```
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
codegraph init --index # Initialize and immediately index
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### `codegraph uninit [path]`
|
|
329
|
-
|
|
330
|
-
Remove CodeGraph from a project. Deletes the `.codegraph/` directory and all indexed data.
|
|
331
|
-
|
|
332
|
-
```bash
|
|
333
|
-
codegraph uninit # Remove from current directory
|
|
334
|
-
codegraph uninit --force # Skip confirmation prompt
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
### `codegraph index [path]`
|
|
338
|
-
|
|
339
|
-
Index all files in the project. Extracts functions, classes, methods, and their relationships.
|
|
340
|
-
|
|
341
|
-
```bash
|
|
342
|
-
codegraph index # Index current directory
|
|
343
|
-
codegraph index --force # Force full re-index
|
|
344
|
-
codegraph index --quiet # Suppress progress output
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
### `codegraph sync [path]`
|
|
348
|
-
|
|
349
|
-
Incrementally sync changes since the last index. Only processes added, modified, or removed files.
|
|
350
|
-
|
|
351
|
-
```bash
|
|
352
|
-
codegraph sync # Sync current directory
|
|
353
|
-
codegraph sync --quiet # Suppress output
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### `codegraph status [path]`
|
|
357
|
-
|
|
358
|
-
Show index status and statistics.
|
|
359
|
-
|
|
360
|
-
```bash
|
|
361
|
-
codegraph status
|
|
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
|
+
└───────────────────────────────────────────────────────────────────┘
|
|
362
256
|
```
|
|
363
257
|
|
|
364
|
-
|
|
365
|
-
- Files indexed, nodes, edges
|
|
366
|
-
- Nodes by kind (functions, classes, methods, etc.)
|
|
367
|
-
- Files by language
|
|
368
|
-
- Pending changes (if any)
|
|
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).
|
|
369
259
|
|
|
370
|
-
|
|
260
|
+
2. **Storage** — Everything goes into a local SQLite database (`.codegraph/codegraph.db`) with FTS5 full-text search.
|
|
371
261
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
```bash
|
|
375
|
-
codegraph query "authenticate" # Search for symbols
|
|
376
|
-
codegraph query "User" --kind class # Filter by kind
|
|
377
|
-
codegraph query "process" --limit 20 # Limit results
|
|
378
|
-
codegraph query "validate" --json # Output as JSON
|
|
379
|
-
```
|
|
262
|
+
3. **Resolution** — After extraction, references are resolved: function calls → definitions, imports → source files, class inheritance, and framework-specific patterns.
|
|
380
263
|
|
|
381
|
-
|
|
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.
|
|
382
265
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
```bash
|
|
386
|
-
codegraph files # Show file tree
|
|
387
|
-
codegraph files --format flat # Simple list
|
|
388
|
-
codegraph files --format grouped # Group by language
|
|
389
|
-
codegraph files --filter src/components # Filter by directory
|
|
390
|
-
codegraph files --pattern "*.test.ts" # Filter by glob pattern
|
|
391
|
-
codegraph files --max-depth 2 # Limit tree depth
|
|
392
|
-
codegraph files --no-metadata # Hide language/symbol counts
|
|
393
|
-
codegraph files --json # Output as JSON
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
### `codegraph context <task>`
|
|
266
|
+
---
|
|
397
267
|
|
|
398
|
-
|
|
268
|
+
## CLI Reference
|
|
399
269
|
|
|
400
270
|
```bash
|
|
401
|
-
codegraph
|
|
402
|
-
codegraph
|
|
403
|
-
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
|
|
404
283
|
```
|
|
405
284
|
|
|
406
|
-
### `codegraph affected
|
|
285
|
+
### `codegraph affected`
|
|
407
286
|
|
|
408
|
-
|
|
287
|
+
Traces import dependencies transitively to find which test files are affected by changed source files.
|
|
409
288
|
|
|
410
289
|
```bash
|
|
411
290
|
codegraph affected src/utils.ts src/api.ts # Pass files as arguments
|
|
412
291
|
git diff --name-only | codegraph affected --stdin # Pipe from git diff
|
|
413
|
-
codegraph affected --stdin --json < changed.txt # JSON output
|
|
414
292
|
codegraph affected src/auth.ts --filter "e2e/*" # Custom test file pattern
|
|
415
|
-
codegraph affected src/lib.ts --depth 3 --quiet # Shallow search, paths only
|
|
416
293
|
```
|
|
417
294
|
|
|
418
|
-
**Options:**
|
|
419
|
-
|
|
420
295
|
| Option | Description | Default |
|
|
421
296
|
|--------|-------------|---------|
|
|
422
|
-
| `--stdin` | Read file list from stdin
|
|
297
|
+
| `--stdin` | Read file list from stdin | `false` |
|
|
423
298
|
| `-d, --depth <n>` | Max dependency traversal depth | `5` |
|
|
424
299
|
| `-f, --filter <glob>` | Custom glob to identify test files | auto-detect |
|
|
425
300
|
| `-j, --json` | Output as JSON | `false` |
|
|
426
|
-
| `-q, --quiet` | Output file paths only
|
|
427
|
-
| `-p, --path <path>` | Project path | auto-detect |
|
|
428
|
-
|
|
429
|
-
**How it works:**
|
|
301
|
+
| `-q, --quiet` | Output file paths only | `false` |
|
|
430
302
|
|
|
431
|
-
|
|
432
|
-
2. Filters results to test files using common conventions (`*.spec.*`, `*.test.*`, `e2e/`, `tests/`, `__tests__/`) or a custom `--filter` glob
|
|
433
|
-
3. Changed files that are themselves test files are always included
|
|
434
|
-
|
|
435
|
-
**Example: CI/hook integration**
|
|
303
|
+
**CI/hook example:**
|
|
436
304
|
|
|
437
305
|
```bash
|
|
438
306
|
#!/usr/bin/env bash
|
|
439
|
-
# In a pre-commit hook or CI step:
|
|
440
307
|
AFFECTED=$(git diff --name-only HEAD | codegraph affected --stdin --quiet)
|
|
441
308
|
if [ -n "$AFFECTED" ]; then
|
|
442
|
-
echo "Running affected tests..."
|
|
443
309
|
npx vitest run $AFFECTED
|
|
444
310
|
fi
|
|
445
311
|
```
|
|
446
312
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
Start CodeGraph as an MCP server for AI assistants.
|
|
450
|
-
|
|
451
|
-
```bash
|
|
452
|
-
codegraph serve # Show MCP configuration help
|
|
453
|
-
codegraph serve --mcp # Start MCP server (stdio)
|
|
454
|
-
codegraph serve --mcp --path /project # Specify project path
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
## 🔌 MCP Tools Reference
|
|
458
|
-
|
|
459
|
-
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.
|
|
460
|
-
|
|
461
|
-
### `codegraph_context`
|
|
462
|
-
|
|
463
|
-
Build context for a specific task. Good for focused queries.
|
|
464
|
-
|
|
465
|
-
```
|
|
466
|
-
codegraph_context(task: "fix checkout validation bug", maxNodes: 20)
|
|
467
|
-
```
|
|
468
|
-
|
|
469
|
-
### `codegraph_search`
|
|
470
|
-
|
|
471
|
-
Quick symbol search by name. Returns locations only.
|
|
472
|
-
|
|
473
|
-
```
|
|
474
|
-
codegraph_search(query: "UserService", kind: "class", limit: 10)
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
### `codegraph_callers` / `codegraph_callees`
|
|
478
|
-
|
|
479
|
-
Find what calls a function, or what a function calls.
|
|
480
|
-
|
|
481
|
-
```
|
|
482
|
-
codegraph_callers(symbol: "validatePayment", limit: 20)
|
|
483
|
-
codegraph_callees(symbol: "processOrder", limit: 20)
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
### `codegraph_impact`
|
|
487
|
-
|
|
488
|
-
Analyze what code would be affected by changing a symbol.
|
|
489
|
-
|
|
490
|
-
```
|
|
491
|
-
codegraph_impact(symbol: "UserService", depth: 2)
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
### `codegraph_node`
|
|
495
|
-
|
|
496
|
-
Get details about a specific symbol. Use `includeCode: true` only when needed.
|
|
497
|
-
|
|
498
|
-
```
|
|
499
|
-
codegraph_node(symbol: "authenticate", includeCode: true)
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
### `codegraph_files`
|
|
503
|
-
|
|
504
|
-
Get the project file structure from the index. Faster than filesystem scanning.
|
|
505
|
-
|
|
506
|
-
```
|
|
507
|
-
codegraph_files(path: "src/components", format: "tree", includeMetadata: true)
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
### `codegraph_status`
|
|
511
|
-
|
|
512
|
-
Check index health and statistics.
|
|
513
|
-
|
|
514
|
-
### How It Works With Claude Code
|
|
313
|
+
---
|
|
515
314
|
|
|
516
|
-
|
|
315
|
+
## MCP Tools
|
|
517
316
|
|
|
518
|
-
|
|
519
|
-
|-------------------|----------------|---------|
|
|
520
|
-
| `grep -r "auth"` | `codegraph_search("auth")` | Instant symbol lookup |
|
|
521
|
-
| Multiple `Read` calls | `codegraph_context(task)` | Related code in one call |
|
|
522
|
-
| Manual file tracing | `codegraph_callers/callees` | Call graph traversal |
|
|
523
|
-
| Guessing impact | `codegraph_impact(symbol)` | Know what breaks |
|
|
524
|
-
| `Glob`/`find` scanning | `codegraph_files(path)` | Indexed file structure |
|
|
317
|
+
When running as an MCP server, CodeGraph exposes these tools to Claude Code:
|
|
525
318
|
|
|
526
|
-
|
|
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 |
|
|
527
329
|
|
|
528
|
-
|
|
330
|
+
---
|
|
529
331
|
|
|
530
|
-
|
|
332
|
+
## Library Usage
|
|
531
333
|
|
|
532
334
|
```typescript
|
|
533
335
|
import CodeGraph from '@colbymchenry/codegraph';
|
|
534
336
|
|
|
535
|
-
// Initialize a new project
|
|
536
337
|
const cg = await CodeGraph.init('/path/to/project');
|
|
338
|
+
// Or: const cg = await CodeGraph.open('/path/to/project');
|
|
537
339
|
|
|
538
|
-
// Or open an existing one
|
|
539
|
-
const cg = await CodeGraph.open('/path/to/project');
|
|
540
|
-
|
|
541
|
-
// Index with progress callback
|
|
542
340
|
await cg.indexAll({
|
|
543
|
-
onProgress: (
|
|
544
|
-
console.log(`${progress.phase}: ${progress.current}/${progress.total}`);
|
|
545
|
-
}
|
|
341
|
+
onProgress: (p) => console.log(`${p.phase}: ${p.current}/${p.total}`)
|
|
546
342
|
});
|
|
547
343
|
|
|
548
|
-
// Search for symbols
|
|
549
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);
|
|
550
348
|
|
|
551
|
-
//
|
|
552
|
-
|
|
553
|
-
const callers = cg.getCallers(node.id);
|
|
554
|
-
|
|
555
|
-
// Build context for a task
|
|
556
|
-
const context = await cg.buildContext('fix login bug', {
|
|
557
|
-
maxNodes: 20,
|
|
558
|
-
includeCode: true,
|
|
559
|
-
format: 'markdown'
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
// Get impact radius
|
|
563
|
-
const impact = cg.getImpactRadius(node.id, 2);
|
|
564
|
-
|
|
565
|
-
// Sync changes
|
|
566
|
-
const syncResult = await cg.sync();
|
|
567
|
-
|
|
568
|
-
// Clean up
|
|
349
|
+
cg.watch(); // auto-sync on file changes
|
|
350
|
+
cg.unwatch(); // stop watching
|
|
569
351
|
cg.close();
|
|
570
352
|
```
|
|
571
353
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
### 1. Extraction
|
|
575
|
-
|
|
576
|
-
CodeGraph uses [tree-sitter](https://tree-sitter.github.io/) to parse source code into ASTs. Language-specific queries (`.scm` files) extract:
|
|
577
|
-
|
|
578
|
-
- **Nodes**: Functions, methods, classes, interfaces, types, variables
|
|
579
|
-
- **Edges**: Calls, imports, extends, implements, returns_type
|
|
580
|
-
|
|
581
|
-
Each node gets a unique ID based on its kind, file path, name, and line number.
|
|
582
|
-
|
|
583
|
-
### 2. Storage
|
|
584
|
-
|
|
585
|
-
All data is stored in a local SQLite database (`.codegraph/codegraph.db`):
|
|
586
|
-
|
|
587
|
-
- **nodes** table: All code entities with metadata
|
|
588
|
-
- **edges** table: Relationships between nodes
|
|
589
|
-
- **files** table: File tracking for incremental updates
|
|
590
|
-
- **unresolved_refs** table: References pending resolution
|
|
591
|
-
- **vectors** table: Embeddings stored as BLOBs for semantic search
|
|
592
|
-
- **nodes_fts**: FTS5 virtual table for full-text search
|
|
593
|
-
- **schema_versions** table: Schema version tracking
|
|
594
|
-
- **project_metadata** table: Project-level key-value metadata
|
|
595
|
-
|
|
596
|
-
### 3. Reference Resolution
|
|
597
|
-
|
|
598
|
-
After extraction, CodeGraph resolves references:
|
|
599
|
-
|
|
600
|
-
1. Match function calls to function definitions
|
|
601
|
-
2. Resolve imports to their source files
|
|
602
|
-
3. Link class inheritance and interface implementations
|
|
603
|
-
4. Apply framework-specific patterns (Express routes, etc.)
|
|
604
|
-
|
|
605
|
-
### 4. Semantic Search
|
|
606
|
-
|
|
607
|
-
CodeGraph uses local embeddings (via [@xenova/transformers](https://github.com/xenova/transformers.js)) to enable semantic search:
|
|
608
|
-
|
|
609
|
-
1. Code symbols are embedded using a transformer model
|
|
610
|
-
2. Queries are embedded and compared using cosine similarity
|
|
611
|
-
3. Results are ranked by relevance
|
|
612
|
-
|
|
613
|
-
### 5. Graph Queries
|
|
614
|
-
|
|
615
|
-
The graph structure enables powerful queries:
|
|
616
|
-
|
|
617
|
-
- **Callers/Callees**: Direct call relationships
|
|
618
|
-
- **Impact Radius**: BFS traversal to find all potentially affected code
|
|
619
|
-
- **Dependencies**: What a symbol depends on
|
|
620
|
-
- **Dependents**: What depends on a symbol
|
|
621
|
-
|
|
622
|
-
### 6. Context Building
|
|
623
|
-
|
|
624
|
-
When you request context for a task:
|
|
625
|
-
|
|
626
|
-
1. Semantic search finds relevant entry points
|
|
627
|
-
2. Graph traversal expands to related code
|
|
628
|
-
3. Code snippets are extracted
|
|
629
|
-
4. Results are formatted for AI consumption
|
|
354
|
+
---
|
|
630
355
|
|
|
631
|
-
##
|
|
356
|
+
## Configuration
|
|
632
357
|
|
|
633
|
-
The `.codegraph/config.json` file controls indexing
|
|
358
|
+
The `.codegraph/config.json` file controls indexing:
|
|
634
359
|
|
|
635
360
|
```json
|
|
636
361
|
{
|
|
637
362
|
"version": 1,
|
|
638
363
|
"languages": ["typescript", "javascript"],
|
|
639
|
-
"exclude": [
|
|
640
|
-
"node_modules/**",
|
|
641
|
-
"dist/**",
|
|
642
|
-
"build/**",
|
|
643
|
-
"*.min.js"
|
|
644
|
-
],
|
|
364
|
+
"exclude": ["node_modules/**", "dist/**", "build/**", "*.min.js"],
|
|
645
365
|
"frameworks": [],
|
|
646
366
|
"maxFileSize": 1048576,
|
|
647
367
|
"extractDocstrings": true,
|
|
@@ -649,18 +369,16 @@ The `.codegraph/config.json` file controls indexing behavior:
|
|
|
649
369
|
}
|
|
650
370
|
```
|
|
651
371
|
|
|
652
|
-
### Options
|
|
653
|
-
|
|
654
372
|
| Option | Description | Default |
|
|
655
373
|
|--------|-------------|---------|
|
|
656
374
|
| `languages` | Languages to index (auto-detected if empty) | `[]` |
|
|
657
375
|
| `exclude` | Glob patterns to ignore | `["node_modules/**", ...]` |
|
|
658
376
|
| `frameworks` | Framework hints for better resolution | `[]` |
|
|
659
377
|
| `maxFileSize` | Skip files larger than this (bytes) | `1048576` (1MB) |
|
|
660
|
-
| `extractDocstrings` |
|
|
661
|
-
| `trackCallSites` |
|
|
378
|
+
| `extractDocstrings` | Extract docstrings from code | `true` |
|
|
379
|
+
| `trackCallSites` | Track call site locations | `true` |
|
|
662
380
|
|
|
663
|
-
##
|
|
381
|
+
## Supported Languages
|
|
664
382
|
|
|
665
383
|
| Language | Extension | Status |
|
|
666
384
|
|----------|-----------|--------|
|
|
@@ -675,39 +393,24 @@ The `.codegraph/config.json` file controls indexing behavior:
|
|
|
675
393
|
| Ruby | `.rb` | Full support |
|
|
676
394
|
| C | `.c`, `.h` | Full support |
|
|
677
395
|
| C++ | `.cpp`, `.hpp`, `.cc` | Full support |
|
|
678
|
-
| Swift | `.swift` |
|
|
679
|
-
| Kotlin | `.kt`, `.kts` |
|
|
396
|
+
| Swift | `.swift` | Full support |
|
|
397
|
+
| Kotlin | `.kt`, `.kts` | Full support |
|
|
680
398
|
| Dart | `.dart` | Full support |
|
|
681
399
|
| Svelte | `.svelte` | Full support (script extraction, Svelte 5 runes, SvelteKit routes) |
|
|
682
400
|
| Liquid | `.liquid` | Full support |
|
|
683
401
|
| Pascal / Delphi | `.pas`, `.dpr`, `.dpk`, `.lpr` | Full support (classes, records, interfaces, enums, DFM/FMX form files) |
|
|
684
402
|
|
|
685
|
-
##
|
|
686
|
-
|
|
687
|
-
### "CodeGraph not initialized"
|
|
688
|
-
|
|
689
|
-
Run `codegraph init` in your project directory first.
|
|
690
|
-
|
|
691
|
-
### Indexing is slow
|
|
692
|
-
|
|
693
|
-
- Check if `node_modules` or other large directories are excluded
|
|
694
|
-
- Use `--quiet` flag to reduce console output overhead
|
|
695
|
-
- Consider increasing `maxFileSize` if you have large files to skip
|
|
403
|
+
## Troubleshooting
|
|
696
404
|
|
|
697
|
-
|
|
405
|
+
**"CodeGraph not initialized"** — Run `codegraph init` in your project directory first.
|
|
698
406
|
|
|
699
|
-
|
|
700
|
-
2. Check the path in your MCP configuration is correct
|
|
701
|
-
3. Verify `codegraph serve --mcp` works from the command line
|
|
702
|
-
4. Check Claude Code logs for connection errors
|
|
407
|
+
**Indexing is slow** — Check that `node_modules` and other large directories are excluded. Use `--quiet` to reduce output overhead.
|
|
703
408
|
|
|
704
|
-
|
|
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.
|
|
705
410
|
|
|
706
|
-
- Run `codegraph sync`
|
|
707
|
-
- Check if the file's language is supported
|
|
708
|
-
- Verify the file isn't excluded by config patterns
|
|
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.
|
|
709
412
|
|
|
710
|
-
##
|
|
413
|
+
## License
|
|
711
414
|
|
|
712
415
|
MIT
|
|
713
416
|
|
|
@@ -715,7 +418,7 @@ MIT
|
|
|
715
418
|
|
|
716
419
|
<div align="center">
|
|
717
420
|
|
|
718
|
-
**Made for the Claude Code community**
|
|
421
|
+
**Made for the Claude Code community**
|
|
719
422
|
|
|
720
423
|
[Report Bug](https://github.com/colbymchenry/codegraph/issues) · [Request Feature](https://github.com/colbymchenry/codegraph/issues)
|
|
721
424
|
|