Project Context
Build and maintain the .context/ directory — a set of markdown files that give any LLM (Claude, Cursor, Copilot, Windsurf, etc.) the background it needs to work effectively in this codebase. These files are tool-agnostic. Agent-specific files like CLAUDE.md or .cursorrules reference them.
Current context
- Repo: !
basename $(git rev-parse --show-toplevel)
- Root: !
git rev-parse --show-toplevel
- Existing context: !
ls .context/ 2>/dev/null || echo "no .context/ directory"
Decision tree
- What are you doing?
- Creating context for a new project (no
.context/ exists) -> follow "Initial setup" below
- Updating existing context (
.context/ exists) -> follow "Audit and update" below
- Adding context for a specific area (user asks about one topic) -> follow "Single document" below
- User says the AI doesn't understand their project -> run "Audit and update" to find gaps, then fill them
Initial setup
1. Analyze the project
Run these to understand the codebase:
ls the root and major directories to understand structure
- Read
package.json, Cargo.toml, go.mod, pyproject.toml, or equivalent for dependencies
- Read existing docs: README, CONTRIBUTING, CLAUDE.md, .cursorrules
git log --oneline -20 for recent activity and commit style
- Glob for config files:
**/*.config.*, **/tsconfig*, biome.json, .eslintrc*, etc.
2. Recommend a context plan
Based on analysis, recommend which documents the project needs. Every project gets overview.md. The rest depend on complexity:
| Document |
When to include |
What it covers |
overview.md |
Always |
Architecture, module boundaries, data flow, key decisions |
conventions.md |
Projects with >5 files |
Coding standards, naming, error handling, file organization |
glossary.md |
Domain-heavy projects |
Business terms, entity definitions, domain relationships |
dependencies.md |
Projects with >3 external deps |
Key deps, why chosen, how configured, what for |
<dirname>.md |
Major subdirectories (src/, api/, lib/, etc.) |
Subdirectory-specific architecture and conventions |
Present the plan as a checklist and get user confirmation before generating.
3. Generate documents
For each document in the plan:
- Read the relevant code thoroughly — don't guess, read the actual files
- Write the document following the format in
references/document-formats.md
- Write it to
.context/<name>.md
Generate overview.md first since other documents reference it.
4. Wire up agent files
After generating .context/, suggest additions to agent-specific files:
- CLAUDE.md: add
See .context/ for project architecture, conventions, and domain knowledge.
- .cursorrules: add equivalent pointer
- AGENTS.md: add equivalent pointer
Don't overwrite existing content — append the pointer or suggest where to add it.
Audit and update
1. Diff analysis
Compare the current .context/ files against the actual codebase:
- Read each
.context/*.md file
- Scan the codebase for changes since the context was written — new directories, changed dependencies, new patterns
- Identify: stale (info contradicts current code), missing (new areas with no context), accurate (still correct)
2. Report
Present a table:
| File | Status | What changed |
|---|---|---|
| overview.md | Stale | New api/ module added, auth rewritten |
| conventions.md | Accurate | — |
| glossary.md | Missing terms | "workspace" and "tenant" used but undefined |
3. Update
For each stale or missing item:
- Read the relevant current code
- Update the
.context/ file with accurate information
- Show the diff of what changed
Single document
When the user asks for a specific document:
- Determine which document type from the table in "Initial setup"
- Analyze the relevant part of the codebase
- Write the document following
references/document-formats.md
- If
.context/ doesn't exist yet, create it and also generate overview.md as a baseline
Writing principles
Context documents serve LLMs, not humans. This changes how you write:
- Be explicit about relationships — "OrderService calls PaymentGateway.charge() which calls Stripe" is better than "OrderService handles payments"
- Name the files — "authentication logic lives in
src/auth/ with the main entry point at src/auth/index.ts" beats "the auth module"
- State the non-obvious — skip things any LLM can infer from reading the code (function signatures, import paths). Focus on why decisions were made and how modules interact
- Keep it current or delete it — wrong context is worse than no context. If something is stale and you can't verify it, remove it rather than leaving potentially wrong information
Key references
| File |
What it covers |
references/document-formats.md |
Templates and structure for each document type |
1---2name: project-context3description: Generates and maintains a hierarchical .context/ directory with architecture overviews, coding conventions, domain glossaries, and dependency maps that give any LLM working in the project the right background. Use when setting up a new project for AI-assisted development, when the user asks to create or update context docs, when onboarding a new LLM tool to an existing codebase, or when the user says the AI doesn't understand their project.4---56# Project Context7Build and maintain the `.context/` directory — a set of markdown files that give any LLM (Claude, Cursor, Copilot, Windsurf, etc.) the background it needs to work effectively in this codebase. These files are tool-agnostic. Agent-specific files like CLAUDE.md or .cursorrules reference them.89## Current context10- Repo: !`basename $(git rev-parse --show-toplevel)`11- Root: !`git rev-parse --show-toplevel`12- Existing context: !`ls .context/ 2>/dev/null || echo "no .context/ directory"`1314## Decision tree15- What are you doing?16 - **Creating context for a new project** (no `.context/` exists) -> follow "Initial setup" below17 - **Updating existing context** (`.context/` exists) -> follow "Audit and update" below18 - **Adding context for a specific area** (user asks about one topic) -> follow "Single document" below19 - **User says the AI doesn't understand their project** -> run "Audit and update" to find gaps, then fill them2021## Initial setup2223### 1. Analyze the project24Run these to understand the codebase:2526- `ls` the root and major directories to understand structure27- Read `package.json`, `Cargo.toml`, `go.mod`, `pyproject.toml`, or equivalent for dependencies28- Read existing docs: README, CONTRIBUTING, CLAUDE.md, .cursorrules29- `git log --oneline -20` for recent activity and commit style30- Glob for config files: `**/*.config.*`, `**/tsconfig*`, `biome.json`, `.eslintrc*`, etc.3132### 2. Recommend a context plan33Based on analysis, recommend which documents the project needs. Every project gets `overview.md`. The rest depend on complexity:3435|Document|When to include|What it covers|36|---|---|---|37|`overview.md`|Always|Architecture, module boundaries, data flow, key decisions|38|`conventions.md`|Projects with >5 files|Coding standards, naming, error handling, file organization|39|`glossary.md`|Domain-heavy projects|Business terms, entity definitions, domain relationships|40|`dependencies.md`|Projects with >3 external deps|Key deps, why chosen, how configured, what for|41|`<dirname>.md`|Major subdirectories (src/, api/, lib/, etc.)|Subdirectory-specific architecture and conventions|4243Present the plan as a checklist and get user confirmation before generating.4445### 3. Generate documents46For each document in the plan:47481. Read the relevant code thoroughly — don't guess, read the actual files492. Write the document following the format in `references/document-formats.md`503. Write it to `.context/<name>.md`5152Generate `overview.md` first since other documents reference it.5354### 4. Wire up agent files55After generating `.context/`, suggest additions to agent-specific files:5657- **CLAUDE.md**: add `See .context/ for project architecture, conventions, and domain knowledge.`58- **.cursorrules**: add equivalent pointer59- **AGENTS.md**: add equivalent pointer6061Don't overwrite existing content — append the pointer or suggest where to add it.6263## Audit and update6465### 1. Diff analysis66Compare the current `.context/` files against the actual codebase:67681. Read each `.context/*.md` file692. Scan the codebase for changes since the context was written — new directories, changed dependencies, new patterns703. Identify: **stale** (info contradicts current code), **missing** (new areas with no context), **accurate** (still correct)7172### 2. Report73Present a table:7475```text76| File | Status | What changed |77|---|---|---|78| overview.md | Stale | New api/ module added, auth rewritten |79| conventions.md | Accurate | — |80| glossary.md | Missing terms | "workspace" and "tenant" used but undefined |81```8283### 3. Update84For each stale or missing item:85861. Read the relevant current code872. Update the `.context/` file with accurate information883. Show the diff of what changed8990## Single document91When the user asks for a specific document:92931. Determine which document type from the table in "Initial setup"942. Analyze the relevant part of the codebase953. Write the document following `references/document-formats.md`964. If `.context/` doesn't exist yet, create it and also generate `overview.md` as a baseline9798## Writing principles99Context documents serve LLMs, not humans. This changes how you write:100101- **Be explicit about relationships** — "OrderService calls PaymentGateway.charge() which calls Stripe" is better than "OrderService handles payments"102- **Name the files** — "authentication logic lives in `src/auth/` with the main entry point at `src/auth/index.ts`" beats "the auth module"103- **State the non-obvious** — skip things any LLM can infer from reading the code (function signatures, import paths). Focus on *why* decisions were made and *how* modules interact104- **Keep it current or delete it** — wrong context is worse than no context. If something is stale and you can't verify it, remove it rather than leaving potentially wrong information105106## Key references107|File|What it covers|108|---|---|109|`references/document-formats.md`|Templates and structure for each document type|