Generate, audit, and compress AI-optimized documentation for codebases. This skill applies research-backed principles from three peer-reviewed papers to create documentation that maximizes AI agent performance instead of degrading it. Use this skill whenever the user asks to "write docs", "create a CLAUDE.md", "document a module", "audit documentation", "compress docs", "optimize docs for AI", "write module docs", "create domain documentation", "review doc quality", or mentions documentation bloat, token waste, or AI context efficiency. Also trigger when the user references "ai-docs principles", "telegram style docs", or wants to apply the "Lost in the Middle", "Less is More", or "AGENTS.md" research findings.
69
85%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
You write documentation that makes AI agents smarter, not dumber.
Before writing or auditing any documentation, internalize these research-backed principles:
Law 1 — Minimal Context (ETH Zurich, 2026): Extensive context reduces AI success 3%, increases cost 20%+. Write only what code can't convey.
Law 2 — Zero Redundancy (Yang et al., 2024): 25-40% of docs are redundant; removing them maintains or improves quality. Delete any sentence the agent can infer from function names, types, or code structure.
Law 3 — Position-Aware Structure (Stanford/Berkeley, 2024): LLMs have U-shaped attention — strong recall at start and end, catastrophic loss in the middle. Place critical constraints at the END. Keep docs short enough that there is no "middle."
For the full research details, read references/research-foundations.md.
| Pattern | Example | Why It's Harmful |
|---|---|---|
| File inventory | src/models/user.py — User model | ls shows this |
| Type narration | "Takes a UUID and returns Optional[Lead]" | The signature says this |
| Framework tutorials | "FastAPI uses Depends() for injection" | Agent already knows FastAPI |
| Auto-generated trees | Full directory tree dumps | Law 1: −3% success rate |
| Architecture novels | 500-line design documents | Law 3: middle is ignored |
| Obvious comments | "# Initialize the database" above db = init_db() | Law 2: pure redundancy |
| Enum explanations | "COLD means the lead is cold" | Redundant by definition |
Determine which mode the user needs:
Read the actual code first. List the module directory, read key files (models, services, routers). Understand the domain from source code, not existing docs.
Identify what's non-inferable:
Apply the templates. Read references/templates.md and use the appropriate template:
Structure for attention:
Self-audit before delivering. Delete every line matching any Anti-Patterns entry above.
Read the documentation file(s).
Score each section against the three laws:
Produce an audit report:
## Audit: {filename}
Lines: {count} (target: < {80|100|150})
Redundancy: {X}% of content is inferable from code
Position: {Critical rules at end? Y/N}
### Lines to Remove
- L{n}: "{quoted text}" — Reason: {restates types | explains standard pattern | file inventory}
### Lines to Add (Missing Non-Inferables)
- {Business rule or edge case discovered in code but not documented}
### Structural Issues
- {Position problems, missing critical-rules-last section, too long, etc.}Read the document and the code it describes.
Apply the Anti-Patterns filter to each line. Also ask:
Restructure the survivor content:
Report: "Compressed from {X} to {Y} lines ({Z}% reduction)"
Scan the module structure: ls backend/src/modules/ and ls frontend/src/features/
For each module, read 2-3 key files (main model, main service, main router) to understand its purpose.
Create an INDEX.md with one line per module — just name and one-phrase purpose.
Identify which modules need dedicated docs based on complexity:
Before delivering any documentation, verify:
caa08df
Also appears in
since Aug 28, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.