--- description: Audit and improve AGENTS.md files in repositories. Use when user asks to check, audit, update, improve, or fix AGENTS.md files. Scans for all AGENTS.md files, evaluates quality, outputs quality report, then makes targeted updates. agent: build --- Audit, evaluate, and improve AGENTS.md files across a codebase to ensure opencode has optimal project context. **This skill can write to AGENTS.md files.** After presenting a quality report and getting user approval, it updates AGENTS.md files with targeted improvements. ## Understanding AGENTS.md AGENTS.md is opencode's equivalent to Cursor rules. It contains custom instructions that customize opencode's behavior for a specific project. **File Types & Locations:** | Type | Location | Purpose | | ---------------- | ------------------------------ | ---------------------------------------------------------- | | Project root | `./AGENTS.md` | Primary project rules (committed to git, shared with team) | | Fallback | `./CLAUDE.md` | Used if no AGENTS.md exists | | Global | `~/.config/opencode/AGENTS.md` | User-wide rules across all projects | | Package-specific | `./packages/*/AGENTS.md` | Module-level rules in monorepos | ## Workflow ### Phase 1: Discovery Find all AGENTS.md files in the repository: ```bash ls -la AGENTS.md .agents.md CLAUDE.md 2>/dev/null find . -maxdepth 3 -name "AGENTS.md" -o -name ".agents.md" 2>/dev/null | head -20 ls ~/.config/opencode/AGENTS.md 2>/dev/null ``` ### Phase 2: Quality Assessment For each AGENTS.md file, evaluate against quality criteria. **Quick Assessment Checklist:** | Criterion | Weight | Check | | ----------------------------- | ------ | ---------------------------------------- | | Project structure documented | High | Is directory layout explained? | | Commands/workflows documented | High | Are build/test/dev commands present? | | Code standards specified | Medium | Are conventions documented? | | External references | Medium | Uses `@file.md` references properly? | | Conciseness | Medium | No verbose explanations or obvious info? | | Currency | Medium | Does it reflect current codebase state? | **Quality Scores:** - **A (90-100)**: Comprehensive, current, actionable - **B (70-89)**: Good coverage, minor gaps - **C (50-69)**: Basic info, missing key sections - **D (30-49)**: Sparse or outdated - **F (0-29)**: Missing or severely outdated ### Phase 3: Quality Report Output **ALWAYS output the quality report BEFORE making any updates.** Format: ``` ## AGENTS.md Quality Report ### Summary - Files found: X - Average score: X/100 - Files needing update: X ### File-by-File Assessment #### 1. ./AGENTS.md (Project Root) **Score: XX/100 (Grade: X)** | Criterion | Score | Notes | |-----------|-------|-------| | Project structure | X/20 | ... | | Commands/workflows | X/20 | ... | | Code standards | X/15 | ... | | External references | X/15 | ... | | Conciseness | X/15 | ... | | Currency | X/15 | ... | **Issues:** - [List specific problems] **Recommended additions:** - [List what should be added] #### 2. ./packages/api/AGENTS.md (Package-specific) ... ``` ### Phase 4: Targeted Updates After outputting the quality report, ask user for confirmation before updating. **Update Guidelines (Critical):** 1. **Propose targeted additions only** - Focus on genuinely useful info: - Commands or workflows discovered during analysis - Gotchas or non-obvious patterns found in code - Package relationships that weren't clear - Testing approaches that work - Configuration quirks 2. **Keep it minimal** - Avoid: - Restating what's obvious from the code - Generic best practices already covered - One-off fixes unlikely to recur - Verbose explanations when a one-liner suffices 3. **Show diffs** - For each change, show: - Which AGENTS.md file to update - The specific addition (as a diff or quoted block) - Brief explanation of why this helps future sessions ### Phase 5: Apply Updates After user approval, apply changes using the Edit tool. Preserve existing content structure. ## AGENTS.md Templates ### Recommended Sections Use only the sections relevant to the project. ### Project Structure Document the directory layout so opencode understands where things live. ```markdown ## Project Structure ### Source code src/ ### Test files tests/ ### Build/utility scripts scripts/ build/ ### Configuration files config/ ``` ### Commands Document essential commands for working with the project. ```markdown ## Commands | Command | Description | | --------------- | ------------------------ | | `npm install` | Install dependencies | | `npm run dev` | Start development server | | `npm run build` | Production build | | `npm test` | Run tests | ``` ### Code Standards Document project-specific coding conventions. ```markdown ## Code Standards - Use TypeScript with strict mode - Prefer `const` over `let` - Use ES modules with explicit imports ``` ### Environment Document required environment variables and setup. ```markdown ## Environment Required: - `DATABASE_URL` - PostgreSQL connection string - `API_KEY` - Third-party API key Setup: - Copy `.env.example` to `.env` - Run `npm run db:migrate` ``` ### Gotchas Document non-obvious patterns, quirks, and warnings. ```markdown ## Gotchas - Tests must run with `--runInBand` due to shared database state - Import order matters - utils must be imported before components - Environment variables must be prefixed with `NEXT_PUBLIC_` for client access ``` ### External References Document external files that opencode should load using `@path` syntax. ```markdown ## External References For TypeScript guidelines: @docs/typescript-guidelines.md For React patterns: @docs/react-patterns.md ``` ## Common Issues to Flag 1. **Stale commands**: Build commands that no longer work 2. **Missing commands**: No build/test/dev commands documented 3. **Outdated architecture**: File structure that's changed 4. **Missing environment setup**: Required env vars not documented 5. **Generic advice**: Not specific to the project 6. **No external refs**: Should use `@file.md` for modular rules ## User Tips to Share When presenting recommendations, remind users: - **Use `/init` command**: Run `/init` in opencode to auto-generate AGENTS.md - **Keep it concise**: AGENTS.md should be human-readable; dense is better than verbose - **Actionable commands**: All documented commands should be copy-paste ready - **Commit to git**: Project AGENTS.md should be version controlled - **Global rules**: Put personal rules in `~/.config/opencode/AGENTS.md` - **External references**: Use `@path/to/file.md` syntax for lazy loading ## What Makes a Great AGENTS.md **Key principles:** - Concise and human-readable - Actionable commands that can be copy-pasted - Project-specific rules, not generic advice - Non-obvious gotchas and warnings **Recommended sections** (use only what's relevant): - Project Structure (directory layout) - Commands (build, test, dev, lint) - Code Standards (conventions) - Environment (required vars, setup) - Gotchas (quirks, common mistakes) - External References (@file.md links)