Optimize a codebase for agent readability: documentation structure, domain organization, discoverability, and knowledge capture. Use when agents struggle to find relevant code, when tribal knowledge lives outside the repo, when onboarding an agent to an existing codebase, or when restructuring docs for agent workflows. Use this skill whenever the user wants to make their codebase easier for agents to navigate or understand. Part of the harness engineering workflow; start with `harness-audit` for overall assessment.
Make a codebase navigable and understandable by coding agents.
Anything not in the repo doesn't exist for the agent. Slack threads, wiki pages, onboarding docs, architecture diagrams in Figma — none of it is accessible. If it matters for making correct decisions, it must be in the repo in a format the agent can read.
Evaluate the codebase by answering these questions:
Good: src/payments/refund.py → clear domain, clear purpose
Bad: src/utils/helpers2.py → what domain? what purpose?
Good: docs/api/authentication.md → findable by topic
Bad: docs/notes.md → findable by... luck
Check whether directory names map to domains and file names describe their contents.
An agent joining this codebase should be able to answer:
If the answers require reading dozens of files or asking a human, the conventions aren't discoverable.
Organize docs by domain, not by document type:
docs/
├── architecture.md # Module boundaries, dependency graph, domain map
├── api/
│ ├── authentication.md # Auth patterns, token handling
│ ├── endpoints.md # Endpoint conventions, request/response formats
│ └── errors.md # Error handling, status codes
├── data/
│ ├── models.md # Schema conventions, migration process
│ └── queries.md # Query patterns, indexing strategy
└── ops/
├── deployment.md # Deploy process, environment configs
└── monitoring.md # Alerts, dashboards, runbooks
Each doc should be self-contained for its domain. An agent reading docs/api/authentication.md should learn everything it needs to implement auth correctly without reading other files.
Create a single docs/architecture.md that serves as the agent's map:
## Module Map
| Directory | Domain | Owner | Key Files |
|---|---|---|---|
| src/api/ | HTTP layer | Platform team | routes.py, middleware.py |
| src/payments/ | Payment processing | Payments team | service.py, stripe.py |
| src/workers/ | Background jobs | Platform team | scheduler.py, tasks/ |
| src/models/ | Data layer | Shared | user.py, order.py |
## Dependency Direction
api → payments → models
api → workers → models
payments ✗→ api (never import api from payments)
## Key Decisions
- All external API calls go through src/clients/ (never call APIs directly)
- Database access only through SQLAlchemy models (no raw SQL)
- Background jobs must be idempotent
Reference this from the root instruction file.
Common sources of tribal knowledge to bring into the repo:
| External Source | Capture As |
|---|---|
| "We always do X when..." | Directive in instruction file or per-directory doc |
| Architecture decisions | ADR (Architecture Decision Record) in docs/decisions/ |
| Onboarding guide | docs/architecture.md + per-domain docs |
| Incident learnings | Constraints in relevant domain docs |
| Code review norms | Conventions in instruction file or linter rules |
Write each as a directive, not a story. "Use optimistic locking for concurrent order updates" not "After the incident in Q3 where two users modified the same order..."
Agents navigate by reading directory listings and file names. Optimize for scanning:
src/services/.payment_refund.py over refund.py if it's in a generic directory.README.md in complex directories explaining what's there and how files relate.src/api/users.py defines user endpoints, src/api/orders.py should define order endpoints — not src/api/order_management.py.Use linters to enforce architectural rules that agents (and humans) might violate:
See verification-harness for implementation details.
After restructuring, test with a fresh agent session:
If the agent still struggles, the documentation isn't providing what it needs — revise based on what it looked for but couldn't find.
harness-audit — assess legibility gaps as part of a broader harness evaluationwrite-agent-instructions — legibility and instruction quality go hand in hand