@colbymchenry/codegraph 0.2.9 → 0.4.8

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.

Potentially problematic release.


This version of @colbymchenry/codegraph might be problematic. Click here for more details.

Files changed (113) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +647 -641
  3. package/dist/bin/codegraph.d.ts +7 -2
  4. package/dist/bin/codegraph.d.ts.map +1 -1
  5. package/dist/bin/codegraph.js +360 -140
  6. package/dist/bin/codegraph.js.map +1 -1
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +8 -1
  9. package/dist/config.js.map +1 -1
  10. package/dist/context/index.d.ts +17 -4
  11. package/dist/context/index.d.ts.map +1 -1
  12. package/dist/context/index.js +182 -15
  13. package/dist/context/index.js.map +1 -1
  14. package/dist/db/index.d.ts.map +1 -1
  15. package/dist/db/index.js +16 -0
  16. package/dist/db/index.js.map +1 -1
  17. package/dist/db/migrations.d.ts +1 -1
  18. package/dist/db/migrations.d.ts.map +1 -1
  19. package/dist/db/migrations.js +11 -12
  20. package/dist/db/migrations.js.map +1 -1
  21. package/dist/db/queries.d.ts +19 -0
  22. package/dist/db/queries.d.ts.map +1 -1
  23. package/dist/db/queries.js +221 -107
  24. package/dist/db/queries.js.map +1 -1
  25. package/dist/db/schema.sql +154 -149
  26. package/dist/directory.d.ts +13 -1
  27. package/dist/directory.d.ts.map +1 -1
  28. package/dist/directory.js +62 -19
  29. package/dist/directory.js.map +1 -1
  30. package/dist/errors.d.ts +1 -1
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/errors.js +7 -1
  33. package/dist/errors.js.map +1 -1
  34. package/dist/extraction/grammars.d.ts +9 -4
  35. package/dist/extraction/grammars.d.ts.map +1 -1
  36. package/dist/extraction/grammars.js +133 -65
  37. package/dist/extraction/grammars.js.map +1 -1
  38. package/dist/extraction/index.d.ts.map +1 -1
  39. package/dist/extraction/index.js +119 -7
  40. package/dist/extraction/index.js.map +1 -1
  41. package/dist/extraction/tree-sitter.d.ts +62 -0
  42. package/dist/extraction/tree-sitter.d.ts.map +1 -1
  43. package/dist/extraction/tree-sitter.js +937 -34
  44. package/dist/extraction/tree-sitter.js.map +1 -1
  45. package/dist/graph/traversal.d.ts.map +1 -1
  46. package/dist/graph/traversal.js +6 -2
  47. package/dist/graph/traversal.js.map +1 -1
  48. package/dist/index.d.ts +6 -38
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +85 -74
  51. package/dist/index.js.map +1 -1
  52. package/dist/installer/banner.js +7 -7
  53. package/dist/installer/claude-md-template.js +32 -32
  54. package/dist/installer/config-writer.d.ts +9 -0
  55. package/dist/installer/config-writer.d.ts.map +1 -1
  56. package/dist/installer/config-writer.js +78 -0
  57. package/dist/installer/config-writer.js.map +1 -1
  58. package/dist/installer/index.d.ts.map +1 -1
  59. package/dist/installer/index.js +28 -16
  60. package/dist/installer/index.js.map +1 -1
  61. package/dist/mcp/index.d.ts +14 -3
  62. package/dist/mcp/index.d.ts.map +1 -1
  63. package/dist/mcp/index.js +109 -29
  64. package/dist/mcp/index.js.map +1 -1
  65. package/dist/mcp/tools.d.ts +62 -1
  66. package/dist/mcp/tools.d.ts.map +1 -1
  67. package/dist/mcp/tools.js +414 -43
  68. package/dist/mcp/tools.js.map +1 -1
  69. package/dist/mcp/transport.d.ts.map +1 -1
  70. package/dist/mcp/transport.js +2 -0
  71. package/dist/mcp/transport.js.map +1 -1
  72. package/dist/resolution/frameworks/index.d.ts +1 -0
  73. package/dist/resolution/frameworks/index.d.ts.map +1 -1
  74. package/dist/resolution/frameworks/index.js +5 -1
  75. package/dist/resolution/frameworks/index.js.map +1 -1
  76. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  77. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  78. package/dist/resolution/frameworks/svelte.js +268 -0
  79. package/dist/resolution/frameworks/svelte.js.map +1 -0
  80. package/dist/resolution/index.d.ts +11 -2
  81. package/dist/resolution/index.d.ts.map +1 -1
  82. package/dist/resolution/index.js +94 -13
  83. package/dist/resolution/index.js.map +1 -1
  84. package/dist/sentry.d.ts +22 -0
  85. package/dist/sentry.d.ts.map +1 -0
  86. package/dist/sentry.js +159 -0
  87. package/dist/sentry.js.map +1 -0
  88. package/dist/sync/index.d.ts +4 -2
  89. package/dist/sync/index.d.ts.map +1 -1
  90. package/dist/sync/index.js +3 -5
  91. package/dist/sync/index.js.map +1 -1
  92. package/dist/types.d.ts +5 -1
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js +11 -0
  95. package/dist/types.js.map +1 -1
  96. package/dist/utils.d.ts +45 -2
  97. package/dist/utils.d.ts.map +1 -1
  98. package/dist/utils.js +114 -3
  99. package/dist/utils.js.map +1 -1
  100. package/dist/vectors/embedder.d.ts +1 -1
  101. package/dist/vectors/embedder.d.ts.map +1 -1
  102. package/dist/vectors/embedder.js +5 -2
  103. package/dist/vectors/embedder.js.map +1 -1
  104. package/dist/vectors/search.d.ts.map +1 -1
  105. package/dist/vectors/search.js +33 -32
  106. package/dist/vectors/search.js.map +1 -1
  107. package/package.json +72 -65
  108. package/scripts/patch-tree-sitter-dart.js +112 -0
  109. package/scripts/postinstall.js +71 -0
  110. package/dist/sync/git-hooks.d.ts +0 -66
  111. package/dist/sync/git-hooks.d.ts.map +0 -1
  112. package/dist/sync/git-hooks.js +0 -281
  113. package/dist/sync/git-hooks.js.map +0 -1
package/README.md CHANGED
@@ -1,641 +1,647 @@
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
- <br />
14
-
15
- ### Get Started
16
-
17
- ```bash
18
- npx @colbymchenry/codegraph
19
- ```
20
-
21
- <sub>Interactive installer configures Claude Code automatically</sub>
22
-
23
- </div>
24
-
25
- ---
26
-
27
- ## 🚀 Why CodeGraph?
28
-
29
- 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.
30
-
31
- **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.
32
-
33
- ### 📊 Benchmark Results
34
-
35
- We ran the same complex task 3 times with and without CodeGraph:
36
-
37
- | Metric | Without CodeGraph | With CodeGraph | Improvement |
38
- |--------|-------------------|----------------|-------------|
39
- | **Explore tokens** | 157.8k | 111.7k | **29% fewer** |
40
- | **Per-agent tokens** | 74.0k | 46.4k | **37% fewer** |
41
- | **Tool calls** | 60 | 45 | **25% fewer** |
42
- | **Main context usage** | 28.7% | 24.0% | **4.7% less** |
43
-
44
- <details>
45
- <summary><strong>Full benchmark data</strong></summary>
46
-
47
- **With CodeGraph:**
48
- | Test | Agents | Tool Uses | Explore Tokens | Plan Tokens | Time |
49
- |------|--------|-----------|----------------|-------------|------|
50
- | 1 | 3 | 54 | 149.7k | 76.4k | 1m 43s |
51
- | 2 | 2 | 41 | 102.1k | 74.8k | 1m 29s |
52
- | 3 | 2 | 40 | 83.3k | 63.3k | 1m 25s |
53
- | **Avg** | **2.3** | **45** | **111.7k** | **71.5k** | **1m 32s** |
54
-
55
- **Without CodeGraph:**
56
- | Test | Agents | Tool Uses | Explore Tokens | Plan Tokens | Time |
57
- |------|--------|-----------|----------------|-------------|------|
58
- | 1 | 3 | 74 | 177.3k | 80.5k | 1m 54s |
59
- | 2 | 2 | 55 | 149.3k | 64.0k | 1m 27s |
60
- | 3 | 2 | 51 | 146.7k | 62.3k | 1m 17s |
61
- | **Avg** | **2.3** | **60** | **157.8k** | **68.9k** | **1m 33s** |
62
-
63
- </details>
64
-
65
- ### 🔄 How It Works
66
-
67
- ```
68
- ┌─────────────────────────────────────────────────────────────────┐
69
- │ Claude Code │
70
- │ │
71
- │ "Implement user authentication" │
72
- │ │ │
73
-
74
- ┌─────────────────┐ ┌─────────────────┐
75
- │ Explore Agent │ ──── Explore Agent │ │
76
- └────────┬────────┘ └────────┬────────┘
77
- │ │ │ │
78
- └───────────┼────────────────────────┼─────────────────────────────┘
79
-
80
- ▼ ▼
81
- ┌───────────────────────────────────────────────────────────────────┐
82
- │ CodeGraph MCP Server │
83
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
84
- │ │ Search │ │ Callers │ │ Context │ │
85
- │ │ "auth" │ │ "login()" │ │ for task │ │
86
- └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
87
- │ │ │
88
- └────────────────┼────────────────┘
89
-
90
- ┌───────────────────────┐
91
- SQLite Graph DB
92
- • 387 symbols │ │
93
- • 1,204 edges │ │
94
- │ • Instant lookups │
95
- └───────────────────────┘
96
- └───────────────────────────────────────────────────────────────────┘
97
- ```
98
-
99
- **Without CodeGraph:** Explore agents use `grep`, `glob`, and `Read` to scan files → many API calls, high token usage
100
-
101
- **With CodeGraph:** Explore agents query the graph via MCP tools → instant results, local processing, fewer tokens
102
-
103
- ---
104
-
105
- ## Key Features
106
-
107
- <table>
108
- <tr>
109
- <td width="33%" valign="top">
110
-
111
- ### 🧠 Smart Context Building
112
- One tool call returns everything Claude needs—entry points, related symbols, and code snippets. No more expensive exploration agents.
113
-
114
- </td>
115
- <td width="33%" valign="top">
116
-
117
- ### 🔍 Semantic Search
118
- Find code by meaning, not just text. Search for "authentication" and find `login`, `validateToken`, `AuthService`—even with different naming conventions.
119
-
120
- </td>
121
- <td width="33%" valign="top">
122
-
123
- ### 📈 Impact Analysis
124
- Know exactly what breaks before you change it. Trace callers, callees, and the full impact radius of any symbol.
125
-
126
- </td>
127
- </tr>
128
- <tr>
129
- <td width="33%" valign="top">
130
-
131
- ### 🌍 15+ Languages
132
- TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin—all with the same API.
133
-
134
- </td>
135
- <td width="33%" valign="top">
136
-
137
- ### 🔒 100% Local
138
- No data leaves your machine. No API keys. No external services. Everything runs on your local SQLite database.
139
-
140
- </td>
141
- <td width="33%" valign="top">
142
-
143
- ### ⚡ Always Fresh
144
- Git hooks automatically sync the index on every commit. Your code intelligence is always up to date.
145
-
146
- </td>
147
- </tr>
148
- </table>
149
-
150
- ---
151
-
152
- ## 🎯 Quick Start
153
-
154
- ### 1. Run the Installer
155
-
156
- ```bash
157
- npx @colbymchenry/codegraph
158
- ```
159
-
160
- The interactive installer will:
161
- - Configure the MCP server in `~/.claude.json`
162
- - Set up auto-allow permissions for CodeGraph tools
163
- - Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
164
- - Optionally initialize your current project
165
-
166
- ### 2. Restart Claude Code
167
-
168
- Restart Claude Code for the MCP server to load.
169
-
170
- ### 3. Initialize Projects
171
-
172
- For each project you want to use CodeGraph with:
173
-
174
- ```bash
175
- cd your-project
176
- codegraph init -i
177
- ```
178
-
179
- That's it! Claude Code will now use CodeGraph tools automatically when a `.codegraph/` directory exists.
180
-
181
- <details>
182
- <summary><strong>Manual Setup (Alternative)</strong></summary>
183
-
184
- If you prefer manual configuration:
185
-
186
- **Install globally:**
187
- ```bash
188
- npm install -g @colbymchenry/codegraph
189
- ```
190
-
191
- **Add to `~/.claude.json`:**
192
- ```json
193
- {
194
- "mcpServers": {
195
- "codegraph": {
196
- "type": "stdio",
197
- "command": "codegraph",
198
- "args": ["serve", "--mcp"]
199
- }
200
- }
201
- }
202
- ```
203
-
204
- **Add to `~/.claude/settings.json` (optional, for auto-allow):**
205
- ```json
206
- {
207
- "permissions": {
208
- "allow": [
209
- "mcp__codegraph__codegraph_search",
210
- "mcp__codegraph__codegraph_context",
211
- "mcp__codegraph__codegraph_callers",
212
- "mcp__codegraph__codegraph_callees",
213
- "mcp__codegraph__codegraph_impact",
214
- "mcp__codegraph__codegraph_node",
215
- "mcp__codegraph__codegraph_status"
216
- ]
217
- }
218
- }
219
- ```
220
-
221
- </details>
222
-
223
- <details>
224
- <summary><strong>Global Instructions Reference</strong></summary>
225
-
226
- The installer automatically adds these instructions to `~/.claude/CLAUDE.md`. This is provided here for reference:
227
-
228
- ```markdown
229
- ## CodeGraph
230
-
231
- CodeGraph builds a semantic knowledge graph of codebases for faster, smarter code exploration.
232
-
233
- ### If `.codegraph/` exists in the project
234
-
235
- **Use codegraph tools for faster exploration.** These tools provide instant lookups via the code graph instead of scanning files:
236
-
237
- | Tool | Use For |
238
- |------|---------|
239
- | `codegraph_search` | Find symbols by name (functions, classes, types) |
240
- | `codegraph_context` | Get relevant code context for a task |
241
- | `codegraph_callers` | Find what calls a function |
242
- | `codegraph_callees` | Find what a function calls |
243
- | `codegraph_impact` | See what's affected by changing a symbol |
244
- | `codegraph_node` | Get details + source code for a symbol |
245
-
246
- **When spawning Explore agents in a codegraph-enabled project:**
247
-
248
- Tell the Explore agent to use codegraph tools for faster exploration.
249
-
250
- **For quick lookups in the main session:**
251
- - Use `codegraph_search` instead of grep for finding symbols
252
- - Use `codegraph_callers`/`codegraph_callees` to trace code flow
253
- - Use `codegraph_impact` before making changes to see what's affected
254
-
255
- ### If `.codegraph/` does NOT exist
256
-
257
- At the start of a session, ask the user if they'd like to initialize CodeGraph:
258
-
259
- "I notice this project doesn't have CodeGraph initialized. Would you like me to run `codegraph init -i` to build a code knowledge graph?"
260
- ```
261
-
262
- </details>
263
-
264
- ---
265
-
266
- ## 📋 Requirements
267
-
268
- - Node.js >= 18.0.0
269
-
270
- ---
271
-
272
- ## 💻 CLI Usage
273
-
274
- ```bash
275
- codegraph # Run interactive installer
276
- codegraph install # Run interactive installer (explicit)
277
- codegraph init [path] # Initialize in a project
278
- codegraph index [path] # Full index
279
- codegraph sync [path] # Incremental update
280
- codegraph status [path] # Show statistics
281
- codegraph query <search> # Search symbols
282
- codegraph context <task> # Build context for AI
283
- codegraph hooks install # Install git auto-sync hook
284
- codegraph serve --mcp # Start MCP server
285
- ```
286
-
287
- ## 📖 CLI Commands
288
-
289
- ### `codegraph` / `codegraph install`
290
-
291
- Run the interactive installer for Claude Code integration. Configures MCP server and permissions automatically.
292
-
293
- ```bash
294
- codegraph # Run installer (when no args)
295
- codegraph install # Run installer (explicit)
296
- npx @colbymchenry/codegraph # Run via npx (no global install needed)
297
- ```
298
-
299
- The installer will:
300
- 1. Ask for installation location (global `~/.claude` or local `./.claude`)
301
- 2. Configure the MCP server in `claude.json`
302
- 3. Optionally set up auto-allow permissions
303
- 4. Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
304
- 5. For local installs: initialize and index the current project
305
-
306
- ### `codegraph init [path]`
307
-
308
- Initialize CodeGraph in a project directory. Creates a `.codegraph/` directory with the database and configuration.
309
-
310
- ```bash
311
- codegraph init # Initialize in current directory
312
- codegraph init /path/to/project # Initialize in specific directory
313
- codegraph init --index # Initialize and immediately index
314
- codegraph init --no-hooks # Skip git hook installation
315
- ```
316
-
317
- ### `codegraph index [path]`
318
-
319
- Index all files in the project. Extracts functions, classes, methods, and their relationships.
320
-
321
- ```bash
322
- codegraph index # Index current directory
323
- codegraph index --force # Force full re-index
324
- codegraph index --quiet # Suppress progress output
325
- ```
326
-
327
- ### `codegraph sync [path]`
328
-
329
- Incrementally sync changes since the last index. Only processes added, modified, or removed files.
330
-
331
- ```bash
332
- codegraph sync # Sync current directory
333
- codegraph sync --quiet # Suppress output
334
- ```
335
-
336
- ### `codegraph status [path]`
337
-
338
- Show index status and statistics.
339
-
340
- ```bash
341
- codegraph status
342
- ```
343
-
344
- Output includes:
345
- - Files indexed, nodes, edges
346
- - Nodes by kind (functions, classes, methods, etc.)
347
- - Files by language
348
- - Pending changes (if any)
349
- - Git hook status
350
-
351
- ### `codegraph query <search>`
352
-
353
- Search for symbols in the codebase by name.
354
-
355
- ```bash
356
- codegraph query "authenticate" # Search for symbols
357
- codegraph query "User" --kind class # Filter by kind
358
- codegraph query "process" --limit 20 # Limit results
359
- codegraph query "validate" --json # Output as JSON
360
- ```
361
-
362
- ### `codegraph context <task>`
363
-
364
- Build relevant code context for a task. Uses semantic search to find entry points, then expands through the graph to find related code.
365
-
366
- ```bash
367
- codegraph context "fix checkout bug"
368
- codegraph context "add user authentication" --format json
369
- codegraph context "refactor payment service" --max-nodes 30
370
- ```
371
-
372
- ### `codegraph hooks`
373
-
374
- Manage git hooks for automatic syncing.
375
-
376
- ```bash
377
- codegraph hooks install # Install post-commit hook
378
- codegraph hooks remove # Remove hook
379
- codegraph hooks status # Check if hook is installed
380
- ```
381
-
382
- ### `codegraph serve`
383
-
384
- Start CodeGraph as an MCP server for AI assistants.
385
-
386
- ```bash
387
- codegraph serve # Show MCP configuration help
388
- codegraph serve --mcp # Start MCP server (stdio)
389
- codegraph serve --mcp --path /project # Specify project path
390
- ```
391
-
392
- ## 🔌 MCP Tools Reference
393
-
394
- 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.
395
-
396
- ### `codegraph_context`
397
-
398
- Build context for a specific task. Good for focused queries.
399
-
400
- ```
401
- codegraph_context(task: "fix checkout validation bug", maxNodes: 20)
402
- ```
403
-
404
- ### `codegraph_search`
405
-
406
- Quick symbol search by name. Returns locations only.
407
-
408
- ```
409
- codegraph_search(query: "UserService", kind: "class", limit: 10)
410
- ```
411
-
412
- ### `codegraph_callers` / `codegraph_callees`
413
-
414
- Find what calls a function, or what a function calls.
415
-
416
- ```
417
- codegraph_callers(symbol: "validatePayment", limit: 20)
418
- codegraph_callees(symbol: "processOrder", limit: 20)
419
- ```
420
-
421
- ### `codegraph_impact`
422
-
423
- Analyze what code would be affected by changing a symbol.
424
-
425
- ```
426
- codegraph_impact(symbol: "UserService", depth: 2)
427
- ```
428
-
429
- ### `codegraph_node`
430
-
431
- Get details about a specific symbol. Use `includeCode: true` only when needed.
432
-
433
- ```
434
- codegraph_node(symbol: "authenticate", includeCode: true)
435
- ```
436
-
437
- ### `codegraph_status`
438
-
439
- Check index health and statistics.
440
-
441
- ### How It Works With Claude Code
442
-
443
- Claude's **Explore agents** use these tools instead of grep/glob/Read for faster exploration:
444
-
445
- | Without CodeGraph | With CodeGraph | Benefit |
446
- |-------------------|----------------|---------|
447
- | `grep -r "auth"` | `codegraph_search("auth")` | Instant symbol lookup |
448
- | Multiple `Read` calls | `codegraph_context(task)` | Related code in one call |
449
- | Manual file tracing | `codegraph_callers/callees` | Call graph traversal |
450
- | Guessing impact | `codegraph_impact(symbol)` | Know what breaks |
451
-
452
- This hybrid approach gives you **~30% fewer tokens** and **~25% fewer tool calls** while letting Claude's native agents handle synthesis.
453
-
454
- ## 📚 Library Usage
455
-
456
- CodeGraph can also be used as a library in your Node.js applications:
457
-
458
- ```typescript
459
- import CodeGraph from '@colbymchenry/codegraph';
460
-
461
- // Initialize a new project
462
- const cg = await CodeGraph.init('/path/to/project');
463
-
464
- // Or open an existing one
465
- const cg = await CodeGraph.open('/path/to/project');
466
-
467
- // Index with progress callback
468
- await cg.indexAll({
469
- onProgress: (progress) => {
470
- console.log(`${progress.phase}: ${progress.current}/${progress.total}`);
471
- }
472
- });
473
-
474
- // Search for symbols
475
- const results = cg.searchNodes('UserService');
476
-
477
- // Get callers of a function
478
- const node = results[0].node;
479
- const callers = cg.getCallers(node.id);
480
-
481
- // Build context for a task
482
- const context = await cg.buildContext('fix login bug', {
483
- maxNodes: 20,
484
- includeCode: true,
485
- format: 'markdown'
486
- });
487
-
488
- // Get impact radius
489
- const impact = cg.getImpactRadius(node.id, 2);
490
-
491
- // Sync changes
492
- const syncResult = await cg.sync();
493
-
494
- // Clean up
495
- cg.close();
496
- ```
497
-
498
- ## ⚙️ How It Works
499
-
500
- ### 1. Extraction
501
-
502
- CodeGraph uses [tree-sitter](https://tree-sitter.github.io/) to parse source code into ASTs. Language-specific queries (`.scm` files) extract:
503
-
504
- - **Nodes**: Functions, methods, classes, interfaces, types, variables
505
- - **Edges**: Calls, imports, extends, implements, returns_type
506
-
507
- Each node gets a unique ID based on its kind, file path, name, and line number.
508
-
509
- ### 2. Storage
510
-
511
- All data is stored in a local SQLite database (`.codegraph/codegraph.db`):
512
-
513
- - **nodes** table: All code entities with metadata
514
- - **edges** table: Relationships between nodes
515
- - **files** table: File tracking for incremental updates
516
- - **node_vectors** / **vector_map**: Embeddings for semantic search (using sqlite-vss)
517
-
518
- ### 3. Reference Resolution
519
-
520
- After extraction, CodeGraph resolves references:
521
-
522
- 1. Match function calls to function definitions
523
- 2. Resolve imports to their source files
524
- 3. Link class inheritance and interface implementations
525
- 4. Apply framework-specific patterns (Express routes, etc.)
526
-
527
- ### 4. Semantic Search
528
-
529
- CodeGraph uses local embeddings (via [@xenova/transformers](https://github.com/xenova/transformers.js)) to enable semantic search:
530
-
531
- 1. Code symbols are embedded using a transformer model
532
- 2. Queries are embedded and compared using cosine similarity
533
- 3. Results are ranked by relevance
534
-
535
- ### 5. Graph Queries
536
-
537
- The graph structure enables powerful queries:
538
-
539
- - **Callers/Callees**: Direct call relationships
540
- - **Impact Radius**: BFS traversal to find all potentially affected code
541
- - **Dependencies**: What a symbol depends on
542
- - **Dependents**: What depends on a symbol
543
-
544
- ### 6. Context Building
545
-
546
- When you request context for a task:
547
-
548
- 1. Semantic search finds relevant entry points
549
- 2. Graph traversal expands to related code
550
- 3. Code snippets are extracted
551
- 4. Results are formatted for AI consumption
552
-
553
- ## ⚙️ Configuration
554
-
555
- The `.codegraph/config.json` file controls indexing behavior:
556
-
557
- ```json
558
- {
559
- "version": 1,
560
- "projectName": "my-project",
561
- "languages": ["typescript", "javascript"],
562
- "exclude": [
563
- "node_modules/**",
564
- "dist/**",
565
- "build/**",
566
- "*.min.js"
567
- ],
568
- "frameworks": ["express", "react"],
569
- "maxFileSize": 1048576,
570
- "gitHooksEnabled": true
571
- }
572
- ```
573
-
574
- ### Options
575
-
576
- | Option | Description | Default |
577
- |--------|-------------|---------|
578
- | `languages` | Languages to index (auto-detected if empty) | `[]` |
579
- | `exclude` | Glob patterns to ignore | `["node_modules/**", ...]` |
580
- | `frameworks` | Framework hints for better resolution | `[]` |
581
- | `maxFileSize` | Skip files larger than this (bytes) | `1048576` (1MB) |
582
- | `gitHooksEnabled` | Enable git hook installation | `true` |
583
-
584
- ## 🌐 Supported Languages
585
-
586
- | Language | Extension | Status |
587
- |----------|-----------|--------|
588
- | TypeScript | `.ts`, `.tsx` | Full support |
589
- | JavaScript | `.js`, `.jsx`, `.mjs` | Full support |
590
- | Python | `.py` | Full support |
591
- | Go | `.go` | Full support |
592
- | Rust | `.rs` | Full support |
593
- | Java | `.java` | Full support |
594
- | C# | `.cs` | Full support |
595
- | PHP | `.php` | Full support |
596
- | Ruby | `.rb` | Full support |
597
- | C | `.c`, `.h` | Full support |
598
- | C++ | `.cpp`, `.hpp`, `.cc` | Full support |
599
- | Swift | `.swift` | Basic support |
600
- | Kotlin | `.kt` | Basic support |
601
-
602
- ## 🔧 Troubleshooting
603
-
604
- ### "CodeGraph not initialized"
605
-
606
- Run `codegraph init` in your project directory first.
607
-
608
- ### Indexing is slow
609
-
610
- - Check if `node_modules` or other large directories are excluded
611
- - Use `--quiet` flag to reduce console output overhead
612
- - Consider increasing `maxFileSize` if you have large files to skip
613
-
614
- ### MCP server not connecting
615
-
616
- 1. Ensure the project is initialized and indexed
617
- 2. Check the path in your MCP configuration is correct
618
- 3. Verify `codegraph serve --mcp` works from the command line
619
- 4. Check Claude Code logs for connection errors
620
-
621
- ### Missing symbols in search
622
-
623
- - Run `codegraph sync` to pick up recent changes
624
- - Check if the file's language is supported
625
- - Verify the file isn't excluded by config patterns
626
-
627
- ---
628
-
629
- ## 📄 License
630
-
631
- MIT
632
-
633
- ---
634
-
635
- <div align="center">
636
-
637
- **Made for the Claude Code community** 🤖
638
-
639
- [Report Bug](https://github.com/colbymchenry/codegraph/issues) · [Request Feature](https://github.com/colbymchenry/codegraph/issues)
640
-
641
- </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
+ ### 🌍 17+ Languages
136
+ TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Dart, Svelte—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
+ Git hooks automatically sync the index on every commit. 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
+ - Optionally initialize your current project
169
+
170
+ ### 2. Restart Claude Code
171
+
172
+ Restart Claude Code for the MCP server to load.
173
+
174
+ ### 3. Initialize Projects
175
+
176
+ For each project you want to use CodeGraph with:
177
+
178
+ ```bash
179
+ cd your-project
180
+ codegraph init -i
181
+ ```
182
+
183
+ That's it! Claude Code will now use CodeGraph tools automatically when a `.codegraph/` directory exists.
184
+
185
+ <details>
186
+ <summary><strong>Manual Setup (Alternative)</strong></summary>
187
+
188
+ If you prefer manual configuration:
189
+
190
+ **Install globally:**
191
+ ```bash
192
+ npm install -g @colbymchenry/codegraph
193
+ ```
194
+
195
+ **Add to `~/.claude.json`:**
196
+ ```json
197
+ {
198
+ "mcpServers": {
199
+ "codegraph": {
200
+ "type": "stdio",
201
+ "command": "codegraph",
202
+ "args": ["serve", "--mcp"]
203
+ }
204
+ }
205
+ }
206
+ ```
207
+
208
+ **Add to `~/.claude/settings.json` (optional, for auto-allow):**
209
+ ```json
210
+ {
211
+ "permissions": {
212
+ "allow": [
213
+ "mcp__codegraph__codegraph_search",
214
+ "mcp__codegraph__codegraph_context",
215
+ "mcp__codegraph__codegraph_callers",
216
+ "mcp__codegraph__codegraph_callees",
217
+ "mcp__codegraph__codegraph_impact",
218
+ "mcp__codegraph__codegraph_node",
219
+ "mcp__codegraph__codegraph_status"
220
+ ]
221
+ }
222
+ }
223
+ ```
224
+
225
+ </details>
226
+
227
+ <details>
228
+ <summary><strong>Global Instructions Reference</strong></summary>
229
+
230
+ The installer automatically adds these instructions to `~/.claude/CLAUDE.md`. This is provided here for reference:
231
+
232
+ ```markdown
233
+ ## CodeGraph
234
+
235
+ CodeGraph builds a semantic knowledge graph of codebases for faster, smarter code exploration.
236
+
237
+ ### If `.codegraph/` exists in the project
238
+
239
+ **Use codegraph tools for faster exploration.** These tools provide instant lookups via the code graph instead of scanning files:
240
+
241
+ | Tool | Use For |
242
+ |------|---------|
243
+ | `codegraph_search` | Find symbols by name (functions, classes, types) |
244
+ | `codegraph_context` | Get relevant code context for a task |
245
+ | `codegraph_callers` | Find what calls a function |
246
+ | `codegraph_callees` | Find what a function calls |
247
+ | `codegraph_impact` | See what's affected by changing a symbol |
248
+ | `codegraph_node` | Get details + source code for a symbol |
249
+
250
+ **When spawning Explore agents in a codegraph-enabled project:**
251
+
252
+ Tell the Explore agent to use codegraph tools for faster exploration.
253
+
254
+ **For quick lookups in the main session:**
255
+ - Use `codegraph_search` instead of grep for finding symbols
256
+ - Use `codegraph_callers`/`codegraph_callees` to trace code flow
257
+ - Use `codegraph_impact` before making changes to see what's affected
258
+
259
+ ### If `.codegraph/` does NOT exist
260
+
261
+ At the start of a session, ask the user if they'd like to initialize CodeGraph:
262
+
263
+ "I notice this project doesn't have CodeGraph initialized. Would you like me to run `codegraph init -i` to build a code knowledge graph?"
264
+ ```
265
+
266
+ </details>
267
+
268
+ ---
269
+
270
+ ## 📋 Requirements
271
+
272
+ - Node.js >= 18.0.0
273
+
274
+ ---
275
+
276
+ ## 💻 CLI Usage
277
+
278
+ ```bash
279
+ codegraph # Run interactive installer
280
+ codegraph install # Run interactive installer (explicit)
281
+ codegraph init [path] # Initialize in a project
282
+ codegraph index [path] # Full index
283
+ codegraph sync [path] # Incremental update
284
+ codegraph status [path] # Show statistics
285
+ codegraph query <search> # Search symbols
286
+ codegraph context <task> # Build context for AI
287
+ codegraph hooks install # Install git auto-sync hook
288
+ codegraph serve --mcp # Start MCP server
289
+ ```
290
+
291
+ ## 📖 CLI Commands
292
+
293
+ ### `codegraph` / `codegraph install`
294
+
295
+ Run the interactive installer for Claude Code integration. Configures MCP server and permissions automatically.
296
+
297
+ ```bash
298
+ codegraph # Run installer (when no args)
299
+ codegraph install # Run installer (explicit)
300
+ npx @colbymchenry/codegraph # Run via npx (no global install needed)
301
+ ```
302
+
303
+ The installer will:
304
+ 1. Ask for installation location (global `~/.claude` or local `./.claude`)
305
+ 2. Configure the MCP server in `claude.json`
306
+ 3. Optionally set up auto-allow permissions
307
+ 4. Add global instructions to `~/.claude/CLAUDE.md` (teaches Claude how to use CodeGraph)
308
+ 5. For local installs: initialize and index the current project
309
+
310
+ ### `codegraph init [path]`
311
+
312
+ Initialize CodeGraph in a project directory. Creates a `.codegraph/` directory with the database and configuration.
313
+
314
+ ```bash
315
+ codegraph init # Initialize in current directory
316
+ codegraph init /path/to/project # Initialize in specific directory
317
+ codegraph init --index # Initialize and immediately index
318
+ codegraph init --no-hooks # Skip git hook installation
319
+ ```
320
+
321
+ ### `codegraph index [path]`
322
+
323
+ Index all files in the project. Extracts functions, classes, methods, and their relationships.
324
+
325
+ ```bash
326
+ codegraph index # Index current directory
327
+ codegraph index --force # Force full re-index
328
+ codegraph index --quiet # Suppress progress output
329
+ ```
330
+
331
+ ### `codegraph sync [path]`
332
+
333
+ Incrementally sync changes since the last index. Only processes added, modified, or removed files.
334
+
335
+ ```bash
336
+ codegraph sync # Sync current directory
337
+ codegraph sync --quiet # Suppress output
338
+ ```
339
+
340
+ ### `codegraph status [path]`
341
+
342
+ Show index status and statistics.
343
+
344
+ ```bash
345
+ codegraph status
346
+ ```
347
+
348
+ Output includes:
349
+ - Files indexed, nodes, edges
350
+ - Nodes by kind (functions, classes, methods, etc.)
351
+ - Files by language
352
+ - Pending changes (if any)
353
+ - Git hook status
354
+
355
+ ### `codegraph query <search>`
356
+
357
+ Search for symbols in the codebase by name.
358
+
359
+ ```bash
360
+ codegraph query "authenticate" # Search for symbols
361
+ codegraph query "User" --kind class # Filter by kind
362
+ codegraph query "process" --limit 20 # Limit results
363
+ codegraph query "validate" --json # Output as JSON
364
+ ```
365
+
366
+ ### `codegraph context <task>`
367
+
368
+ Build relevant code context for a task. Uses semantic search to find entry points, then expands through the graph to find related code.
369
+
370
+ ```bash
371
+ codegraph context "fix checkout bug"
372
+ codegraph context "add user authentication" --format json
373
+ codegraph context "refactor payment service" --max-nodes 30
374
+ ```
375
+
376
+ ### `codegraph hooks`
377
+
378
+ Manage git hooks for automatic syncing.
379
+
380
+ ```bash
381
+ codegraph hooks install # Install post-commit hook
382
+ codegraph hooks remove # Remove hook
383
+ codegraph hooks status # Check if hook is installed
384
+ ```
385
+
386
+ ### `codegraph serve`
387
+
388
+ Start CodeGraph as an MCP server for AI assistants.
389
+
390
+ ```bash
391
+ codegraph serve # Show MCP configuration help
392
+ codegraph serve --mcp # Start MCP server (stdio)
393
+ codegraph serve --mcp --path /project # Specify project path
394
+ ```
395
+
396
+ ## 🔌 MCP Tools Reference
397
+
398
+ 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.
399
+
400
+ ### `codegraph_context`
401
+
402
+ Build context for a specific task. Good for focused queries.
403
+
404
+ ```
405
+ codegraph_context(task: "fix checkout validation bug", maxNodes: 20)
406
+ ```
407
+
408
+ ### `codegraph_search`
409
+
410
+ Quick symbol search by name. Returns locations only.
411
+
412
+ ```
413
+ codegraph_search(query: "UserService", kind: "class", limit: 10)
414
+ ```
415
+
416
+ ### `codegraph_callers` / `codegraph_callees`
417
+
418
+ Find what calls a function, or what a function calls.
419
+
420
+ ```
421
+ codegraph_callers(symbol: "validatePayment", limit: 20)
422
+ codegraph_callees(symbol: "processOrder", limit: 20)
423
+ ```
424
+
425
+ ### `codegraph_impact`
426
+
427
+ Analyze what code would be affected by changing a symbol.
428
+
429
+ ```
430
+ codegraph_impact(symbol: "UserService", depth: 2)
431
+ ```
432
+
433
+ ### `codegraph_node`
434
+
435
+ Get details about a specific symbol. Use `includeCode: true` only when needed.
436
+
437
+ ```
438
+ codegraph_node(symbol: "authenticate", includeCode: true)
439
+ ```
440
+
441
+ ### `codegraph_status`
442
+
443
+ Check index health and statistics.
444
+
445
+ ### How It Works With Claude Code
446
+
447
+ Claude's **Explore agents** use these tools instead of grep/glob/Read for faster exploration:
448
+
449
+ | Without CodeGraph | With CodeGraph | Benefit |
450
+ |-------------------|----------------|---------|
451
+ | `grep -r "auth"` | `codegraph_search("auth")` | Instant symbol lookup |
452
+ | Multiple `Read` calls | `codegraph_context(task)` | Related code in one call |
453
+ | Manual file tracing | `codegraph_callers/callees` | Call graph traversal |
454
+ | Guessing impact | `codegraph_impact(symbol)` | Know what breaks |
455
+
456
+ This hybrid approach gives you **~30% fewer tokens** and **~25% fewer tool calls** while letting Claude's native agents handle synthesis.
457
+
458
+ ## 📚 Library Usage
459
+
460
+ CodeGraph can also be used as a library in your Node.js applications:
461
+
462
+ ```typescript
463
+ import CodeGraph from '@colbymchenry/codegraph';
464
+
465
+ // Initialize a new project
466
+ const cg = await CodeGraph.init('/path/to/project');
467
+
468
+ // Or open an existing one
469
+ const cg = await CodeGraph.open('/path/to/project');
470
+
471
+ // Index with progress callback
472
+ await cg.indexAll({
473
+ onProgress: (progress) => {
474
+ console.log(`${progress.phase}: ${progress.current}/${progress.total}`);
475
+ }
476
+ });
477
+
478
+ // Search for symbols
479
+ const results = cg.searchNodes('UserService');
480
+
481
+ // Get callers of a function
482
+ const node = results[0].node;
483
+ const callers = cg.getCallers(node.id);
484
+
485
+ // Build context for a task
486
+ const context = await cg.buildContext('fix login bug', {
487
+ maxNodes: 20,
488
+ includeCode: true,
489
+ format: 'markdown'
490
+ });
491
+
492
+ // Get impact radius
493
+ const impact = cg.getImpactRadius(node.id, 2);
494
+
495
+ // Sync changes
496
+ const syncResult = await cg.sync();
497
+
498
+ // Clean up
499
+ cg.close();
500
+ ```
501
+
502
+ ## ⚙️ How It Works
503
+
504
+ ### 1. Extraction
505
+
506
+ CodeGraph uses [tree-sitter](https://tree-sitter.github.io/) to parse source code into ASTs. Language-specific queries (`.scm` files) extract:
507
+
508
+ - **Nodes**: Functions, methods, classes, interfaces, types, variables
509
+ - **Edges**: Calls, imports, extends, implements, returns_type
510
+
511
+ Each node gets a unique ID based on its kind, file path, name, and line number.
512
+
513
+ ### 2. Storage
514
+
515
+ All data is stored in a local SQLite database (`.codegraph/codegraph.db`):
516
+
517
+ - **nodes** table: All code entities with metadata
518
+ - **edges** table: Relationships between nodes
519
+ - **files** table: File tracking for incremental updates
520
+ - **node_vectors** / **vector_map**: Embeddings for semantic search (using sqlite-vss)
521
+
522
+ ### 3. Reference Resolution
523
+
524
+ After extraction, CodeGraph resolves references:
525
+
526
+ 1. Match function calls to function definitions
527
+ 2. Resolve imports to their source files
528
+ 3. Link class inheritance and interface implementations
529
+ 4. Apply framework-specific patterns (Express routes, etc.)
530
+
531
+ ### 4. Semantic Search
532
+
533
+ CodeGraph uses local embeddings (via [@xenova/transformers](https://github.com/xenova/transformers.js)) to enable semantic search:
534
+
535
+ 1. Code symbols are embedded using a transformer model
536
+ 2. Queries are embedded and compared using cosine similarity
537
+ 3. Results are ranked by relevance
538
+
539
+ ### 5. Graph Queries
540
+
541
+ The graph structure enables powerful queries:
542
+
543
+ - **Callers/Callees**: Direct call relationships
544
+ - **Impact Radius**: BFS traversal to find all potentially affected code
545
+ - **Dependencies**: What a symbol depends on
546
+ - **Dependents**: What depends on a symbol
547
+
548
+ ### 6. Context Building
549
+
550
+ When you request context for a task:
551
+
552
+ 1. Semantic search finds relevant entry points
553
+ 2. Graph traversal expands to related code
554
+ 3. Code snippets are extracted
555
+ 4. Results are formatted for AI consumption
556
+
557
+ ## ⚙️ Configuration
558
+
559
+ The `.codegraph/config.json` file controls indexing behavior:
560
+
561
+ ```json
562
+ {
563
+ "version": 1,
564
+ "projectName": "my-project",
565
+ "languages": ["typescript", "javascript"],
566
+ "exclude": [
567
+ "node_modules/**",
568
+ "dist/**",
569
+ "build/**",
570
+ "*.min.js"
571
+ ],
572
+ "frameworks": ["express", "react"],
573
+ "maxFileSize": 1048576,
574
+ "gitHooksEnabled": true
575
+ }
576
+ ```
577
+
578
+ ### Options
579
+
580
+ | Option | Description | Default |
581
+ |--------|-------------|---------|
582
+ | `languages` | Languages to index (auto-detected if empty) | `[]` |
583
+ | `exclude` | Glob patterns to ignore | `["node_modules/**", ...]` |
584
+ | `frameworks` | Framework hints for better resolution | `[]` |
585
+ | `maxFileSize` | Skip files larger than this (bytes) | `1048576` (1MB) |
586
+ | `gitHooksEnabled` | Enable git hook installation | `true` |
587
+
588
+ ## 🌐 Supported Languages
589
+
590
+ | Language | Extension | Status |
591
+ |----------|-----------|--------|
592
+ | TypeScript | `.ts`, `.tsx` | Full support |
593
+ | JavaScript | `.js`, `.jsx`, `.mjs` | Full support |
594
+ | Python | `.py` | Full support |
595
+ | Go | `.go` | Full support |
596
+ | Rust | `.rs` | Full support |
597
+ | Java | `.java` | Full support |
598
+ | C# | `.cs` | Full support |
599
+ | PHP | `.php` | Full support |
600
+ | Ruby | `.rb` | Full support |
601
+ | C | `.c`, `.h` | Full support |
602
+ | C++ | `.cpp`, `.hpp`, `.cc` | Full support |
603
+ | Swift | `.swift` | Basic support |
604
+ | Kotlin | `.kt` | Basic support |
605
+ | Dart | `.dart` | Full support |
606
+ | Svelte | `.svelte` | Full support (script extraction, Svelte 5 runes, SvelteKit routes) |
607
+
608
+ ## 🔧 Troubleshooting
609
+
610
+ ### "CodeGraph not initialized"
611
+
612
+ Run `codegraph init` in your project directory first.
613
+
614
+ ### Indexing is slow
615
+
616
+ - Check if `node_modules` or other large directories are excluded
617
+ - Use `--quiet` flag to reduce console output overhead
618
+ - Consider increasing `maxFileSize` if you have large files to skip
619
+
620
+ ### MCP server not connecting
621
+
622
+ 1. Ensure the project is initialized and indexed
623
+ 2. Check the path in your MCP configuration is correct
624
+ 3. Verify `codegraph serve --mcp` works from the command line
625
+ 4. Check Claude Code logs for connection errors
626
+
627
+ ### Missing symbols in search
628
+
629
+ - Run `codegraph sync` to pick up recent changes
630
+ - Check if the file's language is supported
631
+ - Verify the file isn't excluded by config patterns
632
+
633
+ ---
634
+
635
+ ## 📄 License
636
+
637
+ MIT
638
+
639
+ ---
640
+
641
+ <div align="center">
642
+
643
+ **Made for the Claude Code community** 🤖
644
+
645
+ [Report Bug](https://github.com/colbymchenry/codegraph/issues) · [Request Feature](https://github.com/colbymchenry/codegraph/issues)
646
+
647
+ </div>