@colbymchenry/codegraph 0.5.5 โ†’ 0.6.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.
Files changed (54) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +682 -681
  3. package/dist/bin/codegraph.js +14 -14
  4. package/dist/bin/codegraph.js.map +1 -1
  5. package/dist/bin/uninstall.d.ts +15 -0
  6. package/dist/bin/uninstall.d.ts.map +1 -0
  7. package/dist/bin/uninstall.js +174 -0
  8. package/dist/bin/uninstall.js.map +1 -0
  9. package/dist/db/migrations.js +11 -11
  10. package/dist/db/queries.js +86 -86
  11. package/dist/db/schema.sql +163 -163
  12. package/dist/directory.d.ts.map +1 -1
  13. package/dist/directory.js +25 -18
  14. package/dist/directory.js.map +1 -1
  15. package/dist/extraction/grammars.d.ts.map +1 -1
  16. package/dist/extraction/grammars.js +50 -4
  17. package/dist/extraction/grammars.js.map +1 -1
  18. package/dist/extraction/tree-sitter.d.ts +64 -0
  19. package/dist/extraction/tree-sitter.d.ts.map +1 -1
  20. package/dist/extraction/tree-sitter.js +586 -1
  21. package/dist/extraction/tree-sitter.js.map +1 -1
  22. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  23. package/dist/installer/banner.d.ts +1 -1
  24. package/dist/installer/banner.d.ts.map +1 -1
  25. package/dist/installer/banner.js +12 -10
  26. package/dist/installer/banner.js.map +1 -1
  27. package/dist/installer/claude-md-template.js +32 -32
  28. package/dist/installer/config-writer.d.ts +0 -1
  29. package/dist/installer/config-writer.d.ts.map +1 -1
  30. package/dist/installer/config-writer.js +8 -26
  31. package/dist/installer/config-writer.js.map +1 -1
  32. package/dist/installer/index.d.ts.map +1 -1
  33. package/dist/installer/index.js +11 -26
  34. package/dist/installer/index.js.map +1 -1
  35. package/dist/resolution/import-resolver.d.ts +4 -0
  36. package/dist/resolution/import-resolver.d.ts.map +1 -1
  37. package/dist/resolution/import-resolver.js +9 -0
  38. package/dist/resolution/import-resolver.js.map +1 -1
  39. package/dist/resolution/index.d.ts +1 -1
  40. package/dist/resolution/index.d.ts.map +1 -1
  41. package/dist/resolution/index.js +39 -4
  42. package/dist/resolution/index.js.map +1 -1
  43. package/dist/sync/git-hooks.d.ts +66 -0
  44. package/dist/sync/git-hooks.d.ts.map +1 -0
  45. package/dist/sync/git-hooks.js +281 -0
  46. package/dist/sync/git-hooks.js.map +1 -0
  47. package/dist/types.d.ts +1 -1
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/types.js +11 -0
  50. package/dist/types.js.map +1 -1
  51. package/dist/vectors/search.js +33 -33
  52. package/package.json +60 -59
  53. package/scripts/patch-tree-sitter-dart.js +112 -112
  54. package/scripts/postinstall.js +68 -68
package/README.md CHANGED
@@ -1,681 +1,682 @@
1
- <div align="center">
2
-
3
- # ๐Ÿ”ฎ CodeGraph
4
-
5
- ### Supercharge Claude Code with Semantic Code Intelligence
6
-
7
- **30% fewer tokens โ€ข 25% fewer tool calls โ€ข 100% local**
8
-
9
- [![npm version](https://img.shields.io/npm/v/@colbymchenry/codegraph.svg)](https://www.npmjs.com/package/@colbymchenry/codegraph)
10
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
- [![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
12
-
13
- [![Windows](https://img.shields.io/badge/Windows-supported-blue.svg)](#)
14
- [![macOS](https://img.shields.io/badge/macOS-supported-blue.svg)](#)
15
- [![Linux](https://img.shields.io/badge/Linux-supported-blue.svg)](#)
16
-
17
- <br />
18
-
19
- ### Get Started
20
-
21
- ```bash
22
- npx @colbymchenry/codegraph
23
- ```
24
-
25
- <sub>Interactive installer configures Claude Code automatically</sub>
26
-
27
- </div>
28
-
29
- ---
30
-
31
- ## ๐Ÿš€ Why CodeGraph?
32
-
33
- When you ask Claude Code to work on a complex task, it spawns **Explore agents** that scan your codebase using grep, glob, and file reads. These agents consume tokens with every tool call.
34
-
35
- **CodeGraph gives those agents a semantic knowledge graph** โ€” pre-indexed symbol relationships, call graphs, and code structure. Instead of scanning files, agents query the graph instantly.
36
-
37
- ### ๐Ÿ“Š Benchmark Results
38
-
39
- We ran the same complex task 3 times with and without CodeGraph:
40
-
41
- | Metric | Without CodeGraph | With CodeGraph | Improvement |
42
- |--------|-------------------|----------------|-------------|
43
- | **Explore tokens** | 157.8k | 111.7k | **29% fewer** |
44
- | **Per-agent tokens** | 74.0k | 46.4k | **37% fewer** |
45
- | **Tool calls** | 60 | 45 | **25% fewer** |
46
- | **Main context usage** | 28.7% | 24.0% | **4.7% less** |
47
-
48
- <details>
49
- <summary><strong>Full benchmark data</strong></summary>
50
-
51
- **With CodeGraph:**
52
- | Test | Agents | Tool Uses | Explore Tokens | Plan Tokens | Time |
53
- |------|--------|-----------|----------------|-------------|------|
54
- | 1 | 3 | 54 | 149.7k | 76.4k | 1m 43s |
55
- | 2 | 2 | 41 | 102.1k | 74.8k | 1m 29s |
56
- | 3 | 2 | 40 | 83.3k | 63.3k | 1m 25s |
57
- | **Avg** | **2.3** | **45** | **111.7k** | **71.5k** | **1m 32s** |
58
-
59
- **Without CodeGraph:**
60
- | Test | Agents | Tool Uses | Explore Tokens | Plan Tokens | Time |
61
- |------|--------|-----------|----------------|-------------|------|
62
- | 1 | 3 | 74 | 177.3k | 80.5k | 1m 54s |
63
- | 2 | 2 | 55 | 149.3k | 64.0k | 1m 27s |
64
- | 3 | 2 | 51 | 146.7k | 62.3k | 1m 17s |
65
- | **Avg** | **2.3** | **60** | **157.8k** | **68.9k** | **1m 33s** |
66
-
67
- </details>
68
-
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
- ---
108
-
109
- ## โœจ Key Features
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.
129
-
130
- </td>
131
- </tr>
132
- <tr>
133
- <td width="33%" valign="top">
134
-
135
- ### ๐ŸŒ 17+ Languages
136
- TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Dart, Svelte, Liquidโ€”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>
153
-
154
- ---
155
-
156
- ## ๐ŸŽฏ Quick Start
157
-
158
- ### 1. Run the Installer
159
-
160
- ```bash
161
- npx @colbymchenry/codegraph
162
- ```
163
-
164
- The interactive installer will:
165
- - Configure the MCP server in `~/.claude.json`
166
- - Set up auto-allow permissions for CodeGraph tools
167
- - Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
168
- - Install Claude Code hooks for automatic index syncing
169
- - Optionally initialize your current project
170
-
171
- ### 2. Restart Claude Code
172
-
173
- Restart Claude Code for the MCP server to load.
174
-
175
- ### 3. Initialize Projects
176
-
177
- For each project you want to use CodeGraph with:
178
-
179
- ```bash
180
- cd your-project
181
- codegraph init -i
182
- ```
183
-
184
- That's it! Claude Code will now use CodeGraph tools automatically when a `.codegraph/` directory exists.
185
-
186
- <details>
187
- <summary><strong>Manual Setup (Alternative)</strong></summary>
188
-
189
- If you prefer manual configuration:
190
-
191
- **Install globally:**
192
- ```bash
193
- npm install -g @colbymchenry/codegraph
194
- ```
195
-
196
- **Add to `~/.claude.json`:**
197
- ```json
198
- {
199
- "mcpServers": {
200
- "codegraph": {
201
- "type": "stdio",
202
- "command": "codegraph",
203
- "args": ["serve", "--mcp"]
204
- }
205
- }
206
- }
207
- ```
208
-
209
- **Add to `~/.claude/settings.json` (optional, for auto-allow):**
210
- ```json
211
- {
212
- "permissions": {
213
- "allow": [
214
- "mcp__codegraph__codegraph_search",
215
- "mcp__codegraph__codegraph_context",
216
- "mcp__codegraph__codegraph_callers",
217
- "mcp__codegraph__codegraph_callees",
218
- "mcp__codegraph__codegraph_impact",
219
- "mcp__codegraph__codegraph_node",
220
- "mcp__codegraph__codegraph_status",
221
- "mcp__codegraph__codegraph_files"
222
- ]
223
- }
224
- }
225
- ```
226
-
227
- </details>
228
-
229
- <details>
230
- <summary><strong>Global Instructions Reference</strong></summary>
231
-
232
- The installer automatically adds these instructions to `~/.claude/CLAUDE.md`. This is provided here for reference:
233
-
234
- ```markdown
235
- ## CodeGraph
236
-
237
- CodeGraph builds a semantic knowledge graph of codebases for faster, smarter code exploration.
238
-
239
- ### If `.codegraph/` exists in the project
240
-
241
- **Use codegraph tools for faster exploration.** These tools provide instant lookups via the code graph instead of scanning files:
242
-
243
- | Tool | Use For |
244
- |------|---------|
245
- | `codegraph_search` | Find symbols by name (functions, classes, types) |
246
- | `codegraph_context` | Get relevant code context for a task |
247
- | `codegraph_callers` | Find what calls a function |
248
- | `codegraph_callees` | Find what a function calls |
249
- | `codegraph_impact` | See what's affected by changing a symbol |
250
- | `codegraph_node` | Get details + source code for a symbol |
251
- | `codegraph_files` | Get project file structure from the index |
252
-
253
- **When spawning Explore agents in a codegraph-enabled project:**
254
-
255
- Tell the Explore agent to use codegraph tools for faster exploration.
256
-
257
- **For quick lookups in the main session:**
258
- - Use `codegraph_search` instead of grep for finding symbols
259
- - Use `codegraph_callers`/`codegraph_callees` to trace code flow
260
- - Use `codegraph_impact` before making changes to see what's affected
261
-
262
- ### If `.codegraph/` does NOT exist
263
-
264
- At the start of a session, ask the user if they'd like to initialize CodeGraph:
265
-
266
- "I notice this project doesn't have CodeGraph initialized. Would you like me to run `codegraph init -i` to build a code knowledge graph?"
267
- ```
268
-
269
- </details>
270
-
271
- ---
272
-
273
- ## ๐Ÿ“‹ Requirements
274
-
275
- - Node.js >= 18.0.0
276
-
277
- ---
278
-
279
- ## ๐Ÿ’ป CLI Usage
280
-
281
- ```bash
282
- codegraph # Run interactive installer
283
- codegraph install # Run interactive installer (explicit)
284
- codegraph init [path] # Initialize in a project
285
- codegraph uninit [path] # Remove CodeGraph from a project
286
- codegraph index [path] # Full index
287
- codegraph sync [path] # Incremental update
288
- codegraph status [path] # Show statistics
289
- codegraph query <search> # Search symbols
290
- codegraph files [path] # Show project file structure
291
- codegraph context <task> # Build context for AI
292
- codegraph serve --mcp # Start MCP server
293
- ```
294
-
295
- ## ๐Ÿ“– CLI Commands
296
-
297
- ### `codegraph` / `codegraph install`
298
-
299
- Run the interactive installer for Claude Code integration. Configures MCP server and permissions automatically.
300
-
301
- ```bash
302
- codegraph # Run installer (when no args)
303
- codegraph install # Run installer (explicit)
304
- npx @colbymchenry/codegraph # Run via npx (no global install needed)
305
- ```
306
-
307
- The installer will:
308
- 1. Ask for installation location (global `~/.claude` or local `./.claude`)
309
- 2. Configure the MCP server in `claude.json`
310
- 3. Optionally set up auto-allow permissions
311
- 4. Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
312
- 5. Install Claude Code hooks for automatic index syncing
313
- 6. For local installs: initialize and index the current project
314
-
315
- ### `codegraph init [path]`
316
-
317
- Initialize CodeGraph in a project directory. Creates a `.codegraph/` directory with the database and configuration.
318
-
319
- ```bash
320
- codegraph init # Initialize in current directory
321
- codegraph init /path/to/project # Initialize in specific directory
322
- codegraph init --index # Initialize and immediately index
323
- ```
324
-
325
- ### `codegraph uninit [path]`
326
-
327
- Remove CodeGraph from a project. Deletes the `.codegraph/` directory and all indexed data.
328
-
329
- ```bash
330
- codegraph uninit # Remove from current directory
331
- codegraph uninit --force # Skip confirmation prompt
332
- ```
333
-
334
- ### `codegraph index [path]`
335
-
336
- Index all files in the project. Extracts functions, classes, methods, and their relationships.
337
-
338
- ```bash
339
- codegraph index # Index current directory
340
- codegraph index --force # Force full re-index
341
- codegraph index --quiet # Suppress progress output
342
- ```
343
-
344
- ### `codegraph sync [path]`
345
-
346
- Incrementally sync changes since the last index. Only processes added, modified, or removed files.
347
-
348
- ```bash
349
- codegraph sync # Sync current directory
350
- codegraph sync --quiet # Suppress output
351
- ```
352
-
353
- ### `codegraph status [path]`
354
-
355
- Show index status and statistics.
356
-
357
- ```bash
358
- codegraph status
359
- ```
360
-
361
- Output includes:
362
- - Files indexed, nodes, edges
363
- - Nodes by kind (functions, classes, methods, etc.)
364
- - Files by language
365
- - Pending changes (if any)
366
-
367
- ### `codegraph query <search>`
368
-
369
- Search for symbols in the codebase by name.
370
-
371
- ```bash
372
- codegraph query "authenticate" # Search for symbols
373
- codegraph query "User" --kind class # Filter by kind
374
- codegraph query "process" --limit 20 # Limit results
375
- codegraph query "validate" --json # Output as JSON
376
- ```
377
-
378
- ### `codegraph files [path]`
379
-
380
- Show the project file structure from the index. Faster than filesystem scanning since it reads from the indexed data.
381
-
382
- ```bash
383
- codegraph files # Show file tree
384
- codegraph files --format flat # Simple list
385
- codegraph files --format grouped # Group by language
386
- codegraph files --filter src/components # Filter by directory
387
- codegraph files --pattern "*.test.ts" # Filter by glob pattern
388
- codegraph files --max-depth 2 # Limit tree depth
389
- codegraph files --no-metadata # Hide language/symbol counts
390
- codegraph files --json # Output as JSON
391
- ```
392
-
393
- ### `codegraph context <task>`
394
-
395
- Build relevant code context for a task. Uses semantic search to find entry points, then expands through the graph to find related code.
396
-
397
- ```bash
398
- codegraph context "fix checkout bug"
399
- codegraph context "add user authentication" --format json
400
- codegraph context "refactor payment service" --max-nodes 30
401
- ```
402
-
403
- ### `codegraph serve`
404
-
405
- Start CodeGraph as an MCP server for AI assistants.
406
-
407
- ```bash
408
- codegraph serve # Show MCP configuration help
409
- codegraph serve --mcp # Start MCP server (stdio)
410
- codegraph serve --mcp --path /project # Specify project path
411
- ```
412
-
413
- ## ๐Ÿ”Œ MCP Tools Reference
414
-
415
- 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.
416
-
417
- ### `codegraph_context`
418
-
419
- Build context for a specific task. Good for focused queries.
420
-
421
- ```
422
- codegraph_context(task: "fix checkout validation bug", maxNodes: 20)
423
- ```
424
-
425
- ### `codegraph_search`
426
-
427
- Quick symbol search by name. Returns locations only.
428
-
429
- ```
430
- codegraph_search(query: "UserService", kind: "class", limit: 10)
431
- ```
432
-
433
- ### `codegraph_callers` / `codegraph_callees`
434
-
435
- Find what calls a function, or what a function calls.
436
-
437
- ```
438
- codegraph_callers(symbol: "validatePayment", limit: 20)
439
- codegraph_callees(symbol: "processOrder", limit: 20)
440
- ```
441
-
442
- ### `codegraph_impact`
443
-
444
- Analyze what code would be affected by changing a symbol.
445
-
446
- ```
447
- codegraph_impact(symbol: "UserService", depth: 2)
448
- ```
449
-
450
- ### `codegraph_node`
451
-
452
- Get details about a specific symbol. Use `includeCode: true` only when needed.
453
-
454
- ```
455
- codegraph_node(symbol: "authenticate", includeCode: true)
456
- ```
457
-
458
- ### `codegraph_files`
459
-
460
- Get the project file structure from the index. Faster than filesystem scanning.
461
-
462
- ```
463
- codegraph_files(path: "src/components", format: "tree", includeMetadata: true)
464
- ```
465
-
466
- ### `codegraph_status`
467
-
468
- Check index health and statistics.
469
-
470
- ### How It Works With Claude Code
471
-
472
- Claude's **Explore agents** use these tools instead of grep/glob/Read for faster exploration:
473
-
474
- | Without CodeGraph | With CodeGraph | Benefit |
475
- |-------------------|----------------|---------|
476
- | `grep -r "auth"` | `codegraph_search("auth")` | Instant symbol lookup |
477
- | Multiple `Read` calls | `codegraph_context(task)` | Related code in one call |
478
- | Manual file tracing | `codegraph_callers/callees` | Call graph traversal |
479
- | Guessing impact | `codegraph_impact(symbol)` | Know what breaks |
480
- | `Glob`/`find` scanning | `codegraph_files(path)` | Indexed file structure |
481
-
482
- This hybrid approach gives you **~30% fewer tokens** and **~25% fewer tool calls** while letting Claude's native agents handle synthesis.
483
-
484
- ## ๐Ÿ“š Library Usage
485
-
486
- CodeGraph can also be used as a library in your Node.js applications:
487
-
488
- ```typescript
489
- import CodeGraph from '@colbymchenry/codegraph';
490
-
491
- // Initialize a new project
492
- const cg = await CodeGraph.init('/path/to/project');
493
-
494
- // Or open an existing one
495
- const cg = await CodeGraph.open('/path/to/project');
496
-
497
- // Index with progress callback
498
- await cg.indexAll({
499
- onProgress: (progress) => {
500
- console.log(`${progress.phase}: ${progress.current}/${progress.total}`);
501
- }
502
- });
503
-
504
- // Search for symbols
505
- const results = cg.searchNodes('UserService');
506
-
507
- // Get callers of a function
508
- const node = results[0].node;
509
- const callers = cg.getCallers(node.id);
510
-
511
- // Build context for a task
512
- const context = await cg.buildContext('fix login bug', {
513
- maxNodes: 20,
514
- includeCode: true,
515
- format: 'markdown'
516
- });
517
-
518
- // Get impact radius
519
- const impact = cg.getImpactRadius(node.id, 2);
520
-
521
- // Sync changes
522
- const syncResult = await cg.sync();
523
-
524
- // Clean up
525
- cg.close();
526
- ```
527
-
528
- ## โš™๏ธ How It Works
529
-
530
- ### 1. Extraction
531
-
532
- CodeGraph uses [tree-sitter](https://tree-sitter.github.io/) to parse source code into ASTs. Language-specific queries (`.scm` files) extract:
533
-
534
- - **Nodes**: Functions, methods, classes, interfaces, types, variables
535
- - **Edges**: Calls, imports, extends, implements, returns_type
536
-
537
- Each node gets a unique ID based on its kind, file path, name, and line number.
538
-
539
- ### 2. Storage
540
-
541
- All data is stored in a local SQLite database (`.codegraph/codegraph.db`):
542
-
543
- - **nodes** table: All code entities with metadata
544
- - **edges** table: Relationships between nodes
545
- - **files** table: File tracking for incremental updates
546
- - **unresolved_refs** table: References pending resolution
547
- - **vectors** table: Embeddings stored as BLOBs for semantic search
548
- - **nodes_fts**: FTS5 virtual table for full-text search
549
- - **schema_versions** table: Schema version tracking
550
- - **project_metadata** table: Project-level key-value metadata
551
-
552
- ### 3. Reference Resolution
553
-
554
- After extraction, CodeGraph resolves references:
555
-
556
- 1. Match function calls to function definitions
557
- 2. Resolve imports to their source files
558
- 3. Link class inheritance and interface implementations
559
- 4. Apply framework-specific patterns (Express routes, etc.)
560
-
561
- ### 4. Semantic Search
562
-
563
- CodeGraph uses local embeddings (via [@xenova/transformers](https://github.com/xenova/transformers.js)) to enable semantic search:
564
-
565
- 1. Code symbols are embedded using a transformer model
566
- 2. Queries are embedded and compared using cosine similarity
567
- 3. Results are ranked by relevance
568
-
569
- ### 5. Graph Queries
570
-
571
- The graph structure enables powerful queries:
572
-
573
- - **Callers/Callees**: Direct call relationships
574
- - **Impact Radius**: BFS traversal to find all potentially affected code
575
- - **Dependencies**: What a symbol depends on
576
- - **Dependents**: What depends on a symbol
577
-
578
- ### 6. Context Building
579
-
580
- When you request context for a task:
581
-
582
- 1. Semantic search finds relevant entry points
583
- 2. Graph traversal expands to related code
584
- 3. Code snippets are extracted
585
- 4. Results are formatted for AI consumption
586
-
587
- ## โš™๏ธ Configuration
588
-
589
- The `.codegraph/config.json` file controls indexing behavior:
590
-
591
- ```json
592
- {
593
- "version": 1,
594
- "languages": ["typescript", "javascript"],
595
- "exclude": [
596
- "node_modules/**",
597
- "dist/**",
598
- "build/**",
599
- "*.min.js"
600
- ],
601
- "frameworks": [],
602
- "maxFileSize": 1048576,
603
- "extractDocstrings": true,
604
- "trackCallSites": true,
605
- "enableEmbeddings": false
606
- }
607
- ```
608
-
609
- ### Options
610
-
611
- | Option | Description | Default |
612
- |--------|-------------|---------|
613
- | `languages` | Languages to index (auto-detected if empty) | `[]` |
614
- | `exclude` | Glob patterns to ignore | `["node_modules/**", ...]` |
615
- | `frameworks` | Framework hints for better resolution | `[]` |
616
- | `maxFileSize` | Skip files larger than this (bytes) | `1048576` (1MB) |
617
- | `extractDocstrings` | Whether to extract docstrings from code | `true` |
618
- | `trackCallSites` | Whether to track call site locations | `true` |
619
- | `enableEmbeddings` | Enable semantic search embeddings | `false` |
620
-
621
- ## ๐ŸŒ Supported Languages
622
-
623
- | Language | Extension | Status |
624
- |----------|-----------|--------|
625
- | TypeScript | `.ts`, `.tsx` | Full support |
626
- | JavaScript | `.js`, `.jsx`, `.mjs` | Full support |
627
- | Python | `.py` | Full support |
628
- | Go | `.go` | Full support |
629
- | Rust | `.rs` | Full support |
630
- | Java | `.java` | Full support |
631
- | C# | `.cs` | Full support |
632
- | PHP | `.php` | Full support |
633
- | Ruby | `.rb` | Full support |
634
- | C | `.c`, `.h` | Full support |
635
- | C++ | `.cpp`, `.hpp`, `.cc` | Full support |
636
- | Swift | `.swift` | Basic support |
637
- | Kotlin | `.kt`, `.kts` | Basic support |
638
- | Dart | `.dart` | Full support |
639
- | Svelte | `.svelte` | Full support (script extraction, Svelte 5 runes, SvelteKit routes) |
640
- | Liquid | `.liquid` | Full support |
641
-
642
- ## ๐Ÿ”ง Troubleshooting
643
-
644
- ### "CodeGraph not initialized"
645
-
646
- Run `codegraph init` in your project directory first.
647
-
648
- ### Indexing is slow
649
-
650
- - Check if `node_modules` or other large directories are excluded
651
- - Use `--quiet` flag to reduce console output overhead
652
- - Consider increasing `maxFileSize` if you have large files to skip
653
-
654
- ### MCP server not connecting
655
-
656
- 1. Ensure the project is initialized and indexed
657
- 2. Check the path in your MCP configuration is correct
658
- 3. Verify `codegraph serve --mcp` works from the command line
659
- 4. Check Claude Code logs for connection errors
660
-
661
- ### Missing symbols in search
662
-
663
- - Run `codegraph sync` to pick up recent changes
664
- - Check if the file's language is supported
665
- - Verify the file isn't excluded by config patterns
666
-
667
- ---
668
-
669
- ## ๐Ÿ“„ License
670
-
671
- MIT
672
-
673
- ---
674
-
675
- <div align="center">
676
-
677
- **Made for the Claude Code community** ๐Ÿค–
678
-
679
- [Report Bug](https://github.com/colbymchenry/codegraph/issues) ยท [Request Feature](https://github.com/colbymchenry/codegraph/issues)
680
-
681
- </div>
1
+ <div align="center">
2
+
3
+ # ๐Ÿ”ฎ CodeGraph
4
+
5
+ ### Supercharge Claude Code with Semantic Code Intelligence
6
+
7
+ **30% fewer tokens โ€ข 25% fewer tool calls โ€ข 100% local**
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@colbymchenry/codegraph.svg)](https://www.npmjs.com/package/@colbymchenry/codegraph)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
12
+
13
+ [![Windows](https://img.shields.io/badge/Windows-supported-blue.svg)](#)
14
+ [![macOS](https://img.shields.io/badge/macOS-supported-blue.svg)](#)
15
+ [![Linux](https://img.shields.io/badge/Linux-supported-blue.svg)](#)
16
+
17
+ <br />
18
+
19
+ ### Get Started
20
+
21
+ ```bash
22
+ npx @colbymchenry/codegraph
23
+ ```
24
+
25
+ <sub>Interactive installer configures Claude Code automatically</sub>
26
+
27
+ </div>
28
+
29
+ ---
30
+
31
+ ## ๐Ÿš€ Why CodeGraph?
32
+
33
+ When you ask Claude Code to work on a complex task, it spawns **Explore agents** that scan your codebase using grep, glob, and file reads. These agents consume tokens with every tool call.
34
+
35
+ **CodeGraph gives those agents a semantic knowledge graph** โ€” pre-indexed symbol relationships, call graphs, and code structure. Instead of scanning files, agents query the graph instantly.
36
+
37
+ ### ๐Ÿ“Š Benchmark Results
38
+
39
+ We ran the same complex task 3 times with and without CodeGraph:
40
+
41
+ | Metric | Without CodeGraph | With CodeGraph | Improvement |
42
+ |--------|-------------------|----------------|-------------|
43
+ | **Explore tokens** | 157.8k | 111.7k | **29% fewer** |
44
+ | **Per-agent tokens** | 74.0k | 46.4k | **37% fewer** |
45
+ | **Tool calls** | 60 | 45 | **25% fewer** |
46
+ | **Main context usage** | 28.7% | 24.0% | **4.7% less** |
47
+
48
+ <details>
49
+ <summary><strong>Full benchmark data</strong></summary>
50
+
51
+ **With CodeGraph:**
52
+ | Test | Agents | Tool Uses | Explore Tokens | Plan Tokens | Time |
53
+ |------|--------|-----------|----------------|-------------|------|
54
+ | 1 | 3 | 54 | 149.7k | 76.4k | 1m 43s |
55
+ | 2 | 2 | 41 | 102.1k | 74.8k | 1m 29s |
56
+ | 3 | 2 | 40 | 83.3k | 63.3k | 1m 25s |
57
+ | **Avg** | **2.3** | **45** | **111.7k** | **71.5k** | **1m 32s** |
58
+
59
+ **Without CodeGraph:**
60
+ | Test | Agents | Tool Uses | Explore Tokens | Plan Tokens | Time |
61
+ |------|--------|-----------|----------------|-------------|------|
62
+ | 1 | 3 | 74 | 177.3k | 80.5k | 1m 54s |
63
+ | 2 | 2 | 55 | 149.3k | 64.0k | 1m 27s |
64
+ | 3 | 2 | 51 | 146.7k | 62.3k | 1m 17s |
65
+ | **Avg** | **2.3** | **60** | **157.8k** | **68.9k** | **1m 33s** |
66
+
67
+ </details>
68
+
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
+ ---
108
+
109
+ ## โœจ Key Features
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.
129
+
130
+ </td>
131
+ </tr>
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>
153
+
154
+ ---
155
+
156
+ ## ๐ŸŽฏ Quick Start
157
+
158
+ ### 1. Run the Installer
159
+
160
+ ```bash
161
+ npx @colbymchenry/codegraph
162
+ ```
163
+
164
+ The interactive installer will:
165
+ - Configure the MCP server in `~/.claude.json`
166
+ - Set up auto-allow permissions for CodeGraph tools
167
+ - Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
168
+ - Install Claude Code hooks for automatic index syncing
169
+ - Optionally initialize your current project
170
+
171
+ ### 2. Restart Claude Code
172
+
173
+ Restart Claude Code for the MCP server to load.
174
+
175
+ ### 3. Initialize Projects
176
+
177
+ For each project you want to use CodeGraph with:
178
+
179
+ ```bash
180
+ cd your-project
181
+ codegraph init -i
182
+ ```
183
+
184
+ That's it! Claude Code will now use CodeGraph tools automatically when a `.codegraph/` directory exists.
185
+
186
+ <details>
187
+ <summary><strong>Manual Setup (Alternative)</strong></summary>
188
+
189
+ If you prefer manual configuration:
190
+
191
+ **Install globally:**
192
+ ```bash
193
+ npm install -g @colbymchenry/codegraph
194
+ ```
195
+
196
+ **Add to `~/.claude.json`:**
197
+ ```json
198
+ {
199
+ "mcpServers": {
200
+ "codegraph": {
201
+ "type": "stdio",
202
+ "command": "codegraph",
203
+ "args": ["serve", "--mcp"]
204
+ }
205
+ }
206
+ }
207
+ ```
208
+
209
+ **Add to `~/.claude/settings.json` (optional, for auto-allow):**
210
+ ```json
211
+ {
212
+ "permissions": {
213
+ "allow": [
214
+ "mcp__codegraph__codegraph_search",
215
+ "mcp__codegraph__codegraph_context",
216
+ "mcp__codegraph__codegraph_callers",
217
+ "mcp__codegraph__codegraph_callees",
218
+ "mcp__codegraph__codegraph_impact",
219
+ "mcp__codegraph__codegraph_node",
220
+ "mcp__codegraph__codegraph_status",
221
+ "mcp__codegraph__codegraph_files"
222
+ ]
223
+ }
224
+ }
225
+ ```
226
+
227
+ </details>
228
+
229
+ <details>
230
+ <summary><strong>Global Instructions Reference</strong></summary>
231
+
232
+ The installer automatically adds these instructions to `~/.claude/CLAUDE.md`. This is provided here for reference:
233
+
234
+ ```markdown
235
+ ## CodeGraph
236
+
237
+ CodeGraph builds a semantic knowledge graph of codebases for faster, smarter code exploration.
238
+
239
+ ### If `.codegraph/` exists in the project
240
+
241
+ **Use codegraph tools for faster exploration.** These tools provide instant lookups via the code graph instead of scanning files:
242
+
243
+ | Tool | Use For |
244
+ |------|---------|
245
+ | `codegraph_search` | Find symbols by name (functions, classes, types) |
246
+ | `codegraph_context` | Get relevant code context for a task |
247
+ | `codegraph_callers` | Find what calls a function |
248
+ | `codegraph_callees` | Find what a function calls |
249
+ | `codegraph_impact` | See what's affected by changing a symbol |
250
+ | `codegraph_node` | Get details + source code for a symbol |
251
+ | `codegraph_files` | Get project file structure from the index |
252
+
253
+ **When spawning Explore agents in a codegraph-enabled project:**
254
+
255
+ Tell the Explore agent to use codegraph tools for faster exploration.
256
+
257
+ **For quick lookups in the main session:**
258
+ - Use `codegraph_search` instead of grep for finding symbols
259
+ - Use `codegraph_callers`/`codegraph_callees` to trace code flow
260
+ - Use `codegraph_impact` before making changes to see what's affected
261
+
262
+ ### If `.codegraph/` does NOT exist
263
+
264
+ At the start of a session, ask the user if they'd like to initialize CodeGraph:
265
+
266
+ "I notice this project doesn't have CodeGraph initialized. Would you like me to run `codegraph init -i` to build a code knowledge graph?"
267
+ ```
268
+
269
+ </details>
270
+
271
+ ---
272
+
273
+ ## ๐Ÿ“‹ Requirements
274
+
275
+ - Node.js >= 18.0.0
276
+
277
+ ---
278
+
279
+ ## ๐Ÿ’ป CLI Usage
280
+
281
+ ```bash
282
+ codegraph # Run interactive installer
283
+ codegraph install # Run interactive installer (explicit)
284
+ codegraph init [path] # Initialize in a project
285
+ codegraph uninit [path] # Remove CodeGraph from a project
286
+ codegraph index [path] # Full index
287
+ codegraph sync [path] # Incremental update
288
+ codegraph status [path] # Show statistics
289
+ codegraph query <search> # Search symbols
290
+ codegraph files [path] # Show project file structure
291
+ codegraph context <task> # Build context for AI
292
+ codegraph serve --mcp # Start MCP server
293
+ ```
294
+
295
+ ## ๐Ÿ“– CLI Commands
296
+
297
+ ### `codegraph` / `codegraph install`
298
+
299
+ Run the interactive installer for Claude Code integration. Configures MCP server and permissions automatically.
300
+
301
+ ```bash
302
+ codegraph # Run installer (when no args)
303
+ codegraph install # Run installer (explicit)
304
+ npx @colbymchenry/codegraph # Run via npx (no global install needed)
305
+ ```
306
+
307
+ The installer will:
308
+ 1. Ask for installation location (global `~/.claude` or local `./.claude`)
309
+ 2. Configure the MCP server in `claude.json`
310
+ 3. Optionally set up auto-allow permissions
311
+ 4. Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
312
+ 5. Install Claude Code hooks for automatic index syncing
313
+ 6. For local installs: initialize and index the current project
314
+
315
+ ### `codegraph init [path]`
316
+
317
+ Initialize CodeGraph in a project directory. Creates a `.codegraph/` directory with the database and configuration.
318
+
319
+ ```bash
320
+ codegraph init # Initialize in current directory
321
+ codegraph init /path/to/project # Initialize in specific directory
322
+ codegraph init --index # Initialize and immediately index
323
+ ```
324
+
325
+ ### `codegraph uninit [path]`
326
+
327
+ Remove CodeGraph from a project. Deletes the `.codegraph/` directory and all indexed data.
328
+
329
+ ```bash
330
+ codegraph uninit # Remove from current directory
331
+ codegraph uninit --force # Skip confirmation prompt
332
+ ```
333
+
334
+ ### `codegraph index [path]`
335
+
336
+ Index all files in the project. Extracts functions, classes, methods, and their relationships.
337
+
338
+ ```bash
339
+ codegraph index # Index current directory
340
+ codegraph index --force # Force full re-index
341
+ codegraph index --quiet # Suppress progress output
342
+ ```
343
+
344
+ ### `codegraph sync [path]`
345
+
346
+ Incrementally sync changes since the last index. Only processes added, modified, or removed files.
347
+
348
+ ```bash
349
+ codegraph sync # Sync current directory
350
+ codegraph sync --quiet # Suppress output
351
+ ```
352
+
353
+ ### `codegraph status [path]`
354
+
355
+ Show index status and statistics.
356
+
357
+ ```bash
358
+ codegraph status
359
+ ```
360
+
361
+ Output includes:
362
+ - Files indexed, nodes, edges
363
+ - Nodes by kind (functions, classes, methods, etc.)
364
+ - Files by language
365
+ - Pending changes (if any)
366
+
367
+ ### `codegraph query <search>`
368
+
369
+ Search for symbols in the codebase by name.
370
+
371
+ ```bash
372
+ codegraph query "authenticate" # Search for symbols
373
+ codegraph query "User" --kind class # Filter by kind
374
+ codegraph query "process" --limit 20 # Limit results
375
+ codegraph query "validate" --json # Output as JSON
376
+ ```
377
+
378
+ ### `codegraph files [path]`
379
+
380
+ Show the project file structure from the index. Faster than filesystem scanning since it reads from the indexed data.
381
+
382
+ ```bash
383
+ codegraph files # Show file tree
384
+ codegraph files --format flat # Simple list
385
+ codegraph files --format grouped # Group by language
386
+ codegraph files --filter src/components # Filter by directory
387
+ codegraph files --pattern "*.test.ts" # Filter by glob pattern
388
+ codegraph files --max-depth 2 # Limit tree depth
389
+ codegraph files --no-metadata # Hide language/symbol counts
390
+ codegraph files --json # Output as JSON
391
+ ```
392
+
393
+ ### `codegraph context <task>`
394
+
395
+ Build relevant code context for a task. Uses semantic search to find entry points, then expands through the graph to find related code.
396
+
397
+ ```bash
398
+ codegraph context "fix checkout bug"
399
+ codegraph context "add user authentication" --format json
400
+ codegraph context "refactor payment service" --max-nodes 30
401
+ ```
402
+
403
+ ### `codegraph serve`
404
+
405
+ Start CodeGraph as an MCP server for AI assistants.
406
+
407
+ ```bash
408
+ codegraph serve # Show MCP configuration help
409
+ codegraph serve --mcp # Start MCP server (stdio)
410
+ codegraph serve --mcp --path /project # Specify project path
411
+ ```
412
+
413
+ ## ๐Ÿ”Œ MCP Tools Reference
414
+
415
+ 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.
416
+
417
+ ### `codegraph_context`
418
+
419
+ Build context for a specific task. Good for focused queries.
420
+
421
+ ```
422
+ codegraph_context(task: "fix checkout validation bug", maxNodes: 20)
423
+ ```
424
+
425
+ ### `codegraph_search`
426
+
427
+ Quick symbol search by name. Returns locations only.
428
+
429
+ ```
430
+ codegraph_search(query: "UserService", kind: "class", limit: 10)
431
+ ```
432
+
433
+ ### `codegraph_callers` / `codegraph_callees`
434
+
435
+ Find what calls a function, or what a function calls.
436
+
437
+ ```
438
+ codegraph_callers(symbol: "validatePayment", limit: 20)
439
+ codegraph_callees(symbol: "processOrder", limit: 20)
440
+ ```
441
+
442
+ ### `codegraph_impact`
443
+
444
+ Analyze what code would be affected by changing a symbol.
445
+
446
+ ```
447
+ codegraph_impact(symbol: "UserService", depth: 2)
448
+ ```
449
+
450
+ ### `codegraph_node`
451
+
452
+ Get details about a specific symbol. Use `includeCode: true` only when needed.
453
+
454
+ ```
455
+ codegraph_node(symbol: "authenticate", includeCode: true)
456
+ ```
457
+
458
+ ### `codegraph_files`
459
+
460
+ Get the project file structure from the index. Faster than filesystem scanning.
461
+
462
+ ```
463
+ codegraph_files(path: "src/components", format: "tree", includeMetadata: true)
464
+ ```
465
+
466
+ ### `codegraph_status`
467
+
468
+ Check index health and statistics.
469
+
470
+ ### How It Works With Claude Code
471
+
472
+ Claude's **Explore agents** use these tools instead of grep/glob/Read for faster exploration:
473
+
474
+ | Without CodeGraph | With CodeGraph | Benefit |
475
+ |-------------------|----------------|---------|
476
+ | `grep -r "auth"` | `codegraph_search("auth")` | Instant symbol lookup |
477
+ | Multiple `Read` calls | `codegraph_context(task)` | Related code in one call |
478
+ | Manual file tracing | `codegraph_callers/callees` | Call graph traversal |
479
+ | Guessing impact | `codegraph_impact(symbol)` | Know what breaks |
480
+ | `Glob`/`find` scanning | `codegraph_files(path)` | Indexed file structure |
481
+
482
+ This hybrid approach gives you **~30% fewer tokens** and **~25% fewer tool calls** while letting Claude's native agents handle synthesis.
483
+
484
+ ## ๐Ÿ“š Library Usage
485
+
486
+ CodeGraph can also be used as a library in your Node.js applications:
487
+
488
+ ```typescript
489
+ import CodeGraph from '@colbymchenry/codegraph';
490
+
491
+ // Initialize a new project
492
+ const cg = await CodeGraph.init('/path/to/project');
493
+
494
+ // Or open an existing one
495
+ const cg = await CodeGraph.open('/path/to/project');
496
+
497
+ // Index with progress callback
498
+ await cg.indexAll({
499
+ onProgress: (progress) => {
500
+ console.log(`${progress.phase}: ${progress.current}/${progress.total}`);
501
+ }
502
+ });
503
+
504
+ // Search for symbols
505
+ const results = cg.searchNodes('UserService');
506
+
507
+ // Get callers of a function
508
+ const node = results[0].node;
509
+ const callers = cg.getCallers(node.id);
510
+
511
+ // Build context for a task
512
+ const context = await cg.buildContext('fix login bug', {
513
+ maxNodes: 20,
514
+ includeCode: true,
515
+ format: 'markdown'
516
+ });
517
+
518
+ // Get impact radius
519
+ const impact = cg.getImpactRadius(node.id, 2);
520
+
521
+ // Sync changes
522
+ const syncResult = await cg.sync();
523
+
524
+ // Clean up
525
+ cg.close();
526
+ ```
527
+
528
+ ## โš™๏ธ How It Works
529
+
530
+ ### 1. Extraction
531
+
532
+ CodeGraph uses [tree-sitter](https://tree-sitter.github.io/) to parse source code into ASTs. Language-specific queries (`.scm` files) extract:
533
+
534
+ - **Nodes**: Functions, methods, classes, interfaces, types, variables
535
+ - **Edges**: Calls, imports, extends, implements, returns_type
536
+
537
+ Each node gets a unique ID based on its kind, file path, name, and line number.
538
+
539
+ ### 2. Storage
540
+
541
+ All data is stored in a local SQLite database (`.codegraph/codegraph.db`):
542
+
543
+ - **nodes** table: All code entities with metadata
544
+ - **edges** table: Relationships between nodes
545
+ - **files** table: File tracking for incremental updates
546
+ - **unresolved_refs** table: References pending resolution
547
+ - **vectors** table: Embeddings stored as BLOBs for semantic search
548
+ - **nodes_fts**: FTS5 virtual table for full-text search
549
+ - **schema_versions** table: Schema version tracking
550
+ - **project_metadata** table: Project-level key-value metadata
551
+
552
+ ### 3. Reference Resolution
553
+
554
+ After extraction, CodeGraph resolves references:
555
+
556
+ 1. Match function calls to function definitions
557
+ 2. Resolve imports to their source files
558
+ 3. Link class inheritance and interface implementations
559
+ 4. Apply framework-specific patterns (Express routes, etc.)
560
+
561
+ ### 4. Semantic Search
562
+
563
+ CodeGraph uses local embeddings (via [@xenova/transformers](https://github.com/xenova/transformers.js)) to enable semantic search:
564
+
565
+ 1. Code symbols are embedded using a transformer model
566
+ 2. Queries are embedded and compared using cosine similarity
567
+ 3. Results are ranked by relevance
568
+
569
+ ### 5. Graph Queries
570
+
571
+ The graph structure enables powerful queries:
572
+
573
+ - **Callers/Callees**: Direct call relationships
574
+ - **Impact Radius**: BFS traversal to find all potentially affected code
575
+ - **Dependencies**: What a symbol depends on
576
+ - **Dependents**: What depends on a symbol
577
+
578
+ ### 6. Context Building
579
+
580
+ When you request context for a task:
581
+
582
+ 1. Semantic search finds relevant entry points
583
+ 2. Graph traversal expands to related code
584
+ 3. Code snippets are extracted
585
+ 4. Results are formatted for AI consumption
586
+
587
+ ## โš™๏ธ Configuration
588
+
589
+ The `.codegraph/config.json` file controls indexing behavior:
590
+
591
+ ```json
592
+ {
593
+ "version": 1,
594
+ "languages": ["typescript", "javascript"],
595
+ "exclude": [
596
+ "node_modules/**",
597
+ "dist/**",
598
+ "build/**",
599
+ "*.min.js"
600
+ ],
601
+ "frameworks": [],
602
+ "maxFileSize": 1048576,
603
+ "extractDocstrings": true,
604
+ "trackCallSites": true,
605
+ "enableEmbeddings": false
606
+ }
607
+ ```
608
+
609
+ ### Options
610
+
611
+ | Option | Description | Default |
612
+ |--------|-------------|---------|
613
+ | `languages` | Languages to index (auto-detected if empty) | `[]` |
614
+ | `exclude` | Glob patterns to ignore | `["node_modules/**", ...]` |
615
+ | `frameworks` | Framework hints for better resolution | `[]` |
616
+ | `maxFileSize` | Skip files larger than this (bytes) | `1048576` (1MB) |
617
+ | `extractDocstrings` | Whether to extract docstrings from code | `true` |
618
+ | `trackCallSites` | Whether to track call site locations | `true` |
619
+ | `enableEmbeddings` | Enable semantic search embeddings | `false` |
620
+
621
+ ## ๐ŸŒ Supported Languages
622
+
623
+ | Language | Extension | Status |
624
+ |----------|-----------|--------|
625
+ | TypeScript | `.ts`, `.tsx` | Full support |
626
+ | JavaScript | `.js`, `.jsx`, `.mjs` | Full support |
627
+ | Python | `.py` | Full support |
628
+ | Go | `.go` | Full support |
629
+ | Rust | `.rs` | Full support |
630
+ | Java | `.java` | Full support |
631
+ | C# | `.cs` | Full support |
632
+ | PHP | `.php` | Full support |
633
+ | Ruby | `.rb` | Full support |
634
+ | C | `.c`, `.h` | Full support |
635
+ | C++ | `.cpp`, `.hpp`, `.cc` | Full support |
636
+ | Swift | `.swift` | Basic support |
637
+ | Kotlin | `.kt`, `.kts` | Basic support |
638
+ | Dart | `.dart` | Full support |
639
+ | Svelte | `.svelte` | Full support (script extraction, Svelte 5 runes, SvelteKit routes) |
640
+ | Liquid | `.liquid` | Full support |
641
+ | Pascal / Delphi | `.pas`, `.dpr`, `.dpk`, `.lpr` | Full support (classes, records, interfaces, enums, DFM/FMX form files) |
642
+
643
+ ## ๐Ÿ”ง Troubleshooting
644
+
645
+ ### "CodeGraph not initialized"
646
+
647
+ Run `codegraph init` in your project directory first.
648
+
649
+ ### Indexing is slow
650
+
651
+ - Check if `node_modules` or other large directories are excluded
652
+ - Use `--quiet` flag to reduce console output overhead
653
+ - Consider increasing `maxFileSize` if you have large files to skip
654
+
655
+ ### MCP server not connecting
656
+
657
+ 1. Ensure the project is initialized and indexed
658
+ 2. Check the path in your MCP configuration is correct
659
+ 3. Verify `codegraph serve --mcp` works from the command line
660
+ 4. Check Claude Code logs for connection errors
661
+
662
+ ### Missing symbols in search
663
+
664
+ - Run `codegraph sync` to pick up recent changes
665
+ - Check if the file's language is supported
666
+ - Verify the file isn't excluded by config patterns
667
+
668
+ ---
669
+
670
+ ## ๐Ÿ“„ License
671
+
672
+ MIT
673
+
674
+ ---
675
+
676
+ <div align="center">
677
+
678
+ **Made for the Claude Code community** ๐Ÿค–
679
+
680
+ [Report Bug](https://github.com/colbymchenry/codegraph/issues) ยท [Request Feature](https://github.com/colbymchenry/codegraph/issues)
681
+
682
+ </div>