Adaptive docs extract

From divad12/dotfiles · View interactive version

Adaptive docs extract is an AI agent skill from the GitHub repository divad12/dotfiles. Use when the user says 'extract docs', 'split AGENTS.md', 'split CLAUDE.md', 'refactor the docs', 'slim AGENTS.md', or has sprawling root instructions to break up.

How to use this skill

Skill file

Adaptive Docs - Extract

Refactor an existing project's AGENTS.md (and/or CLAUDE.md) into the three-layer adaptive docs system: slim root + on-demand docs/ai/ references + auto-activating skills + nested AGENTS.md guardrails.

This is a consultant skill - it doesn't blindly extract. It interviews the user about which topics deserve their own file, which directories warrant guardrails, and which need skill triggers.

AGENTS.md is treated as the primary root file (agent-agnostic universal standard). CLAUDE.md, if it exists, is for Claude Code-specific additions only.

Prerequisites

Run /adaptive-docs-init first if the structure isn't in place:

test -d docs/ai && test -L .claude/skills && test -f docs/ai/writing-docs.md

If any of those is missing, run init before proceeding.

Steps

1. Read the current root files

Read whichever exist at the project root:

Note their length and structure. If they both exist with near-identical content, flag this as a consolidation opportunity: the universal rules belong in AGENTS.md, and CLAUDE.md should either be deleted (if no Claude-specific content remains) or slimmed to just the Claude-specific parts.

If the root files are under ~100 lines each and well-organized, tell the user there may not be much to extract. Confirm before proceeding.

2. Identify candidate topics

Read through the root file(s) and group content into topics. A topic is a coherent area where 3+ paragraphs (or one substantial section) cluster around a single concern. Common candidates:

| Topic | Often worth extracting if... |

|-------|------------------------------|

| Testing | There are TDD rules, framework choice, test patterns, fixtures |

| API patterns | There are auth patterns, route handler conventions, error handling |

| Data model | There's schema info, relationships, validation rules |

| Forms / dialogs | There are form-specific conventions or UX rules |

| UI components | There are visual standards, design system rules, component patterns |

| State management | There are caching, optimistic update, or sync patterns |

| Git workflow | There are branch/rebase/PR conventions |

| Domain glossary | There's product-specific terminology that recurs |

| Build / deploy | There are deployment-specific rules or environment notes |

| Code review | There are review-specific checklists or rules |

For each potential topic, decide:

3. Confirm the extraction plan with the user

Present the plan using the AskUserQuestion tool. For each candidate, ask:

"I see content about {{topic}}. Should this become docs/ai/{{filename}}.md?"

Options:

For larger refactors, batch related questions into a single AskUserQuestion call.

Also ask:

4. For each approved extraction

For each topic the user approves:

  1. Create docs/ai/{{topic}}.md with the banner header at the top:

```markdown

> IMPORTANT: Before reading, check if you already read this file earlier in this session. If yes, skip the read and announce "Context already loaded: {{topic}}.md (re-using from earlier)". If no, read it and announce "Context loaded: {{topic}}.md".

# {{Topic Title}}

{{extracted content here}}

```

  1. Remove the extracted content from the root files (AGENTS.md and CLAUDE.md if duplicated).
  1. Add a row to the reference table in AGENTS.md (and CLAUDE.md if it has its own table):

```markdown

| Working on... | Read |

| {{when this applies}} | docs/ai/{{topic}}.md |

```

  1. Update the file tables in docs/ai/README.md and docs/ai/writing-docs.md.

5. Propose skills (optional per topic)

For each new doc, ask: "Should this auto-activate via a skill?"

A skill makes sense when:

A skill doesn't make sense when:

For each approved skill, copy ~/.claude/templates/adaptive-docs/skill-template/SKILL.md.template to .agents/skills/{{skill-name}}/SKILL.md. Replace placeholders:

Then add a row to the skill table in docs/ai/writing-docs.md.

6. Propose nested AGENTS.md files

After all docs are extracted, scan the project for high-stakes directories that might warrant guardrails. Common candidates:

For each candidate, ask: "Add a nested AGENTS.md guardrail here?"

Nested AGENTS.md should be under 10 lines and state the rule + why. Example:

# {{Directory}} Guardrails

- Auth check first in every route handler
- Use {{ORM}} for queries, never raw SQL
- Read `docs/ai/api-patterns.md` before editing

Add each created file to the "Nested AGENTS.md" table in docs/ai/writing-docs.md.

7. Slim the root files

After extraction:

Root AGENTS.md should:

Root CLAUDE.md (if it exists) should:

If AGENTS.md is still over 100 lines after extraction, ask the user which sections might still be split or compressed.

8. Consolidate if CLAUDE.md and AGENTS.md duplicate each other

If both files exist and contain near-identical universal rules:

```markdown

# {{PROJECT}} - Claude Code config

See AGENTS.md for universal instructions.

```

Ask the user which they prefer before deleting.

9. Verify and report

Run a final pass:

wc -l AGENTS.md CLAUDE.md docs/ai/*.md 2>/dev/null
ls .agents/skills/

Report:

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.