/claude-md — generate & maintain agent rules
Write a high-quality agent-rules file using a hybrid model and an idempotent managed block, so it works on new and existing projects and is safe to re-run.
Design (read first)
<canonical agent file> ← CLAUDE.md (default) OR AGENTS.md (when canonical)
## Project … (tailored preamble — scan/interview; written once, then user-owned)
<!-- CC-RULES:START --> ← managed by this skill; regen rewrites ONLY this block
## Working Discipline (Karpathy)
## Verification (Anthropic best-practice)
## Parallel Git Workflow (adaptive: team / solo / none)
## Self-Learning Rules (grows via /learn; PRESERVED across regen)
<!-- CC-RULES:END -->
… anything below/around the block is the user's free area — never touched
- Idempotent. The block is upserted between the markers. Re-running replaces only that region; everything else (incl. an OMC
<!-- OMC:START --> block or hand-written sections) is left byte-identical.
- Self-learning preserved. Rules accumulated under
<!-- LEARN:ANCHOR --> survive regeneration (the helper carries them over).
- One block, one file. The block lives in exactly ONE canonical file; never split or duplicated across CLAUDE.md and AGENTS.md.
Target resolution (which file gets the block)
The rules are tool-agnostic, so they belong in the file every agent on this repo reads. Detect the canonical file:
CLAUDE.md is a symlink (readlink CLAUDE.md) → resolve it; the target is the real file (usually AGENTS.md). One physical file — done.
CLAUDE.md imports @AGENTS.md (a line that is exactly @AGENTS.md), or AGENTS.md self-declares canonical → the repo is multi-tool (e.g. Claude + Codex). Target = AGENTS.md so Codex/others also get the rules.
- Only
AGENTS.md exists (no CLAUDE.md) → Target = AGENTS.md. Do not create a redundant CLAUDE.md.
- Otherwise → Target =
CLAUDE.md (default, Claude-native).
Confirm before writing to AGENTS.md. Whenever the target is AGENTS.md (cases 2–3), state it and get a yes first — agent-config has a large blast radius:
Detected @AGENTS.md import → AGENTS.md is the canonical agent file (Codex reads it too). I'll put the managed block in AGENTS.md and keep CLAUDE.md as the pointer. OK?
For the plain CLAUDE.md-only case, no confirmation is needed.
Note: recent Claude Code may read AGENTS.md natively. If so, a @AGENTS.md import in CLAUDE.md double-loads it — consider a symlink or dropping the import. Mention this; don't change their structure without asking.
Procedure
- Find the project root (
git rev-parse --show-toplevel, fallback cwd) and resolve the target per the rules above (confirm if AGENTS.md).
- Detect environment for the adaptive git section:
- git?
git rev-parse --is-inside-work-tree
- remote + GitHub?
git remote -v, gh repo view / gh auth status (treat failure as "no gh")
- team if a remote exists and
gh works; solo if git but no usable remote/gh; none if not a git repo. --team / --solo flags override.
- Language = English by default;
--ko → Korean prose. (Match the target file's existing language when obvious.)
- Remove any stale block from the OTHER file. If the target is AGENTS.md but a
CC-RULES block already exists in CLAUDE.md (or vice-versa), delete it from the non-canonical file first so the block never lives in two places:node "${CLAUDE_PLUGIN_ROOT}/scripts/apply-block.mjs" --remove <root>/CLAUDE.md
- Tailored preamble (only if the target file does NOT already exist):
- Scan for stack & commands:
package.json scripts, Makefile, pyproject.toml, Cargo.toml, go.mod, README, lockfiles, test/build config.
- Optionally ask 1–2 short questions only for facts you cannot infer. Don't ask what the repo already tells you.
Write a minimal preamble: a one-line project description + a ## Project section with build / test / run commands.
- If the target file already exists, do not rewrite the preamble — go straight to the block.
- Compose the managed block body from the template below, choosing the matching Parallel Git Workflow variant and translating prose if
--ko. Keep <!-- LEARN:ANCHOR --> exactly as written.
- Upsert the block idempotently:
node "${CLAUDE_PLUGIN_ROOT}/scripts/apply-block.mjs" <target file> <<'BLOCK'
…composed block body…
BLOCK
- Verify & report: show the resulting block, confirm pre-existing content is intact, and note that re-running is safe. Offer to commit (don't commit without approval).
Managed block body — template
Render this between the markers. Pick ONE Parallel Git Workflow variant. --ko translates the prose; keep headings/markers/anchor verbatim.
## Working Discipline
- **Think before coding.** State assumptions; if uncertain, ask. Surface tradeoffs and competing interpretations instead of silently picking one.
- **Simplicity first.** Write the minimum code that solves the stated problem. No speculative features, abstractions, or configuration for single-use code.
- **Surgical changes.** Touch only what the task requires. Don't refactor or reformat adjacent code; match the existing style. Remove only what your change made unused.
- **Goal-driven.** Define a concrete success check (test / build / command / screenshot) before coding, then loop until it passes.
## Verification
- Always give yourself a way to verify — a test, a bash command, a curl, a screenshot. A working feedback loop is the single biggest quality lever.
- Report honestly: if a check fails, say so with the output; mark unverified work "unverified". Never present incomplete work as done.
## Parallel Git Workflow
<!-- variant: TEAM (git + remote + gh) -->
- Never work on or commit to the default branch (`main`/`master`). **One task = one ISSUE = one branch.**
- **Create the branch/worktree BEFORE you start editing — not at commit time.** Isolate each task in its own **git worktree** (`git worktree add ../<task> -b <branch>`), or use your agent's native worktree support — **Claude Code provides worktrees** — so parallel sessions never share a checkout and never collide on `main`.
- Open small, surgical PRs that reference the issue (e.g. "Fixes #42"); keep one concern per PR.
- If cc-handoff is installed: **one branch = one handoff** (`docs/handoff/<branch>.md`).
<!-- variant: SOLO (git, no remote/gh) — use instead of TEAM -->
- Don't work on or commit to the default branch. **Create a branch/worktree per task BEFORE editing — not at commit time** (`git switch -c <task>`, or `git worktree add ../<task> -b <task>`; **Claude Code provides native worktrees** for isolation).
- Commit in small, focused steps with the *why* in the body. (No PR ceremony needed for a solo repo.)
<!-- variant: NONE (not a git repo) — replace section body with this single line -->
- Not a git repo yet — run `git init` to enable branch/worktree isolation for parallel sessions.
## Self-Learning Rules
<!-- Append one concise rule per correction. `/learn` writes here automatically; newest first. -->
<!-- LEARN:ANCHOR -->
Notes
- The block uses distinct markers (
CC-RULES), so it never collides with an OMC (OMC:START) block in the same file.
- Keep the block lean — it's guidance, not documentation. Project-specific detail belongs in the preamble or the user's free area.
/learn is the companion that grows the Self-Learning Rules; it writes to the same canonical file this skill chose.
1---2name: claude-md3description: Generate or refresh a project's agent rules — a tailored preamble plus an idempotent managed block (working discipline, verification, adaptive parallel-git workflow, self-learning rules). Writes to the repo's canonical agent file (CLAUDE.md by default, or AGENTS.md when it is canonical, e.g. CLAUDE.md imports @AGENTS.md). Works on new and existing projects; only ever rewrites its own managed block. Use when setting up a repo, standardizing AI working rules, or adopting the parallel-git + self-learning workflow.4---56# /claude-md — generate & maintain agent rules78Write a high-quality agent-rules file using a **hybrid** model and an **idempotent managed block**, so it works on new *and* existing projects and is safe to re-run.910## Design (read first)1112```13<canonical agent file> ← CLAUDE.md (default) OR AGENTS.md (when canonical)14## Project … (tailored preamble — scan/interview; written once, then user-owned)1516<!-- CC-RULES:START --> ← managed by this skill; regen rewrites ONLY this block17## Working Discipline (Karpathy)18## Verification (Anthropic best-practice)19## Parallel Git Workflow (adaptive: team / solo / none)20## Self-Learning Rules (grows via /learn; PRESERVED across regen)21<!-- CC-RULES:END -->2223… anything below/around the block is the user's free area — never touched24```2526- **Idempotent.** The block is upserted between the markers. Re-running replaces only that region; everything else (incl. an OMC `<!-- OMC:START -->` block or hand-written sections) is left byte-identical.27- **Self-learning preserved.** Rules accumulated under `<!-- LEARN:ANCHOR -->` survive regeneration (the helper carries them over).28- **One block, one file.** The block lives in exactly ONE canonical file; never split or duplicated across CLAUDE.md and AGENTS.md.2930## Target resolution (which file gets the block)3132The rules are tool-agnostic, so they belong in the file every agent on this repo reads. Detect the canonical file:33341. **`CLAUDE.md` is a symlink** (`readlink CLAUDE.md`) → resolve it; the target is the real file (usually `AGENTS.md`). One physical file — done.352. **`CLAUDE.md` imports `@AGENTS.md`** (a line that is exactly `@AGENTS.md`), or **`AGENTS.md` self-declares canonical** → the repo is multi-tool (e.g. Claude + Codex). **Target = `AGENTS.md`** so Codex/others also get the rules.363. **Only `AGENTS.md` exists** (no `CLAUDE.md`) → Target = `AGENTS.md`. Do not create a redundant CLAUDE.md.374. **Otherwise** → Target = `CLAUDE.md` (default, Claude-native).3839**Confirm before writing to AGENTS.md.** Whenever the target is `AGENTS.md` (cases 2–3), state it and get a yes first — agent-config has a large blast radius:4041> Detected `@AGENTS.md` import → AGENTS.md is the canonical agent file (Codex reads it too). I'll put the managed block in **AGENTS.md** and keep CLAUDE.md as the pointer. OK?4243For the plain CLAUDE.md-only case, no confirmation is needed.4445> Note: recent Claude Code may read `AGENTS.md` natively. If so, a `@AGENTS.md` import in CLAUDE.md double-loads it — consider a symlink or dropping the import. Mention this; don't change their structure without asking.4647## Procedure48491. **Find the project root** (`git rev-parse --show-toplevel`, fallback cwd) and **resolve the target** per the rules above (confirm if AGENTS.md).502. **Detect environment** for the adaptive git section:51 - git? `git rev-parse --is-inside-work-tree`52 - remote + GitHub? `git remote -v`, `gh repo view` / `gh auth status` (treat failure as "no gh")53 - **team** if a remote exists and `gh` works; **solo** if git but no usable remote/gh; **none** if not a git repo. `--team` / `--solo` flags override.54 - Language = English by default; `--ko` → Korean prose. (Match the target file's existing language when obvious.)553. **Remove any stale block from the OTHER file.** If the target is AGENTS.md but a `CC-RULES` block already exists in CLAUDE.md (or vice-versa), delete it from the non-canonical file first so the block never lives in two places:56 ```sh57 node "${CLAUDE_PLUGIN_ROOT}/scripts/apply-block.mjs" --remove <root>/CLAUDE.md58 ```594. **Tailored preamble (only if the target file does NOT already exist):**60 - Scan for stack & commands: `package.json` scripts, `Makefile`, `pyproject.toml`, `Cargo.toml`, `go.mod`, README, lockfiles, test/build config.61 - Optionally ask 1–2 short questions only for facts you cannot infer. Don't ask what the repo already tells you.62 - `Write` a minimal preamble: a one-line project description + a `## Project` section with **build / test / run** commands.63 - If the target file already exists, **do not** rewrite the preamble — go straight to the block.645. **Compose the managed block body** from the template below, choosing the matching Parallel Git Workflow variant and translating prose if `--ko`. Keep `<!-- LEARN:ANCHOR -->` exactly as written.656. **Upsert the block idempotently:**66 ```sh67 node "${CLAUDE_PLUGIN_ROOT}/scripts/apply-block.mjs" <target file> <<'BLOCK'68 …composed block body…69 BLOCK70 ```717. **Verify & report:** show the resulting block, confirm pre-existing content is intact, and note that re-running is safe. Offer to commit (don't commit without approval).7273## Managed block body — template7475> Render this between the markers. Pick ONE Parallel Git Workflow variant. `--ko` translates the prose; keep headings/markers/anchor verbatim.7677```markdown78## Working Discipline79- **Think before coding.** State assumptions; if uncertain, ask. Surface tradeoffs and competing interpretations instead of silently picking one.80- **Simplicity first.** Write the minimum code that solves the stated problem. No speculative features, abstractions, or configuration for single-use code.81- **Surgical changes.** Touch only what the task requires. Don't refactor or reformat adjacent code; match the existing style. Remove only what your change made unused.82- **Goal-driven.** Define a concrete success check (test / build / command / screenshot) before coding, then loop until it passes.8384## Verification85- Always give yourself a way to verify — a test, a bash command, a curl, a screenshot. A working feedback loop is the single biggest quality lever.86- Report honestly: if a check fails, say so with the output; mark unverified work "unverified". Never present incomplete work as done.8788## Parallel Git Workflow89<!-- variant: TEAM (git + remote + gh) -->90- Never work on or commit to the default branch (`main`/`master`). **One task = one ISSUE = one branch.**91- **Create the branch/worktree BEFORE you start editing — not at commit time.** Isolate each task in its own **git worktree** (`git worktree add ../<task> -b <branch>`), or use your agent's native worktree support — **Claude Code provides worktrees** — so parallel sessions never share a checkout and never collide on `main`.92- Open small, surgical PRs that reference the issue (e.g. "Fixes #42"); keep one concern per PR.93- If cc-handoff is installed: **one branch = one handoff** (`docs/handoff/<branch>.md`).9495<!-- variant: SOLO (git, no remote/gh) — use instead of TEAM -->96- Don't work on or commit to the default branch. **Create a branch/worktree per task BEFORE editing — not at commit time** (`git switch -c <task>`, or `git worktree add ../<task> -b <task>`; **Claude Code provides native worktrees** for isolation).97- Commit in small, focused steps with the *why* in the body. (No PR ceremony needed for a solo repo.)9899<!-- variant: NONE (not a git repo) — replace section body with this single line -->100- Not a git repo yet — run `git init` to enable branch/worktree isolation for parallel sessions.101102## Self-Learning Rules103<!-- Append one concise rule per correction. `/learn` writes here automatically; newest first. -->104<!-- LEARN:ANCHOR -->105```106107## Notes108109- The block uses distinct markers (`CC-RULES`), so it never collides with an OMC (`OMC:START`) block in the same file.110- Keep the block lean — it's guidance, not documentation. Project-specific detail belongs in the preamble or the user's free area.111- `/learn` is the companion that grows the Self-Learning Rules; it writes to the same canonical file this skill chose.