| 1 | # Editing Agent Instructions |
| 2 | |
| 3 | > Read this before modifying `AGENTS.md` or any guide it links to. |
| 4 | |
| 5 | ## Token Budget Mindset |
| 6 | |
| 7 | `AGENTS.md` loads on every agent request; domain guides load on entry to a relevant area. |
| 8 | Keep `AGENTS.md` under **200 lines** and each domain guide under **300 lines**. |
| 9 | When a file exceeds its budget, split or prune — do not compress prose to fit. |
| 10 | |
| 11 | ## When NOT to Add Content |
| 12 | |
| 13 | Before writing a new rule, ask whether it is actually needed: |
| 14 | |
| 15 | - **Agents already do it.** Test with a prompt first. If the agent behaves correctly without the rule, don't add it. |
| 16 | - **One-off incident.** Prefer a code-level fix (lint rule, CI check, test assertion) over a new doc rule. |
| 17 | - **Hardcoded paths.** File paths change; use "search for X" patterns instead. |
| 18 | - **Upstream docs.** Don't reproduce pytest, ruff, or other tool docs — link to them. |
| 19 | - **Contradicts an existing rule.** Search all linked guides before adding. If two rules conflict, consolidate into one. |
| 20 | - **Already covered elsewhere.** Search `AGENTS.md` and every linked guide for overlapping guidance. |
| 21 | |
| 22 | If any of the above apply, **do not add the content**. |
| 23 | |
| 24 | ## Where Content Belongs |
| 25 | |
| 26 | The goal is a lean `AGENTS.md` plus rich domain guides that teach agents what they can't learn from the code alone. |
| 27 | |
| 28 | | Scope | File | |
| 29 | | ----- | ---- | |
| 30 | | Project-wide invariants (contribution policy, env setup, test/lint commands, commit conventions) | `AGENTS.md` | |
| 31 | | Area-specific knowledge (model patterns, format details, deprecation timelines) | Domain guide | |
| 32 | |
| 33 | **Rules of thumb:** |
| 34 | |
| 35 | - If it only matters for one area, put it in a domain guide. |
| 36 | - If it matters for all areas, consider `AGENTS.md` — but first verify agents don't already do it. |
| 37 | - Create a new domain guide when you have 5 or more non-obvious instructions sharing a coherent scope. |
| 38 | |
| 39 | ## What Makes a Good Domain Guide |
| 40 | |
| 41 | Add what agents can't infer from the code or public docs: project-specific |
| 42 | conventions that differ from standard patterns, correct approaches that require |
| 43 | cross-file context, and fixes for repeated mistakes. |
| 44 | Each entry should be short, specific, and actionable — e.g., which files to |
| 45 | touch, what order to change them in, and which tests to run. |
| 46 | |
| 47 | ## Keeping Docs Lean |
| 48 | |
| 49 | - Every addition should trigger review of surrounding content for stale or redundant items. |
| 50 | - Prefer examples over explanations — a 3-line snippet beats a paragraph of prose. |
| 51 | - Merge related bullets into one principle instead of listing variants. |
| 52 | - Use `search for X` instead of hardcoded file paths. |
| 53 | - PR references are fine in domain guides for traceability, but avoid them in `AGENTS.md`. |
| 54 | |
| 55 | ## Anti-Patterns |
| 56 | |
| 57 | | Pattern | Problem | |
| 58 | | ------- | ------- | |
| 59 | | Reactive accumulation | Adding a rule per incident without pruning leads to bloat | |
| 60 | | Copy-paste between guides | Duplicated content drifts apart; keep in one place, link from the other | |
| 61 | | Imperative walls | Long DO NOT lists that agents skim past; consolidate into principles | |
| 62 | | Config snapshots | Show the command to get the value, not the value itself | |
| 63 | |
| 64 | ## Change Checklist |
| 65 | |
| 66 | Before submitting changes to any agent instruction file: |
| 67 | |
| 68 | - [ ] **Non-obvious?** Would an agent do the wrong thing without this rule? |
| 69 | - [ ] **No conflicts?** Searched all linked guides for contradictions? |
| 70 | - [ ] **Right file?** Project-wide goes in `AGENTS.md`, area-specific in a domain guide? |
| 71 | - [ ] **Offset the addition?** Removed or consolidated something to compensate? |
| 72 | - [ ] **Under budget?** `AGENTS.md` < 200 lines, domain guides < 300 lines? |
| 73 | - [ ] **No hardcoded paths?** Uses "search for X" where paths may change? |
| 74 | - [ ] **Tested?** Verified that an agent actually follows the new instruction? |