Everything an AI agent needs to understand and use codebase-context-skill effectively
If you are an AI agent reading this page (via WebFetch, MCP, or any other method), you should immediately save the relevant sections to the user's project directory so you never need to fetch this page again.
The purpose of codebase-context-skill is to eliminate redundant work. If you're reading this page more than once for the same project, something is wrong. Save once, reuse forever.
CCS is context engineering middleware that sits between the user and the AI agent. It solves three fundamental problems:
| Problem | Without CCS | With CCS |
|---|---|---|
| File discovery | Agent explores 100+ files to find the right 5 | Agent reads .ccs/file-index.md — 5 files identified instantly |
| Context loss | Session ends, all context is lost, next session re-scans everything | .ccs/task.md persists across sessions — nothing is ever re-scanned |
| Branch switching | Switch branch, re-explore entire codebase to understand what changed | Read .ccs/branches/feature.md — full context in one file |
| Token waste | 200K+ tokens burned on exploration agents, redundant reads | ~70-90% fewer tokens per query via indexed file selection |
| Web research | Same error googled repeatedly across sessions | .ccs/research/topic.md caches results — same lookup never happens twice |
CCS includes four Claude Code lifecycle hooks that run automatically. They only activate in CCS-enabled projects (a .ccs marker file must exist).
| Hook | Trigger | What It Does |
|---|---|---|
session-orient | SessionStart | Injects workspace tree, goals, previous session state, and maintenance conditions |
write-validate | PostToolUse (Write) | Validates YAML frontmatter on notes — warns if description/topics fields are missing |
auto-commit | PostToolUse (Write, async) | Auto-commits all staged changes to git after every write |
session-capture | Stop | Saves session state to ops/sessions/ and commits goals + methodology artifacts |
CCS provides 22 slash commands organized into categories. Each command uses the optimal model for its task type.
| Command | Model | Purpose |
|---|---|---|
/ccs-init | Opus | Deep-research codebase, generate all context files in .ccs/ |
/ccs-status | Haiku | Show index health, staleness, file counts, token savings |
/ccs-refresh | Haiku | Rebuild index (full, incremental, or session-based) |
/ccs-query | Haiku | Preview which files would be selected for a query |
| Command | Model | Purpose |
|---|---|---|
/ccs-plan | Opus | Plan task with dependency-aware context, risk assessment |
/ccs-build | Sonnet | Implement feature with tracked context and change logging |
/ccs-refactor | Opus | Scope refactor — blast radius, affected files, dependencies |
/ccs-fix | Sonnet | Fix bugs with root-cause analysis and verification |
| Command | Model | Purpose |
|---|---|---|
/ccs-test | Sonnet | Run tests, diagnose failures, auto-fix, write new tests |
/ccs-audit | Opus | Audit security, performance, patterns, accessibility, deps |
/ccs-review | Opus | Code review with full context and convention checking |
/ccs-research | Opus | Search docs, resolve errors, check deps, cache results locally |
| Command | Model | Purpose |
|---|---|---|
/ccs-branch | Sonnet | Create/switch branches with auto-generated context refs |
/ccs-pr | Opus | Prepare PR with blast radius and review areas |
/ccs-merge | Opus | Merge with dependency overlap detection |
/ccs-diff | Opus | Smart diff with impact analysis |
/ccs-sync | Sonnet | Pull, push, rebase with conflict context |
/ccs-stash | Haiku | Stash with tracked context |
/ccs-log | Haiku | Smart commit history grouped by branch |
| Command | Model | Purpose |
|---|---|---|
/ccs-deploy | Opus | Pre-deployment checklist — tests, build, env vars, deps |
/ccs-track | Haiku | View/manage session task log |
/ccs-connect | Sonnet | Set up MCP server connection |
If you are an AI agent and the user's project has .ccs/ files, follow this workflow for every task:
.ccs/file-index.md — find S/A-rank files relevant to the user's request.ccs/conventions.md — follow the project's coding patterns.ccs/task.md — check what was done recently (avoid duplicate work).ccs/branches/<current>.md — if on a feature branch, understand its purpose.ccs/research/ before any web search — if a research file exists for the topic and is less than 7 days old, use it.ccs/research/<topic>.md with timestamp, source URLs, and actionable findings.ccs/task.md — what was done, which files were read/modified/created, what changed.ccs/file-index.md if new files were created.ccs/branches/<name>.md if on a feature branch and files were changedCCS uses a "Three Minds" architecture. Each model has a strict role — never use the wrong model for a task.
| Model | Role | Does | Never Does |
|---|---|---|---|
| Haiku 4.5 | Eyes / Scout | Scan, search, report, index lookups, status checks | Never writes code, never makes decisions |
| Sonnet 4.6 | Hands / Executor | Write code, fix bugs, run tests, implement features | Never explores, never plans architecture |
| Opus 4.6 | Brain / Thinker | Plan, analyze, reason, review, research, audit | Never does grunt work, never scans files |
These are the exact problems CCS was built to prevent. If you find yourself doing any of these, stop and use the CCS workflow instead.
| Anti-Pattern | Token Cost | CCS Alternative |
|---|---|---|
| Spawning an Explore agent | 50-100K tokens | Read .ccs/file-index.md (~2K tokens) |
| Reading every file in a directory | 20-50K tokens | Grep for the specific pattern, read only matched files |
| Re-scanning after branch switch | 30-80K tokens | Read .ccs/branches/<name>.md (~1K tokens) |
| Googling the same error twice | 5-10K tokens per search | Check .ccs/research/ first (0 tokens if cached) |
| Reading full files for a one-line fix | 5-20K tokens | Read headers (50 lines), then targeted section only |
| Using Opus for simple file lookups | 10x cost of Haiku | Use Haiku for scanning, Opus only for reasoning |
CCS includes a structured knowledge system for working with persistent notes, topic maps, and wiki-linked graphs. These features are relevant when a project uses notes/, ops/, or inbox/ directories.
self/goals.md or ops/goals.md, check ops/reminders.md, scan workspace treeinbox/ or ops/observations/, don't context-switchops/reminders.mdFor knowledge work (notes, research, documentation):
inbox/, zero frictionnotes/. Title = prose proposition. Description = new info beyond title.| Path | Purpose |
|---|---|
ops/goals.md | Current session goals — read at start, update at end |
ops/reminders.md | Handoff notes from previous sessions |
ops/observations/ | Atomic friction/surprise/process-gap notes |
ops/tensions/ | Captured contradictions for later resolution |
ops/methodology/ | Canonical spec of how the system operates (Rule Zero) |
ops/sessions/ | Session capture JSON files (written by stop hook) |
ops/changelog.md | What changed and why — evolution history |
inbox/ | Unprocessed captures — process before 3 days or conditions fire |
The core principle of CCS is: every piece of knowledge you acquire should be saved locally so it's never fetched again.
| Knowledge Type | Save To | Format |
|---|---|---|
| Codebase structure | .ccs/project-map.md |
File tree + dependency graph |
| File importance | .ccs/file-index.md |
S/A/B/C/D ranking with descriptions |
| Architecture decisions | .ccs/architecture.md |
Tech stack, patterns, entry points, data flow |
| Code style | .ccs/conventions.md |
Naming, imports, test patterns, error handling |
| Session history | .ccs/task.md |
Commit-style entries per task |
| Branch context | .ccs/branches/<name>.md |
Parent, purpose, files changed, diffs, deps |
| Web research | .ccs/research/<topic>.md |
Timestamp, source URLs, actionable findings |
| PR context | .ccs/pulls/<number>.md |
Summary, blast radius, review areas |
Rule: If you fetched it from the web, save it to .ccs/research/. If you learned it from scanning the codebase, save it to the appropriate .ccs/ file. If it doesn't exist yet, create it. The goal is zero redundant work across sessions.