Analyze repository structure and generate standardized AGENTS.md files that serve as contributor guides for AI agents. Supports both single-repo and monorepo structures...
This skill enables the agent to generate AGENTS.md files that serve as contributor guides for AI agents working on a codebase.
AGENTS.md documentAGENTS.md, preserving user-defined custom sectionsFor single repositories or individual packages in a monorepo:
For the root of a monorepo structure:
AGENTS.md from scratch (default when no AGENTS.md exists)AGENTS.md while preserving custom sections. See ./references/update_strategy.md for detailed workflow and section matching rules.The agent automatically selects the appropriate mode based on whether an AGENTS.md file already exists at the target location.
Supports three modes: All (root + all packages, default), Root Only, and Single Package. See ./references/monorepo_strategy.md for detailed strategy and mode selection criteria.
Run these steps in order. Each step has a fixed output that the next step depends on; skipping ahead produces wrong character budgets, unmatched update sections, or missed monorepo packages. The bundled scripts under ./scripts/ make the deterministic steps reproducible — invoke them rather than re-deriving the logic each run.
Check whether AGENTS.md exists at the target location. Present → Update. Absent → Generate.
Run monorepo detection at the repo root:
python ./scripts/detect_monorepo.py <repo_root>
Output: {is_monorepo, markers}. If is_monorepo is true, choose All / Root Only / Single Package per ./references/monorepo_strategy.md. Otherwise treat the repo as a single document.
For each target document (single repo, or root + each package), run:
python ./scripts/loc_to_limit.py <target_directory>
Output: {loc, scale, character_limit}. If the script reports tokei is missing, surface its install message and stop — do not estimate LOC by hand. Allocate character_limit across sections using the proportions in ./references/loc_measurement.md (Section Budget Allocation).
Before pattern/convention analysis, read the package manifests at the document's scope (root or per package) per ./references/read_only_commands.md > Dependency Discovery. Skip lock files. Use this stack context to focus Step 4 on relevant frameworks rather than searching blindly.
Run the multi-phase analysis defined in ./references/agents_md_template.md:
If Serena MCP is available, prefer its read-only symbol tools (find_symbol, find_referencing_symbols, get_symbols_overview, etc.) over rg / grep / find — symbolic queries are more accurate for caller tracing and cross-layer flows. See ./references/read_only_commands.md#symbol-level-analysis-optional-requires-serena-mcp.
Run this analysis in the current context only. Do not delegate to subagents — Phase 3 cross-pattern validation and section-level budget tracking require a unified view (see Scope Boundaries > Single-Context Execution).
Stay within each section's character budget from Step 2. Document only patterns/conventions actually observed.
Generate: Emit the document using the structure in ./references/agents_md_template.md (5 sections for single repo / package, 3 for monorepo root). Use ./references/working_agreements.md for the Working Agreements section.
Update: Run the section parser on the existing file:
python ./scripts/parse_sections.py <path/to/AGENTS.md> --doc-type single_repo
(Use --doc-type monorepo_root for the monorepo root document.) The output marks each ## heading as is_standard (managed) or not (preserved). Replace only the standard sections' bodies; keep custom sections, the file title, and any preamble before the first ## unchanged. Insert any missing_standard heading at its numbered position relative to other standard sections. Full reassembly rules: ./references/update_strategy.md.
If the existing document type no longer matches the repo (e.g., a single repo became a monorepo), force full regeneration instead of update.
Before writing, confirm:
character_limit; no section exceeds its budget.Keep edits minimal, Minimal changes, preserve public APIs, existing plugin behavior, or avoid unnecessary abstraction; custom sections may keep any user-owned wording.Then write with the Edit/Write tool. For Monorepo with mode = All, repeat Steps 2–6 per target package after handling the root.
This skill uses the following read-only tools for repository analysis. See ./references/read_only_commands.md for detailed usage patterns.
find_symbol, find_referencing_symbols, find_referencing_code_snippets, get_symbols_overview, search_for_pattern, list_dir, find_file, read_file. Prefer these over rg / grep / find for symbol lookups, caller tracing, and structural analysis. Use only the read-only tools listed; do NOT invoke write/edit symbol tools or execute_shell_command. See ./references/read_only_commands.md#symbol-level-analysis-optional-requires-serena-mcp.tokei: LOC measurement (required)rg (ripgrep): Content search (fallback when Serena MCP is unavailable)grep / Select-String: Content search (fallback per OS, when neither Serena nor rg is available)sed -n / Get-Content \| Select-Object: Paginated file reading per OStree: Directory structure visualizationfind: File and directory discovery (Linux / macOS, fallback when Serena find_file is unavailable)ls, pwd: Basic directory navigationDeterministic steps are bundled as scripts under ./scripts/ so they run identically across invocations and platforms. Prefer these over re-deriving the logic in natural language.
scripts/loc_to_limit.py: Runs tokei with the prescribed exclusions, parses the Total row, and returns {loc, scale, character_limit}. Surfaces the install message and exits non-zero if tokei is missing.scripts/detect_monorepo.py: Checks marker files (pnpm-workspace.yaml, lerna.json, nx.json, turbo.json, rush.json, .moon/workspace.yml, go.work, Cargo.toml [workspace], package.json workspaces, Gradle settings.gradle*, Maven pom.xml <modules>, Bazel, Buck2, Pants, Hatch/uv/rye). Returns {is_monorepo, markers}.scripts/parse_sections.py: For Update mode. Parses an existing AGENTS.md and returns a section map flagging which ## headings are standard (managed) vs custom (preserved), plus any missing standard headings.pnpm-lock.yaml, package-lock.json, yarn.lock, etc.) are outside analysis scopeAgent / Task tool, Explore, general-purpose, or any delegated agent) at any step. AGENTS.md generation requires a unified view of the repository: accumulated stack context (Step 3), per-section character budgets (Step 2), Phase 3 validation across 3+ locations, and Update-mode byte-for-byte preservation of custom sections all depend on a single context. Splitting work across subagents loses this state and produces inconsistent or budget-violating output. A parent agent invoking this skill is fine — the skill's internal execution must stay in one context.