From product-shaping
Generate an AGENTS.md onboarding document for AI coding agents working in this repository. Inspects the repo (package manifest, README, scripts, lint/test config, layout, commit history) and writes a concise contributor guide titled "Repository Guidelines". Use when the user invokes /shape-agents-md, asks to "create AGENTS.md", "write an agent onboarding doc", "generate contributor guide for agents", or similar. The output is optimized to be small, precise, reference-heavy, and ordered with critical rules at the top — so a future agent reads it once and stays unblocked.
How this skill is triggered — by the user, by Claude, or both
Slash command
/product-shaping:shape-agents-mdThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Produce an `AGENTS.md` that serves as an onboarding document for AI coding agents in this repository. The file is short, specific to the repo, and structured so the most important rules appear first.
Produce an AGENTS.md that serves as an onboarding document for AI coding agents in this repository. The file is short, specific to the repo, and structured so the most important rules appear first.
$ARGUMENTS is optional. It may be:
AGENTS.md at the repo root.AGENTS.md inside that directory (useful for nested per-area guides, e.g. src/api/AGENTS.md)..md → write there verbatim.If the target file already exists, do not silently overwrite. Switch to the update flow under "Procedure → Update path". The default behavior is a surgical edit that preserves still-valid content, not a rewrite.
The same skill can produce two materially different documents depending on where it's invoked from. Detect the scope before discovery so the draft targets the right altitude.
$ARGUMENTS names a path, that's the target. Otherwise it's the current working directory (pwd).git rev-parse --show-toplevel. If the target directory equals the repo root → repo-level scope. If it's a subdirectory (e.g. src/components/, packages/api/src/routes/, app/api/) → directory-level scope.Repo-level scope. Follow the procedure and "Output structure" below as written — the document is a high-level onboarding guide (project structure, build commands, CI gate, commit conventions, etc.).
Directory-level scope. Drop the repository-onboarding framing entirely. The reader already knows the repo; they need the rules of this directory. Reorient discovery and output:
index.*/mod.rs/__init__.py, co-located tests, the parent directory's README if any, and any nested config (e.g. tsconfig.json, .eslintrc, route manifests) that overrides repo-level defaults. Only consult repo-root docs (README.md, CLAUDE.md) to resolve conflicts or pull a single canonical @-reference — not as the primary source.PascalCase.tsx, kebab-case.ts, *.handler.ts), default vs. named exports, prop/argument conventions, where types/styles/tests live relative to the unit, error-handling idioms, what gets imported from where. The AGENTS.md captures the convention you observed, not generic advice.@./<sibling-file>.src/server/"), accessibility or i18n rules visible in siblings.AGENTS.md. If the reader needs them, link once: See @AGENTS.md at the repo root for repo-wide rules.The Quality guards still apply, with one substitution: guard 5 ("Critical rules first") becomes "Local rules first" — the highest-leverage line is the one that prevents a wrong-shaped sibling from landing in this directory.
Whenever the procedure says "ask the user", use whichever interactive-question tool the host agent exposes. The skill is host-agnostic; do not hard-code one tool name. Known equivalents (non-exhaustive):
AskUserQuestionask_questionrequest_user_inputSelf-discovery rule. Before the first interactive step, scan your own available tools for one matching the patterns above (names containing ask, question, input, prompt_user, etc., with a question or prompt parameter and an options/choices field). Use the first match. If none is available, fall back to a plain conversational message asking the user to reply with one of the labelled options — do not block the procedure.
State which tool you selected (or that you fell back to plain chat) the first time you ask a question, so the user can correct you if there's a better option.
If the host exposes a subagent / task-spawn tool, the discovery and diff steps parallelize cleanly — they're mostly independent reads. Known equivalents (non-exhaustive):
Agent (with Explore/general-purpose subagent types)Self-discovery rule. Before kicking off discovery, check whether such a tool exists. If it does, fan out the independent reads in one batched call (multiple subagents in a single message, not sequentially):
README.md, CLAUDE.md, existing AGENTS.md, top-level docs/ index;LAST_TOUCH).Each subagent should return a short structured report (≤200 words: facts only, with path:line citations) — not a full file dump. The main agent then synthesizes the AGENTS.md from those reports.
When not to use subagents. Skip the fan-out if:
Do not delegate the synthesis step (drafting and Quality-guard checks). Drafting requires holding the full picture in one context to enforce the 200–400 word budget, ordering, and @-reference policy.
@-references to canonical files instead (e.g. @package.json, @tsconfig.json, @docs/architecture.md).CONTEXT_ROOT and exclude context/ from gitBefore reading or writing anything under context/, apply the context-root protocol documented in ../shape-init/references/context-root-protocol.md (or invoke /shape-init via the Skill tool, which runs the same protocol as its Step 0). The protocol does two things in one block:
CONTEXT_ROOT — the directory context/ lives in. Inside a git repo, that's the parent of git rev-parse --git-common-dir (the main working tree of the repo, even when invoked from a worktree). Outside a git repo, it's the cwd. Anywhere this skill's instructions say context/foo/bar.md, treat it as $CONTEXT_ROOT/context/foo/bar.md.context/ from git — appends one line to <git-common-dir>/info/exclude (repo-local, untracked, never committed, shared by every worktree of the same repo). Idempotent: skipped if context/ is already excluded.Why this skill cares about the worktree case: if the user has a layout like ~/Projects/kibana (main) plus ~/Projects/kibana.worktrees/feature-a, ~/Projects/kibana.worktrees/feature-b, etc., they don't want to re-init each worktree. The protocol resolves CONTEXT_ROOT to ~/Projects/kibana from any of those locations — so /shape-prd writes the same prd.md regardless of which worktree it ran from, and the git-exclude line is set once for the whole repo.
Why this skill cares about the exclude case: when the user is running this command from inside a shared repository they don't own (kibana, an upstream monorepo), the artifact this skill writes under context/ is a personal working note. It must never be staged, committed, or pushed by accident. The exclusion lives only in the user's clone (in info/exclude, never in .gitignore) and cannot leak upstream.
The protocol is idempotent and safe — if context/ is already excluded, this is a no-op. If you are not inside a git repo at all, CONTEXT_ROOT is just the cwd and there is no exclude to write. Surface a one-line git-exclude: <state> in this skill's final summary, plus a context-root: <path> line when CONTEXT_ROOT differs from cwd (so the user knows their notes are in the shared, worktree-spanning location).
Do not edit .gitignore. /shape-init mode=gitignore is the only path that touches the tracked .gitignore, and only when the user explicitly opted in.
First, branch on existence. Before discovering anything else, check whether the resolved target path already exists (use Read or ls). If it does, follow the Update path below. If not, follow the Create path.
README.md, CLAUDE.md, existing AGENTS.md, top-level docs/ index.package.json (scripts, workspaces, engines), or pyproject.toml / Cargo.toml / go.mod / Gemfile / equivalent..eslintrc*, oxlint*, biome.json, tsconfig.json, ruff.toml, .editorconfig.vitest.config.*, jest.config.*, pytest.ini, playwright.config.*, *.test.* locations..github/workflows/* (one or two files; just enough to know the gate).ls/find-bounded), workspace package list if monorepo.git log --oneline -n 30 to learn commit-message conventions; git config remote.origin.url for PR target.Write call to the resolved path. Confirm the path and word count back to the user.Triggered when the target file already exists. The default is a surgical edit: keep what's still true, fix what's stale, fill what's missing, and remove what's been deleted from the repo. Do not rewrite from scratch unless the user asks.
Inventory the existing file.
Read the full file.@-reference and every relative path or filename it cites.Date the file via git.
git log --follow --format="%h %ad %s" --date=short -- <path> — full edit history of the file.LAST_TOUCH.git ls-files --error-unmatch <path> fails), treat it as freshly authored: skip git-diff steps and run the full Create path discovery, but still preserve any obviously project-specific content the user wrote.Diff repo state since LAST_TOUCH. Use these checks (skip any whose target the file doesn't reference):
git diff --stat LAST_TOUCH..HEAD -- README.md CLAUDE.md docs/ — has top-level documentation moved or changed?git diff LAST_TOUCH..HEAD -- package.json pyproject.toml Cargo.toml go.mod (whichever exists) — for scripts, dependencies, engines, workspaces. Pay closest attention to the scripts block: renamed/added/removed scripts are the most common source of stale AGENTS.md content.git diff LAST_TOUCH..HEAD -- .eslintrc* oxlint* biome.json tsconfig.json ruff.toml .editorconfig — has the lint/format/type toolchain changed?git diff LAST_TOUCH..HEAD -- vitest.config.* jest.config.* pytest.ini playwright.config.* — has the test stack or layout changed?git diff --stat LAST_TOUCH..HEAD -- .github/workflows/ — has the CI gate changed?git log --oneline LAST_TOUCH..HEAD -- <commit-conventions-relevant-area> and git log --oneline -n 30 — does the commit-style observation in the file still match recent history?@-reference and path the file mentions: ls/Read the path. If it no longer exists or has been renamed, that line is stale.Classify each line of the existing file into one of four buckets:
git log).
Keep this classification as a short table you can show the user. Cite path:line (in the existing AGENTS.md) for every UPDATE/REMOVE entry, and cite the source-of-truth path (e.g. package.json:42) for every UPDATE/MISSING entry.Confirm scope before editing. Use the host's interactive-question tool once (see "Interactive prompts — host-agnostic" above) with these options:
Edit calls; KEEP lines are not touched.Edit surgically. For the "Apply" choice, prefer multiple small Edit calls (one per UPDATE/REMOVE/MISSING entry) over a single Write rewrite. This preserves authorial voice in KEEP sections and produces a reviewable diff. If section ordering violates the "critical rules first" guard from the Quality guards and the user approved updates, you may move whole sections — but only sections, never re-author rule wording silently.
Re-run the Quality guards on the updated file. The same five gates apply. If a guard now fails because of the update (e.g. body grew past 400 words after MISSING additions), trim KEEP content that has become low-leverage rather than dropping the new MISSING content.
Report. Confirm path, new word count, and a one-line summary of what changed in each bucket (e.g. "3 updated, 1 removed, 2 added; section order unchanged").
The document title is # Repository Guidelines. Target length is 200–400 words of body content. Use Markdown headings for structure. Adapt sections to what the repo actually has — omit any section that would be empty or speculative.
Order sections by leverage to a fresh agent, not by tradition. Critical rules and the most-used commands go first; nice-to-know context goes last. A useful default ordering, when in doubt:
@path/to/doc.md instead of inlining them.pnpm <script> / make <target> / etc. over raw tool invocations when the project wraps them.git log (e.g. Conventional Commits prefixes seen), PR description expectations, required CI checks.@-reference) — 3–6 bullets max; otherwise link out.Open the file with one short paragraph (1–2 sentences) naming what the project is and the primary stack — enough that an agent landing in the repo for the first time has a frame. No mission statements, team intros, or values.
Write)Each guard is a hard gate. If any fails, revise the draft.
@path/to/file. Short single-line command examples (pnpm test, git rebase main) are fine.README.md / package.json / lint config, replace it with @README.md / @package.json / @.eslintrc.json.Professional, instructional, terse. Second person ("Run pnpm test before pushing") or imperative ("Place new handlers in src/api/<feature>/"). No marketing voice, no emojis, no decorative dividers.
Report to the user:
Do not propose follow-ups unless the user asks.
README.md and no manifest detected. Stop and tell the user the repo looks empty or unfamiliar; ask for a one-paragraph project description before drafting.AGENTS.md that lists packages and @-references each package's README, rather than duplicating per-package detail. Suggest nested packages/<name>/AGENTS.md for any package with rules that materially differ.CLAUDE.md in the repo. Treat it as authoritative source material. The new AGENTS.md should be a tighter, agent-tool-agnostic distillation that points back to @CLAUDE.md for depth, not a verbatim copy.AGENTS.md was edited by hand after its last commit. git diff HEAD -- <path> will show uncommitted changes. Read those changes first and treat them as KEEP unless they directly contradict a CI-enforced rule — the user is mid-edit and you must not clobber in-flight work.LAST_TOUCH is the initial commit of the repo. Diff range becomes LAST_TOUCH..HEAD with no useful signal. Fall back to inspecting current repo state vs. the file's claims, line by line, without the git-diff shortcut.git log empty). Skip the commit-conventions section rather than guessing; note in the PR section that the convention is to be defined.npx claudepluginhub patrykkopycinski/patryks-treadmill-claude-plugins --plugin product-shapingCreates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.