How the codebase-index Claude Code Skill works and how to extend it.
The skill is defined in skill/SKILL.md with YAML frontmatter that agent
clients use for automatic selection. The primary file is intentionally a short
operating protocol; detailed command and payload material lives in
skill/references/ and is loaded only when needed.
---
name: codebase-index
description: Use before answering repository questions about architecture, implementation, symbols, references, dependencies, refactoring impact, data flow, or bugs. Query the local hybrid index first so the agent reads only evidence-bearing file:line ranges instead of scanning the repository.
allowed-tools: Bash(codebase-index search *), Bash(codebase-index explain *), Bash(codebase-index architecture *), Bash(codebase-index symbol *), Bash(codebase-index refs *), Bash(codebase-index impact *), Bash(codebase-index diff-impact *), Bash(codebase-index path *), Bash(codebase-index describe *), Bash(codebase-index graph *), Bash(codebase-index stats *), Bash(codebase-index doctor *), Bash(codebase-index update *), Bash(codebase-index index *), Bash(cbx *), Read, Grep, Glob
---The skill identifier. Must be unique within .claude/skills/.
Used by Claude Code's automatic skill selection. Should clearly state:
- When to use the skill (before answering codebase questions)
- What it does (searches a local hybrid index)
- Why it's better than scanning (reads only relevant files)
Restricts which tools Claude can use while executing this skill:
| Tool | Purpose |
|---|---|
Bash(codebase-index *) |
Run CLI commands |
Bash(cbx *) |
Run wrapper scripts |
Read |
Read specific line ranges from recommended files |
Grep |
Fallback search when index is weak |
Glob |
Fallback path discovery |
Explicitly not allowed: Write, Edit, Bash (unscoped),
codebase-index * (unscoped), python -m codebase_index *, or destructive
and scaffolding commands such as clean, init, and watch.
User asks codebase question
↓
Skill auto-selected by Claude Code
↓
Route intent: Find / Trace / Predict
↓
Parse JSON response:
- Check index.exists / index.stale
- Read recommended_reads line ranges
- Check confidence level
↓
Answer + file:line evidence
↓
If confidence low → fallback to Grep/Glob
The skill checks index freshness before using results:
index.exists: false→ Runcodebase-index index(full build)index.stale: truewith few changes → Runcodebase-index update(incremental)index.stale: truewith many changes → Runcodebase-index index(full rebuild)- Fresh → Use results directly
The skill enforces token-efficient behavior:
- Read line ranges, not whole files
- Start with top 1-3 results only
- Trust the
snippetfield — it may already answer the question - Use
symbol/refs/impactfor refinement, not reworded searches - Fallback to Grep/Glob only when confidence is low
SKILL.md links two optional resources:
references/commands.md— command options, graph commands, health commands, and query examples.references/response-contract.md— payload fields, freshness handling, partial-coverage behavior, and answer examples.
Do not move the core evidence or freshness protocol out of SKILL.md; agents
need those rules on every invocation. Keep detailed option lists and examples in
references so they do not consume context on routine searches.
The skill asks agents to return:
- the direct answer;
- the minimum supporting
file:lineevidence; - confidence only when evidence is partial, inferred, stale, or missing;
- a next check only when it materially reduces uncertainty.
This prevents tool narration from displacing the actual engineering answer and prevents partial graph coverage from being presented as proof of absence.
If you add a new CLI command, update:
skill/SKILL.md— add the command to the intent tableskill/references/commands.md— document detailed options and examplesskill/SKILL.md— add toallowed-toolsif needed- Both safe wrappers — add the subcommand only if it is read-only or a freshness operation
- Run
python scripts/sync_skill_copies.py
The cbx wrapper scripts (skill/scripts/cbx, skill/scripts/cbx.ps1) ensure the correct binary is used. To extend:
- Add the new subcommand to the allowed list in the wrapper
- Update
allowed-toolsinSKILL.md
Configure automatic index updates in .codeindex.json:
{
"hooks": {
"post_tool_use": {
"enabled": true,
"events": ["Write", "Edit"],
"command": "codebase-index update --quiet"
}
}
}This keeps the index fresh without manual intervention.
The skill is selected when the user's question contains:
- Location queries: "where is", "find", "locate"
- Explanation queries: "how does", "explain", "what does"
- Reference queries: "who calls", "references to", "depends on"
- Impact queries: "what breaks", "impact", "blast radius"
- Architecture queries: "architecture", "overview", "structure"
- Debugging: error messages, stack traces, "why is this error"