Generate hierarchical AGENTS.md structure for codebases to optimize AI agent token usage...
Create a hierarchical AGENTS.md system for codebases that enables AI coding agents to work efficiently with minimal token usage. Generates lightweight root documentation with detailed sub-folder guidance following the "nearest-wins" principle.
Follow these phases in order. See references/generation-process.md for complete details.
Analyze the codebase:
Output: Structured map of the repository before generating any files.
Root must be lightweight: ~100-200 lines maximum, universal guidance only. Acts as index and navigation hub. Agents read the closest AGENTS.md to the file being edited โ sub-folder files override root (nearest-wins).
Create root file with these sections:
Example Implementation Rules:
## Implementation Rules
Before adding ANY external dependency (gems, npm packages, GitHub Actions, Docker images, APIs, CDN links):
- Use WebSearch to verify the latest stable version BEFORE implementation
- Never trust training data for version numbers
Example JIT Index:
## JIT Index (what to open, not what to paste)
### Package Structure
- Web UI: `apps/web/` -> [see apps/web/AGENTS.md](apps/web/AGENTS.md)
- API: `apps/api/` -> [see apps/api/AGENTS.md](apps/api/AGENTS.md)
- Shared packages: `packages/**/` -> [see packages/README.md]
### Quick Find Commands
- Search function: `rg -n "functionName" apps/** packages/**`
- Find component: `rg -n "export.*ComponentName" apps/web/src`
- Find API routes: `rg -n "export const (GET|POST)" apps/api`
Example Development Workflow:
## Development Workflow
- Before coding -> describe approach -> wait for approval
- Ambiguous requirements -> ask first
- If task touches >3 files -> decompose first
- After coding -> list breakage risks + suggest tests
- Bug fix -> write failing test -> fix until green
- When corrected -> add lesson to .agents/lessons/
Sub-folders have MORE detail than root โ specific patterns, technology-specific conventions, real file examples from the codebase.
For EACH major package/directory, create detailed AGENTS.md:
Key: Patterns & Conventions must include real file paths with DO/DON'T examples.
Adapt templates for specific package types (Design System, Database, API, Testing). See references/generation-process.md for specialized templates.
AGENTS.md # Root (lightweight)
apps/
web/AGENTS.md # Frontend details
api/AGENTS.md # Backend details
packages/
ui/AGENTS.md # Design system details
shared/AGENTS.md # Shared code details
AGENTS.md # Root (can be more detailed)
src/
components/AGENTS.md # Component patterns
services/AGENTS.md # Service patterns
Update AGENTS.md when: