/ai-rules:rules-setupfrom ai-rules
Manages versioned sections of standing instructions in CLAUDE.md from a shared library. Adds, upgrades, changes, or removes sections with optional modules and settings.
Ships in ai-rules. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You manage sections of standing instructions in a CLAUDE.md file. Each section comes from the library in this skill's folder, has a version, and can have optional modules (parts the user turns on or off) and options (values such as a time zone). Installed sections sit between markers that record the version and the user's choices, so you can upgrade them later without losing the user's edits.
CRITICAL: This command takes no arguments. If the user typed anything after it, ignore it and gather all input with AskUserQuestion as described below.
Keep messages short. If the user cancels at any step, say "No changes made." and stop.
Every question has 2 to 4 options, and one call holds up to 4 questions. The user can always type their own answer through "Other".
${CLAUDE_SKILL_DIR}/library/catalog.json lists every section, its current version, every released version with a one-line note, its modules and its options. Each released version of a section is a template at ${CLAUDE_SKILL_DIR}/library/<section-id>/<version>.md.python3 --version, then python --version, then py -3 --version. Use the first that prints Python 3.8 or later. On Windows, python can be a stub that opens the Microsoft Store and prints nothing, so skip any command that doesn't print a version. If Python is found, use ${CLAUDE_SKILL_DIR}/scripts/rules.py for rendering and status. If not, work in manual mode: follow Rendering and Status by hand yourself.git --version. You use git diff --no-index for previews and git merge-file for upgrades of edited sections. Claude Code on Windows installs with Git for Windows, so git is normally there. Without git, compare and merge the text yourself, and show the diff as plain text.mktemp -d in Bash, New-Item -ItemType Directory (Join-Path $env:TEMP "rules-setup-<timestamp>") in PowerShell). Write every intermediate file there, never next to the target file.Ask:
~/.claude/CLAUDE.md, loaded in every project./CLAUDE.md, loaded in this project for everyone who clones itResolve the home folder with the first of these that returns a path: echo "$HOME" (macOS, Linux, WSL, Git Bash), $env:USERPROFILE (PowerShell), echo %USERPROFILE% (cmd). Forward slashes work in file paths on Windows.
If the file doesn't exist, ask "No CLAUDE.md at <path>. Create it?" with "Yes, create it" and "Cancel". On yes, treat it as empty.
Run <python> "${CLAUDE_SKILL_DIR}/scripts/rules.py" status "<path>", or follow Status by hand. The JSON has:
blocks: each installed section, with its state:
current: matches the library's current version.edited: the user changed the text. It is on the current version.upgrade: a newer version exists, and the text is unchanged.edited-upgrade: a newer version exists, and the user changed the text.kept: the user chose to keep their text over the newest version. The block won't be offered for upgrade again until a later version comes out.newer: the file was written by a newer version of this plugin. Leave the block alone, and tell the user to run /plugin marketplace update ai-agent-plugins and update ai-rules on this machine.unknown: the library has no section with this ID, for the same reason as newer, or because the section was removed. Offer only Remove for it.duplicate or broken: a marker problem.changes (the notes for each version after the installed one), new_modules (modules added since then) and new_options (options added since then that the block has no value for).unmanaged: library sections whose heading is in the file without markers, such as sections pasted by hand, with the lines each one covers (line to end_line).legacy: markers left by /workflow-rules, the ai-workflow skill this one replaces. Retired rules carry their replacement.available: sections not in the file at all.problems: marker errors.Show the user a short status table: each section's title, installed version, current version and state, plus a line for unmanaged sections and legacy rules. If problems is not empty, list them and stop. Tell the user to fix the markers by hand, or to delete the broken block, then run /rules-setup again. Never guess where a broken block ends.
If unmanaged or legacy is not empty, ask before the main menu:
On yes, run Adopt, then scan again before the menu.
Build the options from the scan, in this order, and leave out any that has nothing to act on:
upgrade or edited-upgradeavailablecurrent, edited, upgrade, edited-upgrade or keptA question holds 4 options, and "Done" must be one of them. When all four actions apply, which happens whenever "Upgrade" and "Add" both do, show one option "Change or remove sections" in place of "Change modules or options" and "Remove sections". The menu is then "Upgrade sections (recommended)", "Add sections", "Change or remove sections" and "Done". If the user picks "Change or remove sections", ask "Change or remove?" (Header: "Sections") with "Change modules or options" and "Remove sections", then run that flow.
If only "Done" would be left, say "Everything is current. Nothing to change." and stop.
Ask "What would you like to do?" (Header: "Rules setup"). After a flow finishes and the file is written, show the menu again from a fresh scan, until the user picks "Done".
groups in the catalog, used as the header), listing only sections in available. Each option's label is the section title, and its description is the section summary. Every section is a separate choice, so never add a whole group because the user picked one section in it. In the question for the t3 group, say that these sections need T3 Code.requires that are neither installed nor picked, such as Messages to other people, which needs Plain wording, ask whether to add the required section too. Recommend yes.render <id> --modules a,b --set key=value ... --markers).changes, one line per version, such as reply-format 1.0.0 → 1.1.0: Adds a rule for long-running PR watches.new_modules is not empty, ask whether to turn each one on. Recommend the catalog default. For each option in new_options, use the value another installed section already stores for the same option, such as t3. If no section stores one, ask for it as in Choose modules and options. Leave out a new module whose requires option is off.upgrade, render the current version with the stored modules and options plus the new choices, and replace the whole block, markers included.edited-upgrade, go to Edited sections.current or upgrade, replace it with the new rendering. If it is edited, edited-upgrade or kept, go to Edited sections, with the new choices as "theirs".unknown blocks in a question of their own, because they belong to no group, and a group's question can already hold 4 sections.requires one being removed, warn the user and ask whether to remove both or keep the required one.For each entry in unmanaged:
line through end_line in the scan. That runs from the heading up to the next # or ## heading, the next marker or the end of the file, and it ignores headings inside fenced code blocks, such as the sample replies in Reply format. In manual mode, find the same range yourself, and skip lines inside ``` or ~~~ fences.git diff --no-index between the rendering and the user's text.edited, and later upgrades merge new versions into it.For legacy markers from /workflow-rules:
pr-hygiene section. Build one pr-hygiene block at the position of the first legacy rule. Use the ## PR and Commit Hygiene heading, then each rule block's text in its current order, with its <!-- workflow-rules:id=... --> and <!-- /workflow-rules:id=... --> lines removed. The begin marker gets the current version, and modules lists the IDs found. If the text matches the rendering, it shows as current. Otherwise it shows as edited.## PR and Commit Hygiene heading. Also delete any other heading the move left with nothing under it, such as ## Scope Discipline or ## Communication Style from older versions.Then Preview and write once for everything adopted.
For each section, in catalog order:
t3, are asked once and stored in every section that has them.t3 (yes/no): recommend yes if this session has tools whose names start with mcp__t3-code__, which means it runs in T3 Code. Otherwise recommend no. Ask "Do you use T3 Code?", and say in the description that T3 Code is the app that renders collapsed panels and runs scheduled tasks and thread snoozing.timezone (text): detect the system time zone. On macOS run readlink /etc/localtime (the part after zoneinfo/). On Linux run timedatectl show -p Timezone --value, or read /etc/timezone. On Windows run powershell -NoProfile -Command "(Get-TimeZone).Id". Turn it into a short name people say, such as "US Eastern" for America/New_York or Eastern Standard Time, "US Pacific", "UK time" or "Central European". Offer that name (recommended) and "UTC".chrome (yes/no): recommend yes if this session has tools whose names start with mcp__claude-in-chrome__. Otherwise recommend no. Ask "Do you use Claude in Chrome?", and say in the description that Claude in Chrome is the browser extension that lets Claude work in your own browser, with your sign-ins.private-names (text, Public and private repos): ask only for the user CLAUDE.md. Offer "None (recommended)" and let the user type names through "Other", such as server names, deploy tools and private repos. In a project CLAUDE.md, don't ask, and leave it empty: that file is often committed, and in a public repo the names would become public. If the user wants names there, tell them to put the names in the user CLAUDE.md or in CLAUDE.local.md instead."" may stay empty, and an empty option turns off the text that uses it. Values can't contain a double quote.rules.py, quote it for the shell, such as --set 'company=Acme LLC'. Never put a value inside double quotes or backticks on the command line, because the shell could run part of it.requires options are on. For example, with t3 set to no, Reply format offers only Examples. Ask a multi-select question per section with each module's title and summary, and mark the defaults "(recommended)". A section with more than 4 modules gets "All (recommended)" / "Pick" first, then the split questions. A section with one module gets a yes/no question.The Code ownership section tells Claude where it works as the owner and where it works as a guest. Its options depend on each other, so ask about the user's setup, then set the options and modules from the answers. In Change, mark the stored answers "(recommended)". In Adopt, read the answers from the user's text instead of asking.
A project CLAUDE.md. The file loads only in this repo, so skip questions 2 and 3 and the worktrees question. Leave own-folder, accounts, guest-folder and worktree-folder empty, and turn guest and worktrees off. The section then says that this codebase is Claude's to own. First run git remote -v. If the repo has an upstream remote, or its origin belongs to someone else, tell the user that this looks like someone else's repo, and ask whether to go on.
The user CLAUDE.md. Ask these four questions in one call:
Then ask only for the values those answers need. Put them in one call where you can:
company: for "Me and my company", ask for the company's name as the user writes it. For "Only me", leave it empty.own-folder: for "By folder", ask which folder. Offer up to three folders that exist: the folder that holds this project's main repo (the first line of git worktree list), and any of ~/code, ~/dev, ~/Developer, ~/git, ~/projects, ~/repos, ~/src, ~/Source and ~/workspace. The user can type another one.accounts: for "By git remote", and for "Yes, next to my own repos", ask which accounts and organizations on the git host are the user's. Offer the owner in this project's origin URL (git remote get-url origin) if it has one. Store the answer as plain words, such as sam-lee and acme-inc on GitHub.guest-folder: for "Yes, in their own folder", ask which folder.a11y: the standard's name, or empty for "None".mcp__t3-code__ tools, if git worktree list prints more than one line, or if ~/.t3/worktrees exists. On yes, turn on the worktrees module. Set worktree-folder to the worktree folders you found or the user names, and leave it empty when there is no fixed folder.Set the rest from the answers:
| Answer | Options and modules |
|---|---|
| "By folder" | own-folder is set |
| "By git remote" | accounts is set, own-folder is empty |
| "Every repo is mine" | own-folder and accounts are empty |
| Other repos: "No" | guest is off, guest-folder is empty |
| Other repos: "Yes, in their own folder" | guest is on, guest-folder is set |
| Other repos: "Yes, next to my own repos" | guest is on, guest-folder is empty, accounts is set |
~ for the home folder and forward slashes. Join several folders with "and", such as ~/code/worktrees and ~/.t3/worktrees.Use this when a block's text differs from what its stored version and choices render, and a new rendering must replace it.
base.md: the block's installed version rendered with its stored modules and options.mine.md: the block's current text, between the markers.new.md: the new rendering, at the new version and with the new choices.git diff --no-index base.md mine.md), and the version notes.git merge-file -p mine.md base.md new.md and use its output. Exit code 0 means a clean merge. A positive exit code is the number of conflicts.new.md. The user's edits are lost, but the backup keeps them.v= at the installed version and add skip="<current version>" to the begin marker. On a change, ask again, because keeping the text would ignore the new choices.<<<<<<<, =======, >>>>>>>) into the target file.edited, which is correct.Change only the blocks the flow touches, plus the adopted text and legacy markers in Adopt. Keep every other line of the file exactly as it is.
Place a new block in catalog order among the managed blocks: just before the first managed block whose section comes later in the catalog. If there is none, place it just after the last managed block. If the file has no managed blocks, place it at the end of the file.
Leave exactly one blank line between a block and the text around it.
A begin marker looks like this, with modules in catalog order and options in catalog order:
<!-- ai-rules:begin id=reply-format v=1.1.0 modules="panels,snooze,examples" t3="yes" timezone="US Eastern" -->
## Reply format
...
<!-- ai-rules:end id=reply-format -->
rules.py render --markers writes this form. The section's ## heading is inside the markers. Everything outside the markers belongs to the user.
<scratch>/proposed.md.git diff --no-index -- "<target>" "<scratch>/proposed.md". If the diff is long, show the summary (--stat) and the hunks for sections you rendered, and say that unchanged library text is left out.<target>?" with "Yes, write them" and "Cancel".<home>/.claude/backups/ai-rules/<name>-<YYYYMMDD-HHMMSS>.md, where <name> is user-CLAUDE for the user file and <project folder>-CLAUDE for a project file. Create the folder if needed. Skip the backup only when the file didn't exist.current, or edited when the user kept or merged edits, or kept. If not, say what is wrong, and tell the user where the backup is./rules-setup shows new versions after /plugin marketplace update ai-agent-plugins.Rendering turns a template into section text. rules.py render does this. In manual mode, follow these rules exactly, so that the result matches what the script would produce:
{{#name}}...{{/name}} keeps its content when name is on. {{^name}}...{{/name}} keeps its content when name is off. {{name}} is replaced by the option's value. Sections can nest.modules list, or an option whose value is yes or any other text. An option with the value no, false, off or 0, or an empty value, is off.requires lists an option that is off is treated as off, even if the user picked it.{{#x}}, {{^x}} or {{/x}}) is removed along with its line break.Without Python, work out each block's state yourself:
<!-- ai-rules:begin ... --> line and its <!-- ai-rules:end id=<same id> --> line. Read id, v, modules, any skip and the option attributes.since in the catalog is later than the installed version doesn't exist in that version, so the block has no value for it.git diff --no-index --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol. Any remaining difference means edited.v with the section's current in the catalog to decide between current, edited, upgrade, edited-upgrade, kept (a skip at or above current) and newer (v above current).heading in the catalog) outside markers, and for <!-- workflow-rules:id=... --> markers. Ignore anything inside fenced code blocks, including markers.newer.~/.claude/CLAUDE.md without asking.The short-pr-bodies rule in the pr-hygiene section is adapted from file-pr in tstack by Theo Browne (MIT). See THIRD-PARTY-NOTICES.md.
agents/openai.yaml (opens in a new tab)library/catalog.json (opens in a new tab)library/claude-in-chrome/1.0.0.md (opens in a new tab)library/claude-in-chrome/1.1.0.md (opens in a new tab)library/code-ownership/1.0.0.md (opens in a new tab)library/estimates/1.0.0.md (opens in a new tab)library/ios-simulators/1.0.0.md (opens in a new tab)library/messages-to-others/1.0.0.md (opens in a new tab)library/personal-data/1.0.0.md (opens in a new tab)library/plain-wording/1.0.0.md (opens in a new tab)library/pr-hygiene/1.0.0.md (opens in a new tab)library/reply-format/1.0.0.md (opens in a new tab)library/reply-format/1.1.0.md (opens in a new tab)library/reply-format/1.2.0.md (opens in a new tab)library/repo-visibility/1.0.0.md (opens in a new tab)library/t3-context-handoff/1.0.0.md (opens in a new tab)library/t3-phase-threads/1.0.0.md (opens in a new tab)library/t3-phase-threads/1.1.0.md (opens in a new tab)library/t3-reviewer/1.0.0.md (opens in a new tab)library/t3-reviewer/1.1.0.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub charlesjones-dev/ai-agent-plugins --plugin ai-rules2 skills in this plugin
Other plugins' skills for the same job