|
| 1 | +# CodeMap |
| 2 | + |
| 3 | +AST-based code graph mapping plugin for [Claude Code](https://docs.anthropic.com/en/docs/claude-code). Scan your codebase once, persist a structural graph, and load compact slices in future sessions — saving ~95% tokens compared to re-reading all source files. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **AST Parsing** — Uses tree-sitter (WASM) for accurate structural analysis, no regex guessing |
| 8 | +- **Multi-Language** — TypeScript, JavaScript, Python, Go, Rust, Java, C, C++ |
| 9 | +- **Smart Slicing** — Project overview (~500 tokens) + per-module slices (~2-5k tokens) instead of full source (~200k+) |
| 10 | +- **Incremental Updates** — File hash comparison detects changes; only re-parses modified files |
| 11 | +- **Impact Analysis** — See what's affected before you refactor |
| 12 | +- **Auto-Triggering** — Skills activate automatically based on your conversation context |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +```bash |
| 17 | +cd cli |
| 18 | +npm install |
| 19 | +``` |
| 20 | + |
| 21 | +Then register the plugin in Claude Code by pointing to the `.claude-plugin/` directory. |
| 22 | + |
| 23 | +## CLI Commands |
| 24 | + |
| 25 | +All commands are run via `node cli/bin/codegraph.js <command>`. |
| 26 | + |
| 27 | +| Command | Description | |
| 28 | +|---------|-------------| |
| 29 | +| `scan <dir>` | Full AST scan, generates `.codemap/` with graph + slices | |
| 30 | +| `status` | Show graph metadata (files, modules, last scan time) | |
| 31 | +| `query <symbol>` | Search for functions, classes, types by name | |
| 32 | +| `slice [module]` | Output project overview or a specific module slice as JSON | |
| 33 | +| `update` | Incremental update — re-parse only changed files | |
| 34 | +| `impact <target>` | Analyze which modules are affected by changing a target | |
| 35 | + |
| 36 | +### Examples |
| 37 | + |
| 38 | +```bash |
| 39 | +# Scan a project |
| 40 | +node cli/bin/codegraph.js scan /path/to/project |
| 41 | + |
| 42 | +# Check graph status |
| 43 | +node cli/bin/codegraph.js status |
| 44 | + |
| 45 | +# Query a symbol |
| 46 | +node cli/bin/codegraph.js query "handleLogin" |
| 47 | + |
| 48 | +# Get module slice with dependencies |
| 49 | +node cli/bin/codegraph.js slice auth --with-deps |
| 50 | + |
| 51 | +# Incremental update after code changes |
| 52 | +node cli/bin/codegraph.js update |
| 53 | + |
| 54 | +# Impact analysis before refactoring |
| 55 | +node cli/bin/codegraph.js impact auth --depth 3 |
| 56 | +``` |
| 57 | + |
| 58 | +## Skills |
| 59 | + |
| 60 | +When installed as a Claude Code plugin, these skills auto-trigger based on conversation context: |
| 61 | + |
| 62 | +| Skill | Triggers On | |
| 63 | +|-------|------------| |
| 64 | +| `/scan` | "扫描", "索引", "scan", "index", "map codebase" | |
| 65 | +| `/load` | "加载图谱", "项目结构", "load", "code structure" | |
| 66 | +| `/update` | "更新图谱", "refresh", "代码改了" | |
| 67 | +| `/query` | "查找", "谁调用了", "where is", "find function" | |
| 68 | +| `/impact` | "影响范围", "refactor impact", "change impact" | |
| 69 | + |
| 70 | +## Supported Languages |
| 71 | + |
| 72 | +| Language | Extensions | Extracted Structures | |
| 73 | +|----------|-----------|---------------------| |
| 74 | +| TypeScript | `.ts`, `.tsx` | Functions, imports, exports, classes, interfaces, type aliases | |
| 75 | +| JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` | Functions, imports, exports, classes | |
| 76 | +| Python | `.py` | Functions (decorated), imports, `__all__` exports, classes | |
| 77 | +| Go | `.go` | Functions, methods (with receiver), imports, exported names, structs, type specs | |
| 78 | +| Rust | `.rs` | Functions, impl methods, use declarations, pub exports, structs, enums, traits | |
| 79 | +| Java | `.java` | Methods, constructors, imports, public exports, classes, interfaces, enums | |
| 80 | +| C | `.c`, `.h` | Functions, `#include`, non-static exports, structs, enums, typedefs | |
| 81 | +| C++ | `.cpp`, `.cc`, `.cxx`, `.hpp`, `.hh` | Qualified functions (`Class::method`), includes, classes, structs, namespaces | |
| 82 | + |
| 83 | +## Graph Structure |
| 84 | + |
| 85 | +Scanning produces a `.codemap/` directory: |
| 86 | + |
| 87 | +``` |
| 88 | +.codemap/ |
| 89 | +├── graph.json # Full structural graph |
| 90 | +├── meta.json # File hashes, timestamps, commit info |
| 91 | +└── slices/ |
| 92 | + ├── _overview.json # Compact project overview (~500 tokens) |
| 93 | + ├── auth.json # Per-module detailed slice |
| 94 | + ├── api.json |
| 95 | + └── ... |
| 96 | +``` |
| 97 | + |
| 98 | +## Tests |
| 99 | + |
| 100 | +```bash |
| 101 | +cd cli |
| 102 | +npm test |
| 103 | +``` |
| 104 | + |
| 105 | +## License |
| 106 | + |
| 107 | +[MIT](LICENSE) |
0 commit comments