Agent Code: Directory Context Documentation
You write directory-level context documentation — the CLAUDE.md + README.md pair that provides context to humans and AI assistants entering a source code directory.
User Input
$ARGUMENTS
Context Loading
Read .context/README.md (if exists)
- Extract from top-level: Objectives, Constraints, Key Terms
- Use these to inform CLAUDE.md content (e.g., if Constraints mention compliance requirements, note those in the directory's CLAUDE.md)
Accept target directory from the user via $ARGUMENTS
Principles
- Deep-read, don't skim. Read every file in the target directory — full implementations, not just signatures.
- Apply the content test. For every candidate fact: "Would an AI assistant working in this directory make a mistake or waste time without knowing this?" Yes → CLAUDE.md. No but useful → README.md.
- Separate concerns. CLAUDE.md is the grab-and-go cheat sheet. README.md is the structured reference. Never duplicate content between them.
- No empty sections. Only include README.md sections that have content.
- Verify against source. Every file name, path, env var, service name must be confirmed by reading the actual code.
Process
Accept target directory from the user
Read every file in the directory (and immediate subdirectories if relevant). Read full content — trace function calls, identify external service wrappers, find env var reads, spot validation constraints.
Identify grab-and-go facts by scanning for these categories:
ultrathink — False negatives in CLAUDE.md are costly — an AI assistant that doesn't know a critical constraint will violate it. Apply the content test rigorously across all categories below.
- Service identity — which client, SDK, or API does this wrap?
- IAM requirement — which policy or permissions are needed?
- Required env vars — what must be set for the code to run?
- Input constraints — what validation rules produce cryptic errors?
- Consistency model — eventual vs immediate, caching behavior?
- Auth mechanism — how does identity flow through the code?
- Critical rules — what's easy to violate?
- Project patterns — conventions from
CLAUDE.md if present, or evident in the surrounding code, that apply to this directory
Discover doc locations dynamically — check for developer-docs directories. Do not hardcode paths.
Write CLAUDE.md following the template below
Write README.md following the template below
Validate using the checklist below
CLAUDE.md Template
# {directory-path}/
{One sentence: what lives here and its role in the system.}
{Optional second sentence: key technology or wrapper target.}
- {Fact: the thing you'd get wrong — wrong service name, wrong import}
- {Fact: the constraint that causes a runtime error — regex, env var, type}
- {Fact: the behavioral surprise — eventual consistency, missing API, side effect}
See README.md for {what the README covers}.
Rules:
- H1 header uses the directory path relative to the project root
- 3-8 lines of content (excluding H1). Maximum 10.
- Each bullet is a fact that prevents a mistake, not background information
- End with a pointer to README.md that names what it covers
README.md Template
Include only sections that have content.
# {Title}
{1-2 sentence description of what this directory contains and its purpose.}
## Contents
| File/Directory | Purpose |
|----------------|---------|
| `file.py` | Brief description |
## {Domain-Specific Section}
(Varies by directory type: routes table, API mapping, concepts, data flow)
## Known Quirks
(Hard-won debugging knowledge. Things that work differently than expected.)
## Environment Variables
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
## Integration Points
(How this code connects to the rest of the system.)
## Related
- See [CLAUDE.md](./CLAUDE.md) for conventions.
Rules:
- Use tables for structured data
- Use prose for narrative
- "Known Quirks" is highest-value when wrapping external services
Validation Checklist
Scope
This skill applies to any codebase. It does NOT:
- Write docstrings
- Write published documentation site pages
- Decide whether a directory needs context docs — the user activates this skill
1---2name: ai-context3description: Write agent context documentation (CLAUDE.md + README.md) for a source code directory. Invoke ONLY via the /ai-context slash command. Do not activate from intent, keywords, or near-synonyms — slash incantation is required.4---56# Agent Code: Directory Context Documentation78You write directory-level context documentation — the CLAUDE.md + README.md pair that provides context to humans and AI assistants entering a source code directory.910## User Input1112```text13$ARGUMENTS14```1516## Context Loading17181. Read `.context/README.md` (if exists)19 - Extract from top-level: Objectives, Constraints, Key Terms20 - Use these to inform CLAUDE.md content (e.g., if Constraints mention compliance requirements, note those in the directory's CLAUDE.md)21222. Accept target directory from the user via `$ARGUMENTS`2324## Principles25261. **Deep-read, don't skim.** Read every file in the target directory — full implementations, not just signatures.272. **Apply the content test.** For every candidate fact: "Would an AI assistant working in this directory make a mistake or waste time without knowing this?" Yes → CLAUDE.md. No but useful → README.md.283. **Separate concerns.** CLAUDE.md is the grab-and-go cheat sheet. README.md is the structured reference. Never duplicate content between them.294. **No empty sections.** Only include README.md sections that have content.305. **Verify against source.** Every file name, path, env var, service name must be confirmed by reading the actual code.3132## Process33341. **Accept target directory** from the user352. **Read every file** in the directory (and immediate subdirectories if relevant). Read full content — trace function calls, identify external service wrappers, find env var reads, spot validation constraints.363. **Identify grab-and-go facts** by scanning for these categories:3738 **ultrathink** — False negatives in CLAUDE.md are costly — an AI assistant that doesn't know a critical constraint will violate it. Apply the content test rigorously across all categories below.3940 - Service identity — which client, SDK, or API does this wrap?41 - IAM requirement — which policy or permissions are needed?42 - Required env vars — what must be set for the code to run?43 - Input constraints — what validation rules produce cryptic errors?44 - Consistency model — eventual vs immediate, caching behavior?45 - Auth mechanism — how does identity flow through the code?46 - Critical rules — what's easy to violate?47 - Project patterns — conventions from `CLAUDE.md` if present, or evident in the surrounding code, that apply to this directory484. **Discover doc locations dynamically** — check for developer-docs directories. Do not hardcode paths.495. **Write CLAUDE.md** following the template below506. **Write README.md** following the template below517. **Validate** using the checklist below5253## CLAUDE.md Template5455```markdown56# {directory-path}/5758{One sentence: what lives here and its role in the system.}59{Optional second sentence: key technology or wrapper target.}6061- {Fact: the thing you'd get wrong — wrong service name, wrong import}62- {Fact: the constraint that causes a runtime error — regex, env var, type}63- {Fact: the behavioral surprise — eventual consistency, missing API, side effect}6465See README.md for {what the README covers}.66```6768Rules:69- H1 header uses the directory path relative to the project root70- 3-8 lines of content (excluding H1). Maximum 10.71- Each bullet is a fact that prevents a mistake, not background information72- End with a pointer to README.md that names what it covers7374## README.md Template7576Include only sections that have content.7778```markdown79# {Title}8081{1-2 sentence description of what this directory contains and its purpose.}8283## Contents8485| File/Directory | Purpose |86|----------------|---------|87| `file.py` | Brief description |8889## {Domain-Specific Section}9091(Varies by directory type: routes table, API mapping, concepts, data flow)9293## Known Quirks9495(Hard-won debugging knowledge. Things that work differently than expected.)9697## Environment Variables9899| Variable | Required | Default | Description |100|----------|----------|---------|-------------|101102## Integration Points103104(How this code connects to the rest of the system.)105106## Related107108- See [CLAUDE.md](./CLAUDE.md) for conventions.109```110111Rules:112- Use tables for structured data113- Use prose for narrative114- "Known Quirks" is highest-value when wrapping external services115116## Validation Checklist117118- [ ] CLAUDE.md is under 10 lines of content (excluding H1)119- [ ] CLAUDE.md contains only facts that prevent mistakes120- [ ] README.md is scannable in under 2 minutes121- [ ] README.md has no empty sections122- [ ] All file names match actual files in the directory123- [ ] All import paths are correct124- [ ] All env var names match what the code actually reads125- [ ] No content in CLAUDE.md that belongs in README.md126- [ ] CLAUDE.md pointer to README.md names specific content127128## Scope129130This skill applies to any codebase. It does NOT:131- Write docstrings132- Write published documentation site pages133- Decide whether a directory needs context docs — the user activates this skill