codemap
A persistent, file-based map of a codebase. The build script walks the target repo with tree-sitter, writes a graph of symbols and edges to .codemap/graph.json, and a human-readable summary to .codemap/MAP.md. Other skills read these instead of running Glob/Grep/Read loops over raw source.
For TypeScript/JavaScript, use the sibling ts-codemap skill (ts-morph based, higher fidelity). Both write the same .codemap/graph.json schema, so consumer skills don't care which one ran.
Quick start
# Full build (run from repo root, or pass a target path)
/ken-swe:codemap build
# Incremental update (only re-parses files whose SHA256 changed)
/ken-swe:codemap update
Both commands execute the bundled scripts via npx tsx. They install dependencies inside the skill folder on first run; the target repo gets .codemap/ (committed) and .codemap/cache/ (gitignored).
Supported languages
| Language |
Extensions |
Symbols |
Edges |
| Java |
.java |
classes, interfaces, methods |
imports, calls, extends, implements |
| Go |
.go |
funcs, methods, structs, interfaces |
imports, calls |
| Python |
.py |
functions, classes, methods |
imports, calls, extends (base classes) |
| Rust |
.rs |
fns, structs, enums, traits |
imports (use), calls, implements (impl Trait for T) |
Polyglot repos (e.g. a Go backend with a Python ML pipeline) are supported — both languages get indexed in the same graph.json.
When to invoke
- Foundation phase for any non-trivial work in a Java/Go/Python/Rust repo. Build once, then other skills query the map.
- After significant refactors (large file moves, framework upgrade, big API renames).
- When
.codemap/MAP.md is missing or older than the latest commit on the relevant module.
Workflow
1. Detect target repo
- Default: current working directory.
- Optional first argument: explicit path to a target repo.
- Refuse to run if no
.java/.go/.py/.rs files are found — direct the user to /ken-swe:ts-codemap if the repo looks TS/JS.
2. Resolve action
| Argument |
Action |
build (or no arg, no existing .codemap/) |
Full build |
update (or no arg, .codemap/ exists) |
Incremental update via SHA256 cache |
3. Run the script
The skill scripts:
- Walk the target repo, collecting
.java/.go/.py/.rs files (ignoring vendored/build dirs).
- Initialize tree-sitter and load the WASM grammar for each detected language.
- For each file: parse, run the language's extraction queries, emit nodes + edges.
- Write
.codemap/graph.json, .codemap/MAP.md, and update .codemap/cache/<sha>.json per file.
- On first run, append
.codemap/cache/ to the target repo's .gitignore.
4. Report
Print a one-screen summary:
- File count, symbol count, edge count.
- Languages detected and per-language counts.
- Top-level modules (dirs with > N symbols).
- Wall-clock time and cache hit rate (update mode).
Output format
Identical to ts-codemap — same graph.json schema, same MAP.md sections. Consumer skills read from .codemap/ regardless of which producer ran.
{
"meta": {
"generated_at": "<iso8601>",
"version": "1",
"stats": { "files": 0, "nodes": 0, "edges": 0 },
"languages": { "python": 12, "go": 5 }
},
"nodes": [
{
"id": "<rel-path>#<symbol>",
"type": "file|class|function|const|module",
"file": "<rel-path>",
"name": "<symbol>",
"line_start": 0,
"line_end": 0,
"exported": true,
"lang": "python|go|java|rust"
}
],
"edges": [
{ "source": "<id>", "target": "<id>", "type": "imports|calls|extends|implements|exports" }
]
}
Stable IDs: <rel-path>#<symbol> for symbols, <rel-path> for files. For class methods, <rel-path>#<ClassName>.<methodName>.
Consumer contract
Other skills read .codemap/ first. Each consumer skill has a short note describing how it queries the map. Keep the format stable — breaking changes to graph.json need a version bump in meta.version.
v1 scope
Included
- Java, Go, Python, Rust
- Top-level functions/methods, classes/structs/enums/interfaces/traits
- Imports (lexical: target is the module path string, not a resolved file)
- Calls (lexical: target is the called identifier name)
- Inheritance edges where the language has the concept (Java
extends/implements, Python base classes, Rust impl Trait for T)
- SHA256-keyed incremental cache
- Polyglot indexing (multiple languages in one
graph.json)
Out of scope (intentionally, for v1)
- TS/JS (use
ts-codemap)
- Other languages (C, C++, Ruby, Kotlin, Swift, etc.)
- Cross-file symbol resolution (imports stay as lexical strings)
- Generics / type parameters
- Macros (Rust) / annotations (Java) / decorators (Python) — captured by name only
- Vector search / embeddings
- Watch mode
Failure modes
- No source files — refuse with a clear error suggesting
/ken-swe:ts-codemap for TS/JS repos.
- WASM grammar load failure — log and skip that language's files; continue with others.
- File parse error — skip the file, log a warning, continue.
graph.json larger than 5 MB — emit a warning suggesting the user trim ignored dirs (e.g. target/, vendor/, __pycache__/).
Relationship to other skills
| Phase |
Skill |
Uses codemap for |
| Implementation |
feature-dev |
Stage 2 codebase exploration: read MAP.md first, then targeted graph.json lookups |
| Debugging |
bug-fix |
Stage 2 root cause: trace caller/callee edges instead of grepping for usages |
| Quality |
code-review |
Blast-radius assessment: transitive callers of changed symbols |
| Planning |
prd-to-plan |
Module boundaries when defining tracer-bullet slices |
1---2name: codemap3description: Build and maintain a persistent structural index of a Java, Go, Python, or Rust codebase under .codemap/ (graph.json + MAP.md), so other skills explore via the map instead of grep + read loops. Tree-sitter based; supports polyglot repos. Use when starting work in an unfamiliar non-TS/JS repo, when the user asks to build/refresh/update the codemap, after large refactors, or before any exploration phase that would otherwise scan source files. For TypeScript/JavaScript repos, use the sibling `ts-codemap` skill — it has higher fidelity (path aliases, re-export flattening, JSX).4---56# codemap78A persistent, file-based map of a codebase. The build script walks the target repo with tree-sitter, writes a graph of symbols and edges to `.codemap/graph.json`, and a human-readable summary to `.codemap/MAP.md`. Other skills read these instead of running Glob/Grep/Read loops over raw source.910For TypeScript/JavaScript, use the sibling `ts-codemap` skill (ts-morph based, higher fidelity). Both write the same `.codemap/graph.json` schema, so consumer skills don't care which one ran.1112## Quick start1314```sh15# Full build (run from repo root, or pass a target path)16/ken-swe:codemap build1718# Incremental update (only re-parses files whose SHA256 changed)19/ken-swe:codemap update20```2122Both commands execute the bundled scripts via `npx tsx`. They install dependencies inside the skill folder on first run; the target repo gets `.codemap/` (committed) and `.codemap/cache/` (gitignored).2324## Supported languages2526| Language | Extensions | Symbols | Edges |27|---|---|---|---|28| Java | `.java` | classes, interfaces, methods | imports, calls, extends, implements |29| Go | `.go` | funcs, methods, structs, interfaces | imports, calls |30| Python | `.py` | functions, classes, methods | imports, calls, extends (base classes) |31| Rust | `.rs` | fns, structs, enums, traits | imports (`use`), calls, implements (`impl Trait for T`) |3233Polyglot repos (e.g. a Go backend with a Python ML pipeline) are supported — both languages get indexed in the same `graph.json`.3435## When to invoke3637- **Foundation phase** for any non-trivial work in a Java/Go/Python/Rust repo. Build once, then other skills query the map.38- After significant refactors (large file moves, framework upgrade, big API renames).39- When `.codemap/MAP.md` is missing or older than the latest commit on the relevant module.4041## Workflow4243### 1. Detect target repo4445- Default: current working directory.46- Optional first argument: explicit path to a target repo.47- Refuse to run if no `.java`/`.go`/`.py`/`.rs` files are found — direct the user to `/ken-swe:ts-codemap` if the repo looks TS/JS.4849### 2. Resolve action5051| Argument | Action |52|---|---|53| `build` (or no arg, no existing `.codemap/`) | Full build |54| `update` (or no arg, `.codemap/` exists) | Incremental update via SHA256 cache |5556### 3. Run the script5758The skill scripts:59601. Walk the target repo, collecting `.java`/`.go`/`.py`/`.rs` files (ignoring vendored/build dirs).612. Initialize tree-sitter and load the WASM grammar for each detected language.623. For each file: parse, run the language's extraction queries, emit nodes + edges.634. Write `.codemap/graph.json`, `.codemap/MAP.md`, and update `.codemap/cache/<sha>.json` per file.645. On first run, append `.codemap/cache/` to the target repo's `.gitignore`.6566### 4. Report6768Print a one-screen summary:6970- File count, symbol count, edge count.71- Languages detected and per-language counts.72- Top-level modules (dirs with > N symbols).73- Wall-clock time and cache hit rate (update mode).7475## Output format7677Identical to `ts-codemap` — same `graph.json` schema, same `MAP.md` sections. Consumer skills read from `.codemap/` regardless of which producer ran.7879```json80{81 "meta": {82 "generated_at": "<iso8601>",83 "version": "1",84 "stats": { "files": 0, "nodes": 0, "edges": 0 },85 "languages": { "python": 12, "go": 5 }86 },87 "nodes": [88 {89 "id": "<rel-path>#<symbol>",90 "type": "file|class|function|const|module",91 "file": "<rel-path>",92 "name": "<symbol>",93 "line_start": 0,94 "line_end": 0,95 "exported": true,96 "lang": "python|go|java|rust"97 }98 ],99 "edges": [100 { "source": "<id>", "target": "<id>", "type": "imports|calls|extends|implements|exports" }101 ]102}103```104105Stable IDs: `<rel-path>#<symbol>` for symbols, `<rel-path>` for files. For class methods, `<rel-path>#<ClassName>.<methodName>`.106107## Consumer contract108109Other skills read `.codemap/` first. Each consumer skill has a short note describing how it queries the map. Keep the format stable — breaking changes to `graph.json` need a version bump in `meta.version`.110111## v1 scope112113**Included**114115- Java, Go, Python, Rust116- Top-level functions/methods, classes/structs/enums/interfaces/traits117- Imports (lexical: target is the module path string, not a resolved file)118- Calls (lexical: target is the called identifier name)119- Inheritance edges where the language has the concept (Java `extends`/`implements`, Python base classes, Rust `impl Trait for T`)120- SHA256-keyed incremental cache121- Polyglot indexing (multiple languages in one `graph.json`)122123**Out of scope** (intentionally, for v1)124125- TS/JS (use `ts-codemap`)126- Other languages (C, C++, Ruby, Kotlin, Swift, etc.)127- Cross-file symbol resolution (imports stay as lexical strings)128- Generics / type parameters129- Macros (Rust) / annotations (Java) / decorators (Python) — captured by name only130- Vector search / embeddings131- Watch mode132133## Failure modes134135- **No source files** — refuse with a clear error suggesting `/ken-swe:ts-codemap` for TS/JS repos.136- **WASM grammar load failure** — log and skip that language's files; continue with others.137- **File parse error** — skip the file, log a warning, continue.138- **`graph.json` larger than 5 MB** — emit a warning suggesting the user trim ignored dirs (e.g. `target/`, `vendor/`, `__pycache__/`).139140## Relationship to other skills141142| Phase | Skill | Uses codemap for |143|---|---|---|144| Implementation | `feature-dev` | Stage 2 codebase exploration: read `MAP.md` first, then targeted `graph.json` lookups |145| Debugging | `bug-fix` | Stage 2 root cause: trace caller/callee edges instead of grepping for usages |146| Quality | `code-review` | Blast-radius assessment: transitive callers of changed symbols |147| Planning | `prd-to-plan` | Module boundaries when defining tracer-bullet slices |