context-codebase
Project context engine for fast repo orientation, cached handoff, and
task-focused code retrieval.
Artifacts:
- Snapshot:
{project}/repo/progress/context-codebase.json
- Index state:
{project}/repo/progress/context-codebase.index.json
- SQLite FTS5 index:
{project}/repo/progress/context-codebase.db
When To Use
Use this skill when you need to:
- understand a codebase quickly
- refresh a reusable project snapshot
- retrieve focused files and snippets for a concrete question
- prepare a deep technical walkthrough from a cached project context
- fuzzy-search symbols by name (IDE-like Ctrl+P / Go to Symbol)
- identify change hotspots and blame history via Git integration
When NOT to Use
Skip this skill when:
- the task is a small bugfix or single-file change that does not require repo-wide orientation
- you already have full context from a recently loaded handoff or snapshot
- the question is purely conceptual (language syntax, algorithm design) with no codebase dependency
- the repository is tiny (< 10 source files) and manual file reading is faster
- you need live runtime behavior (API calls, DB queries, server state) rather than static code analysis
- the snapshot is known to be significantly stale and a full regeneration would be expensive relative to the benefit
Modes
/context-codebase
Default entry.
Behavior:
- Generate a new snapshot when none exists
- Reuse the cached snapshot when the source fingerprint is unchanged
- Return a project overview optimized for fast model understanding
Use it when:
- entering a project for the first time
- switching to a new model or IDE
- you want a general repo overview
/context-codebase refresh
Incrementally update the index and cache metadata.
Behavior:
- Recompute the source fingerprint and compare it with the cached artifacts
- Reuse the cached artifacts when nothing changed
- Update the index incrementally when sources changed
- Keep the existing snapshot structure and only refresh metadata needed by the
cache contract
- Can be combined with
read / report to refresh before answering
Use it when:
- the repo changed and you want the cache to catch up
- you want fresh context without forcing unnecessary rebuild work
- you want
read / report to consume the freshest snapshot first
/context-codebase read
Focused retrieval mode.
Behavior:
- Consume the existing snapshot and index
- Skip forced regeneration logic
- Return a retrieval-oriented payload with:
files
snippets
flowAnchors
nextHops
searchScope
hotspots
externalContext
Use it when:
- the snapshot already exists
- you want fast file and snippet retrieval for a specific question
- you want to preserve tokens and avoid rescanning
Host requirements:
- Explicitly say read mode is consuming the existing snapshot and index
- Do not imply the repo is being rescanned
- Start from
files, snippets, nextHops, and searchScope
- Do not jump to repo-wide search first
Preferred opening:
我将直接读取已有快照和索引,不重新扫描仓库。
我会先用 read payload 里的 files、snippets 和 nextHops 做定点读取,不先做全仓搜索。
Avoid:
Read answer contract:
- Treat
read as a quick implementation summary, not a deep technical report
- Use this order when the payload has enough evidence:
- one-sentence conclusion
- call entry
- core implementation files
- key anchors
- one-sentence implementation summary
- Prefer 3-4 core files and 3-5 anchors
- Prioritize entry points and execution flow before type definitions or tables
- Stop once the next model can continue reading code efficiently
- Leave exhaustive tracing, edge cases, and broader architecture to
report
/context-codebase report
Deep-analysis mode.
Behavior:
- Consume the existing snapshot and index when present
- Generate a snapshot first only when missing
- Return a
deep-pack for host-side deep report generation
- Treat
deep-pack generation as the default stopping point for the parent thread
Use it when:
- you want a full technical report
- you want a complete call chain or architecture trace
- you want to preserve the parent thread token budget
Host requirements:
- Explicitly say report mode is consuming the existing snapshot and index
- Mention snapshot generation only if the snapshot is actually missing
- Prefer delegating
deep-pack to a subagent or delegated worker
- Do not continue parent-thread
Read / Search expansion after the pack is
generated unless delegation is unavailable
Preferred opening:
我将基于已有快照和索引生成 deep-pack,不重新扫描仓库。
如果宿主支持 subagent,我会优先把 deep-pack 交给子任务处理。
在可委派的情况下,我会停在 deep-pack 边界,不在主线程继续展开长报告。
Avoid:
我先重新分析整个仓库再写报告。
deep-pack 已生成,现在我继续在主线程读取关键文件并输出完整长报告。
Execution Semantics
The entrypoint is always scripts/generate.py, but the mode determines whether
source code is scanned or cached artifacts are consumed:
- default mode: may generate a snapshot or reuse a cached one
refresh: incrementally updates the index when sources changed and keeps the
existing snapshot structure
read: consumes the existing snapshot and index to build a retrieval payload
report: consumes the existing snapshot and index to build a deep-pack
Important clarifications:
- Seeing
python ... generate.py ... --read or --report does not mean the
repo is being rescanned
- Seeing
refresh means "incrementally update the index if needed", not "force rebuild"
freshness.reason inside a read or report payload describes how the
current snapshot was produced previously; it does not mean the current
invocation regenerated the snapshot
git.status=dirty means the worktree has uncommitted changes; it does not
automatically prove that the snapshot fingerprint changed
Retrieval Model
The retrieval pipeline uses FTS5 BM25 keyword search combined with graph-aware expansion and importance boosting:
- BM25 keyword (FTS5 SQLite) — lexical precision for exact matches
- Graph expansion (dependency graph neighbors) — structural context around high-scoring chunks
- Important-file boosting — prioritizes key configuration and entry-point files
- Recent-change boosting — boosts recently modified files for bugfix/code-review tasks
- Fuzzy symbol search (FuzzySymbolSearcher) — IDE-style camelCase/snake_case fuzzy matching
Chunking
- Regex chunker — line-based chunking (60-line windows with anchor-point overlap), works for all languages.
Symbol Search
- FuzzySymbolSearcher — IDE-like Ctrl+P symbol lookup with camelCase and snake_case aware fuzzy matching. Filters by file path patterns.
Git Integration
- GitEnrichment (
git_index.py) — annotates chunks with change frequency, hotspot score, churn metric, recent authors, and blame data. Results feed into recent-change-boost and importance-boost retrieval strategies.
Retrieval Workflow
For read:
- Inspect
files, snippets, flowAnchors, nextHops, and searchScope
- Read suggested files directly when possible
- Only widen to repo search if the payload is insufficient
- Exclude
repo/progress/, node_modules/, dist/, build/, and
__pycache__/ when widening search
For report:
- Inspect
coreFiles, snippets, flowAnchors, and recommendedReportShape
- If the host supports subagents, pass the
deep-pack there
- Stop at the pack boundary on the parent thread when delegation is available
- Fall back to same-thread deep reporting only when delegation is unavailable
Query Guidance
For focused questions, prefer --task with a UTF-8 safe query channel.
⚠️ Cross-Lingual Search Limitation:
- If your internal reasoning or the user's prompt is in a non-English language (e.g., Chinese) but the codebase uses English identifiers, you MUST append English keyword translations to your query string.
- Why? BM25 uses literal FTS5 token matching, which yields 0 hits if lexical characters do not overlap.
- Example: Instead of
--query "记忆模块", use --query "记忆模块 memory module".
On Windows or any environment where non-ASCII query text may become mojibake:
- Prefer
--query-escaped <ascii_only_query>
- Then
--query-file <utf8_file>
- Then
--query-stdin
- Avoid raw
--query for non-ASCII input when the shell is unreliable
CLI output contract:
- stdout is reserved for UTF-8 JSON payloads
- warnings and errors must go to stderr
Manual Script Usage
Replace {skill_dir} with the actual installed skill path. In this repository,
that path is context-codebase/.
python {skill_dir}/scripts/generate.py <project_path>
python {skill_dir}/scripts/generate.py <project_path> refresh
python {skill_dir}/scripts/generate.py <project_path> --read
python {skill_dir}/scripts/generate.py <project_path> --read --refresh
python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query "skill lifecycle runtime"
python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-escaped "\\u6280\\u80fd\\u7ba1\\u7406\\u5668\\u5982\\u4f55\\u5b9e\\u73b0"
python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-file query.txt
python {skill_dir}/scripts/generate.py <project_path> --report --task feature-delivery --query "skill download flow"
cat query.txt | python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-stdin
Windows-safe example:
python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-escaped "\\u6280\\u80fd\\u4e0b\\u8f7d\\u6d41\\u7a0b"
References
Read these only when needed:
- references/snapshot-schema.md
- read when you need field-level snapshot or retrieval payload details
- references/response-contract.md
- read when you need the full presentation contract for overview or read-mode outputs
- references/deep-pack.md
- read when you need the
report protocol, host delegation rules, or deep-pack fields
Core Rules
- Exclude generated/vendor noise such as
.git, node_modules, dist,
build, __pycache__, and repo/progress
- Avoid self-referential scans of the skill's own output
- Prefer cached artifacts over rescanning whenever the mode allows it
- Use
read for focused retrieval and report for deep-pack generation
- Keep the parent thread lightweight in
report mode when delegation exists
Boundaries
- Focus on repo orientation, snapshot maintenance, and targeted retrieval.
- Do not expand into broad implementation work unless another skill or agent explicitly takes over.
- Prefer cached context artifacts over unnecessary rescans.
Escalation Rules
Pause and ask the owner before:
- forcing a full refresh when cached artifacts are still adequate
- broadening retrieval into a repository-wide rewrite or redesign exercise
- delegating deep-pack work when the added token and coordination cost is not justified
Final Output Contract (MANDATORY)
Output style is mode-specific:
read:
- Answer the user's concrete code question directly.
- Prefer a compact summary of the code location, call entry, core files, and
implementation flow.
- Do not append the explicit headings
Skill Fit, Primary Deliverable,
Execution Evidence, Risks / Open Questions, or Next Action in normal
successful reads.
- Only surface execution evidence or risks when they materially affect answer
quality, such as cache staleness, fallback retrieval, low-confidence hits,
or missing source coverage.
report and refresh:
- End with a visible structured closeout containing:
Skill Fit - why context-codebase was the right retrieval path
Primary Deliverable - snapshot/read/report artifact or answer package
Execution Evidence - cache usage, files indexed, or retrieval sources
Risks / Open Questions - stale cache risk, missing context, or unresolved ambiguity
Next Action - the recommended follow-up retrieval or implementation step
1---2name: context-codebase3description: Project context engine for repo orientation, cached handoff, and task-focused code retrieval.4---56# context-codebase78Project context engine for fast repo orientation, cached handoff, and9task-focused code retrieval.1011Artifacts:1213- Snapshot: `{project}/repo/progress/context-codebase.json`14- Index state: `{project}/repo/progress/context-codebase.index.json`15- SQLite FTS5 index: `{project}/repo/progress/context-codebase.db`1617## When To Use1819Use this skill when you need to:2021- understand a codebase quickly22- refresh a reusable project snapshot23- retrieve focused files and snippets for a concrete question24- prepare a deep technical walkthrough from a cached project context25- fuzzy-search symbols by name (IDE-like Ctrl+P / Go to Symbol)26- identify change hotspots and blame history via Git integration2728## When NOT to Use2930Skip this skill when:3132- the task is a small bugfix or single-file change that does not require repo-wide orientation33- you already have full context from a recently loaded handoff or snapshot34- the question is purely conceptual (language syntax, algorithm design) with no codebase dependency35- the repository is tiny (< 10 source files) and manual file reading is faster36- you need live runtime behavior (API calls, DB queries, server state) rather than static code analysis37- the snapshot is known to be significantly stale and a full regeneration would be expensive relative to the benefit3839## Modes4041### `/context-codebase`4243Default entry.4445Behavior:4647- Generate a new snapshot when none exists48- Reuse the cached snapshot when the source fingerprint is unchanged49- Return a project overview optimized for fast model understanding5051Use it when:5253- entering a project for the first time54- switching to a new model or IDE55- you want a general repo overview5657### `/context-codebase refresh`5859Incrementally update the index and cache metadata.6061Behavior:6263- Recompute the source fingerprint and compare it with the cached artifacts64- Reuse the cached artifacts when nothing changed65- Update the index incrementally when sources changed66- Keep the existing snapshot structure and only refresh metadata needed by the67 cache contract68- Can be combined with `read` / `report` to refresh before answering6970Use it when:7172- the repo changed and you want the cache to catch up73- you want fresh context without forcing unnecessary rebuild work74- you want `read` / `report` to consume the freshest snapshot first7576### `/context-codebase read`7778Focused retrieval mode.7980Behavior:8182- Consume the existing snapshot and index83- Skip forced regeneration logic84- Return a retrieval-oriented payload with:85 - `files`86 - `snippets`87 - `flowAnchors`88 - `nextHops`89 - `searchScope`90 - `hotspots`91 - `externalContext`9293Use it when:9495- the snapshot already exists96- you want fast file and snippet retrieval for a specific question97- you want to preserve tokens and avoid rescanning9899Host requirements:100101- Explicitly say read mode is consuming the existing snapshot and index102- Do not imply the repo is being rescanned103- Start from `files`, `snippets`, `nextHops`, and `searchScope`104- Do not jump to repo-wide search first105106Preferred opening:107108- `我将直接读取已有快照和索引,不重新扫描仓库。`109- `我会先用 read payload 里的 files、snippets 和 nextHops 做定点读取,不先做全仓搜索。`110111Avoid:112113- `我先重新加载项目上下文。`114- `我先重新扫描仓库。`115116Read answer contract:117118- Treat `read` as a quick implementation summary, not a deep technical report119- Use this order when the payload has enough evidence:120 1. one-sentence conclusion121 2. call entry122 3. core implementation files123 4. key anchors124 5. one-sentence implementation summary125- Prefer 3-4 core files and 3-5 anchors126- Prioritize entry points and execution flow before type definitions or tables127- Stop once the next model can continue reading code efficiently128- Leave exhaustive tracing, edge cases, and broader architecture to `report`129130### `/context-codebase report`131132Deep-analysis mode.133134Behavior:135136- Consume the existing snapshot and index when present137- Generate a snapshot first only when missing138- Return a `deep-pack` for host-side deep report generation139- Treat `deep-pack` generation as the default stopping point for the parent thread140141Use it when:142143- you want a full technical report144- you want a complete call chain or architecture trace145- you want to preserve the parent thread token budget146147Host requirements:148149- Explicitly say report mode is consuming the existing snapshot and index150- Mention snapshot generation only if the snapshot is actually missing151- Prefer delegating `deep-pack` to a subagent or delegated worker152- Do not continue parent-thread `Read` / `Search` expansion after the pack is153 generated unless delegation is unavailable154155Preferred opening:156157- `我将基于已有快照和索引生成 deep-pack,不重新扫描仓库。`158- `如果宿主支持 subagent,我会优先把 deep-pack 交给子任务处理。`159- `在可委派的情况下,我会停在 deep-pack 边界,不在主线程继续展开长报告。`160161Avoid:162163- `我先重新分析整个仓库再写报告。`164- `deep-pack 已生成,现在我继续在主线程读取关键文件并输出完整长报告。`165166## Execution Semantics167168The entrypoint is always `scripts/generate.py`, but the mode determines whether169source code is scanned or cached artifacts are consumed:170171- default mode: may generate a snapshot or reuse a cached one172- `refresh`: incrementally updates the index when sources changed and keeps the173 existing snapshot structure174- `read`: consumes the existing snapshot and index to build a retrieval payload175- `report`: consumes the existing snapshot and index to build a `deep-pack`176177Important clarifications:178179- Seeing `python ... generate.py ... --read` or `--report` does not mean the180 repo is being rescanned181- Seeing `refresh` means "incrementally update the index if needed", not "force rebuild"182- `freshness.reason` inside a `read` or `report` payload describes how the183 current snapshot was produced previously; it does not mean the current184 invocation regenerated the snapshot185- `git.status=dirty` means the worktree has uncommitted changes; it does not186 automatically prove that the snapshot fingerprint changed187188## Retrieval Model189190The retrieval pipeline uses FTS5 BM25 keyword search combined with graph-aware expansion and importance boosting:191192- **BM25 keyword** (FTS5 SQLite) — lexical precision for exact matches193- **Graph expansion** (dependency graph neighbors) — structural context around high-scoring chunks194- **Important-file boosting** — prioritizes key configuration and entry-point files195- **Recent-change boosting** — boosts recently modified files for bugfix/code-review tasks196- **Fuzzy symbol search** (FuzzySymbolSearcher) — IDE-style camelCase/snake_case fuzzy matching197198### Chunking199200- **Regex chunker** — line-based chunking (60-line windows with anchor-point overlap), works for all languages.201202### Symbol Search203204- **FuzzySymbolSearcher** — IDE-like Ctrl+P symbol lookup with camelCase and snake_case aware fuzzy matching. Filters by file path patterns.205206### Git Integration207208- **GitEnrichment** (`git_index.py`) — annotates chunks with change frequency, hotspot score, churn metric, recent authors, and blame data. Results feed into `recent-change-boost` and `importance-boost` retrieval strategies.209210## Retrieval Workflow211212For `read`:2132141. Inspect `files`, `snippets`, `flowAnchors`, `nextHops`, and `searchScope`2152. Read suggested files directly when possible2163. Only widen to repo search if the payload is insufficient2174. Exclude `repo/progress/`, `node_modules/`, `dist/`, `build/`, and218 `__pycache__/` when widening search219220For `report`:2212221. Inspect `coreFiles`, `snippets`, `flowAnchors`, and `recommendedReportShape`2232. If the host supports subagents, pass the `deep-pack` there2243. Stop at the pack boundary on the parent thread when delegation is available2254. Fall back to same-thread deep reporting only when delegation is unavailable226227## Query Guidance228229For focused questions, prefer `--task` with a UTF-8 safe query channel.230231**⚠️ Cross-Lingual Search Limitation:**232- If your internal reasoning or the user's prompt is in a non-English language (e.g., Chinese) but the codebase uses English identifiers, you **MUST append English keyword translations** to your query string.233- *Why?* BM25 uses literal FTS5 token matching, which yields 0 hits if lexical characters do not overlap.234- *Example:* Instead of `--query "记忆模块"`, use `--query "记忆模块 memory module"`.235236On Windows or any environment where non-ASCII query text may become mojibake:237238- Prefer `--query-escaped <ascii_only_query>`239- Then `--query-file <utf8_file>`240- Then `--query-stdin`241- Avoid raw `--query` for non-ASCII input when the shell is unreliable242243CLI output contract:244245- stdout is reserved for UTF-8 JSON payloads246- warnings and errors must go to stderr247248## Manual Script Usage249250Replace `{skill_dir}` with the actual installed skill path. In this repository,251that path is `context-codebase/`.252253```bash254python {skill_dir}/scripts/generate.py <project_path>255python {skill_dir}/scripts/generate.py <project_path> refresh256python {skill_dir}/scripts/generate.py <project_path> --read257python {skill_dir}/scripts/generate.py <project_path> --read --refresh258python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query "skill lifecycle runtime"259python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-escaped "\\u6280\\u80fd\\u7ba1\\u7406\\u5668\\u5982\\u4f55\\u5b9e\\u73b0"260python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-file query.txt261python {skill_dir}/scripts/generate.py <project_path> --report --task feature-delivery --query "skill download flow"262cat query.txt | python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-stdin263```264265Windows-safe example:266267```powershell268python {skill_dir}/scripts/generate.py <project_path> --read --task feature-delivery --query-escaped "\\u6280\\u80fd\\u4e0b\\u8f7d\\u6d41\\u7a0b"269```270271## References272273Read these only when needed:274275- [references/snapshot-schema.md](references/snapshot-schema.md)276 - read when you need field-level snapshot or retrieval payload details277- [references/response-contract.md](references/response-contract.md)278 - read when you need the full presentation contract for overview or read-mode outputs279- [references/deep-pack.md](references/deep-pack.md)280 - read when you need the `report` protocol, host delegation rules, or deep-pack fields281282## Core Rules283284- Exclude generated/vendor noise such as `.git`, `node_modules`, `dist`,285 `build`, `__pycache__`, and `repo/progress`286- Avoid self-referential scans of the skill's own output287- Prefer cached artifacts over rescanning whenever the mode allows it288- Use `read` for focused retrieval and `report` for deep-pack generation289- Keep the parent thread lightweight in `report` mode when delegation exists290291## Boundaries292293- Focus on repo orientation, snapshot maintenance, and targeted retrieval.294- Do not expand into broad implementation work unless another skill or agent explicitly takes over.295- Prefer cached context artifacts over unnecessary rescans.296297## Escalation Rules298299Pause and ask the owner before:300301- forcing a full refresh when cached artifacts are still adequate302- broadening retrieval into a repository-wide rewrite or redesign exercise303- delegating deep-pack work when the added token and coordination cost is not justified304305## Final Output Contract (MANDATORY)306307Output style is mode-specific:308309- `read`:310 - Answer the user's concrete code question directly.311 - Prefer a compact summary of the code location, call entry, core files, and312 implementation flow.313 - Do not append the explicit headings `Skill Fit`, `Primary Deliverable`,314 `Execution Evidence`, `Risks / Open Questions`, or `Next Action` in normal315 successful reads.316 - Only surface execution evidence or risks when they materially affect answer317 quality, such as cache staleness, fallback retrieval, low-confidence hits,318 or missing source coverage.319320- `report` and `refresh`:321 - End with a visible structured closeout containing:322 1. `Skill Fit` - why `context-codebase` was the right retrieval path323 2. `Primary Deliverable` - snapshot/read/report artifact or answer package324 3. `Execution Evidence` - cache usage, files indexed, or retrieval sources325 4. `Risks / Open Questions` - stale cache risk, missing context, or unresolved ambiguity326 5. `Next Action` - the recommended follow-up retrieval or implementation step