| name | graph-build |
| description | [Code Intelligence] Use when you need to build, update, or sync the code review knowledge graph. Flag: --scope={full|update|sync} (default auto-detect); --scope=full forces a full rebuild, --scope=update re-parses uncommitted working-tree changes, --scope=sync syncs committed git changes then updates the working tree. |
| version | 1.0.0 |
Quick Summary
Goal: [Code Intelligence] Build, update, or sync the code review knowledge graph. Parses codebase with Tree-sitter into a structural graph (functions, classes, imports, calls, tests) stored in SQLite. Enables blast-radius analysis and graph-powered code review. --scope selects the lifecycle operation โ full (rebuild), update (working-tree changes; folds former /graph-update), sync (committed git changes + working-tree update; folds former /graph-sync) โ default auto-detects from graph status.
Workflow:
- Detect โ classify request scope and target artifacts.
- Execute โ apply required steps with evidence-backed actions.
- Verify โ confirm constraints, output quality, and completion evidence.
Key Rules:
- Scope flag (see Scope Mode): default (no flag) auto-detects via
status (full if never built, else incremental); --scope=full forces rebuild; --scope=update = uncommitted working-tree changes (CLI update, folds /graph-update); --scope=sync = committed git changes then working-tree update (CLI sync + update, folds /graph-sync).
- MUST ATTENTION keep claims evidence-based (
file:line) with confidence >80% to act.
- MUST ATTENTION keep task tracking updated as each step starts/completes.
- NEVER skip mandatory workflow or skill gates.
Prerequisites
Requires Python 3.10+ with: pip install tree-sitter tree-sitter-language-pack networkx
Scope Mode (--scope=)
--scope | CLI verb(s) | What it does | Former skill |
|---|
| (none, default) | status โ build or update | Auto-detect: full build if never built, else incremental update | โ |
full | build --json | Force full rebuild (ignore existing graph) | โ |
update | update --json | Re-parse uncommitted working-tree changes (staged/unstaged) | /graph-update |
sync | sync --json then update --json | Sync committed git changes (last_synced_commit โ HEAD), then working tree | /graph-sync |
Default (no --scope) auto-detects from status. update = working-tree changes (base HEAD~1, options --base/--repo). sync = committed changes + chained working-tree update (the syncโupdate chain is preserved). Session-start auto-sync runs the CLI sync directly via the graph-session-init hook โ independent of this skill. Pick --scope FIRST (default auto-detect), then run the matching branch.
Steps
Default (auto-detect) โ build or incremental update
-
Check availability โ Run via Bash:
python .claude/scripts/code_graph status --json
- If error (Python/deps missing): show install instructions and stop
- If
last_updated is null: graph never built โ proceed with full build
- If
last_updated exists: graph exists โ proceed with incremental update
-
Build or update โ Run via Bash:
- Full build:
python .claude/scripts/code_graph build --json
- Incremental:
python .claude/scripts/code_graph update --json
-
Report results from JSON output:
- Files parsed, nodes created, edges created
- Languages detected
- Any errors encountered
- Build type (full vs incremental)
--scope=full โ force full rebuild
python .claude/scripts/code_graph build --json
Always does a complete reparse (ignores existing graph). Report: files parsed, nodes/edges created, languages, build type.
--scope=update โ uncommitted working-tree changes (folds /graph-update)
python .claude/scripts/code_graph update --json
Diffs the working tree against a base commit (default HEAD~1), re-parses changed/added files, removes deleted files from the graph, then re-runs the API + implicit connectors. Options: --base <commit> (default HEAD~1), --repo <path>. Report: files updated/added/deleted, or "Working tree clean โ graph already up to date".
--scope=sync โ committed git changes + working tree (folds /graph-sync)
-
Sync committed changes via Bash:
python .claude/scripts/code_graph sync --json
Diffs last_synced_commit โ HEAD, re-parses changed/added files, removes deleted files, re-runs connectors, stores new HEAD. If it reports full_rebuild_fallback (unreachable commit after rebase/force-push), a full rebuild was triggered โ inform the user.
-
Update working tree (chained โ former graph-sync step 4) via Bash:
python .claude/scripts/code_graph update --json
-
Report: files synced/added/modified/deleted, then working-tree update results (or "working tree clean").
sync vs update: sync detects committed changes only (last_synced_commit โ HEAD; use after pull/merge/checkout). update detects working-tree changes (staged/uncommitted, mid-session). No --files flag on sync/update (auto-detected from git); there is no incremental subcommand (use update).
When to Use
- First time setting up graph for a project
- After major refactoring or branch switches
- If graph seems stale or out of sync
- Graph auto-updates via PostToolUse hook, so manual builds are rarely needed
Notes
- Graph stored at
.code-graph/graph.db (SQLite, auto-gitignored)
- Supported: Python, TypeScript, JavaScript, Vue, Go, Rust, Java, C#, Ruby, Kotlin, Swift, PHP, Solidity, C/C++
- Initial build: ~10s for 500 files. Incremental: <2s
Connectors (Auto-Run)
After build/update, graph connectors run automatically if configured in project-config.json:
- API Endpoints: Frontend HTTP calls matched to backend routes (
graphConnectors.apiEndpoints)
- Implicit Connections: Entity events, message bus, command events (
graphConnectors.implicitConnections)
See /graph-connect-api and .claude/docs/code-graph-mechanism.md for details.
DB Performance Indexes
The graph database includes optimized indexes created automatically on first build:
idx_nodes_name โ fast node name lookups for search
idx_edges_kind_source โ composite index for filtered edge queries (kind + source)
idx_edges_kind_target โ composite index for filtered edge queries (kind + target)
These indexes are defined in the init schema and auto-create in any new project on first graph build.
Auto-Connect After Build
After building, the CLI automatically runs:
- API connector โ detects frontend HTTP calls matching backend route definitions
- Implicit connector โ detects behavioral relationships (entity events, bus messages, command events) based on rules in
project-config.json โ graphConnectors.implicitConnections[]
This creates edges for MESSAGE_BUS, TRIGGERS_EVENT, PRODUCES_EVENT, TRIGGERS_COMMAND_EVENT, and API_ENDPOINT โ enabling full system flow tracing via the trace command.
Describe (AI-Friendly Command Reference)
Run python .claude/scripts/code_graph describe --json to get MCP-style structured descriptions of all available CLI commands, their parameters, and usage. Useful for AI agents to discover graph capabilities programmatically.
Valid CLI Subcommands
build, update, status, blast-radius, query, connections, trace, search, find-path, batch-query, sync, export, export-mermaid, connect-api, connect-implicit, review-context, describe
migrate-paths is also available to convert existing databases built with absolute file paths into repo-relative storage without reparsing the repository.
Common Mistakes (DO NOT USE)
| Invalid Command | Correct Alternative |
|---|
incremental | update --json (incremental is the default behavior of update) |
update --files <list> | update --json (auto-detects changed files via git diff) |
build --files <list> | build --json (always does full rebuild) |
sync --files <list> | sync --json (auto-detects from git) |
file_summary | connections <file> --json |
Build Graph
Build or incrementally update the persistent code knowledge graph for this repository.
AI Mistake Prevention โ Failure modes to avoid on every task:
Re-read files after context changes. Context compaction, resume, or long-running work can make memory stale; verify current files before acting.
Verify generated content against source evidence. AI hallucinates APIs, names, claims, and document facts. Check the relevant source before documenting or referencing.
Check downstream references before deleting or renaming. Removing an artifact can stale docs, generated mirrors, configs, and callers; map references first.
Trace the full impact chain after edits. Changing a definition can miss derived outputs and consumers. Follow the affected chain before declaring done.
Verify ALL affected outputs, not just the first. One green check is not all green checks; validate every output surface the change can affect.
Assume existing values are intentional โ ask WHY before changing. Before changing a constant, limit, flag, wording, or pattern, read nearby context and history.
Surface ambiguity before acting โ don't pick silently. Multiple valid interpretations require an explicit question or stated assumption with risk.
Keep shared guidance role-relevant. Universal guidance must help every receiving skill or agent; code-specific obligations belong only in code-specific protocols.
Critical Thinking Mindset โ Apply critical thinking, sequential thinking. Every claim needs traced proof, confidence >80% to act.
Anti-hallucination: Never present guess as fact โ cite sources for every claim, admit uncertainty freely, self-check output for errors, cross-reference independently, stay skeptical of own confidence โ certainty without evidence root of all hallucination.
MUST ATTENTION apply critical + sequential thinking โ every claim needs appropriate traced evidence (file:line for repo/code claims; source URL or artifact section for research, product, content, and docs claims); confidence >80% to act, <60% DO NOT recommend. Anti-hallucination: never present guess as fact, admit uncertainty freely, cross-reference independently, stay skeptical of own confidence.
MUST ATTENTION apply AI mistake prevention โ verify generated content against evidence, trace downstream references before deleting or renaming, verify all affected outputs, re-read files after context loss, and surface ambiguity before acting.
Closing Reminders
Protocols in force (concise digest of the SYNC/shared blocks this skill carries) โ MUST ATTENTION honor each canonical body:
-
AI Mistake Prevention: verify generated content against evidence, trace downstream references, verify all affected outputs, re-read after context loss, surface ambiguity.
-
Critical Thinking: traced file:line proof per claim, confidence >80%, NEVER guess as fact.
-
MANDATORY IMPORTANT MUST ATTENTION break work into small todo tasks using TaskCreate BEFORE starting
-
MANDATORY IMPORTANT MUST ATTENTION search codebase for 3+ similar patterns before creating new code
-
MANDATORY IMPORTANT MUST ATTENTION cite file:line evidence for every claim (confidence >80% to act)
-
MANDATORY IMPORTANT MUST ATTENTION add a final review todo task to verify work quality
[TASK-PLANNING] Before acting, analyze task scope and systematically break it into small todo tasks and sub-tasks using TaskCreate.