/code-story:code-story [base <branch>] [story <link>] [stack|no stack] [uncommitted] [@spec] [ticket keys] [what to explain]from code-story
Builds or updates a code story: a chaptered artifact that explains how and why a code change works, sourced from a branch, PR, or PR stack.
Ships in code-story. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Request: $ARGUMENTS
A code story re-cuts a change into the stack of PRs it could have been, one chapter per mechanism, and explains why the code changed the way it did, for a reader new to the codebase. references/craft.md says how to write it. This file says how to run it.
Hard rules for the whole run:
Call mcp__code-story__config; when it is not loaded, look it up with tool search first. It returns:
languages (English first, plus at most one more);glossFirstUse;diagramSkill (null means the built-in diagrams);uncommitted (ignore | include | ask);stack (ask | always | never);warnings, to repeat in the final report.Without the tool, use languages: ["en"], glossFirstUse: true, diagramSkill: null, uncommitted: "ignore", stack: "ask", and say so in one report line.
The request overrides a setting for this run only:
stack and no stack decide the stack question;uncommitted includes uncommitted changes.Asking. Ask only through the question tool, and only when one is available. When you run as a subagent or have no way to ask, an ask setting takes its safe answer and the report says so:
Work in <scratchpad>/code-story/<branch>/, with every / in the branch name replaced by - (feat/x → feat-x): story.json, chapters/, diagrams/. Run git fetch origin --quiet first. Run every git, gh and node command from the repository root.
Base.
gh pr list --head <branch> --state open --json number,baseRefName,url).gh pr list --state open --json number,headRefName,isCrossRepository --jq "$SAFE_PRS", then git merge-base --is-ancestor 'origin/<head>' HEAD).Use origin/<base> whenever it exists; a stale local copy widens the range.
Branch names from other PRs. Anyone who can open a PR names its head, and a git branch name may hold ', $(…) and backticks. Every gh pr list that returns other PRs' names passes --jq "$SAFE_PRS" with SAFE_PRS='[.[] | select((.isCrossRepository | not) and (.headRefName | test("^[A-Za-z0-9._/-]+$")) and ((.baseRefName // "main") | test("^[A-Za-z0-9._/-]+$")))]', so a fork's PR (its head is never on origin) and any name with other characters never reach a command. Put the names that pass in single quotes, and name any PR the filter dropped in the report.
Stack. From the open PRs (gh pr list --state open --json number,title,headRefName,baseRefName,isCrossRepository --limit 200 --jq "$SAFE_PRS"), follow this branch's PR down while its base is another open PR's head, and up while another open PR has this branch as its base. A chain of two or more PRs is a stack:
stack setting never: tell only this branch.always: tell the whole stack.ask: ask once, naming the PRs. The answer counts for this run only.Whole stack. In story.json:
base: the bottom PR's base;head: origin/<top PR's head>;branch: the top branch;stack: the PR numbers bottom to top.Uncommitted changes. When git status --porcelain --untracked-files=no prints anything:
ignore: tell the committed change and list the files in the report.include: set "uncommitted": true (only when head is HEAD).ask: ask.Untracked files are never part of the story; say so when there are any.
Empty range. When git log --oneline <base>..<head> lists nothing, stop and say there is nothing to tell.
A story describes one branch, or one stack, and is updated in place under the same link. Look for an existing one, in this order:
## Code story section with a claude.ai link in this branch's PR body (gh pr view <n> --json body --jq .body).Read a candidate with the Artifact tool's read action and save the page locally. It is the same story when its code-story:repo and code-story:branch meta match, or, for a whole-stack story, when this branch's PR number is in its code-story:stack.
Update.
node ${CLAUDE_SKILL_DIR}/scripts/unpack.mjs <saved.html> <workdir>. This writes the old chapters, story.json, and previous.json holding the old meta. story.json keeps the old head; when this run's scope from step 2 differs (for example the top PR has merged), set head, base, branch, stack and pr again from step 2. When the stored story is a whole stack and this run tells one branch, start a new story instead of updating it.git diff --stat <previous head>..<head> and the new commits with the chapters.New story. With no candidate, start fresh. Do not search the Artifact gallery for one.
git log --format='%h %s%n%b' <base>..<head>, git diff --stat <base>...<head>, then the diff file by file. Skim lockfiles, generated code and snapshots; read their stat only.gh pr view <n> --json title,body,reviews,comments, gh api repos/{owner}/{repo}/pulls/<n>/comments);git show <base-sha>:<path>), and the unchanged or third-party code it leans on.Before writing HTML, list the chapters: one question each, in the order understanding has to build, with the files and line ranges each will show. A typical story has 4 to 8 chapters.
Read references/craft.md once. It holds the markup, the voice, the language rules and a worked chapter. Open references/example.html only when a choice is still unclear; it is long and uses the older single-language format.
Write one file per chapter, chapters/01.html, 02.html and so on, each holding one <article>. Write every story language in the same file, English first.
story.json:
{
"base": "origin/main",
"head": "HEAD",
"languages": ["en", "pl"],
"title": {"en": "…", "pl": "…"},
"pr": 4472,
"stack": [],
"uncommitted": false
}
For a language with no built-in labels in references/ui.json, add "ui": {"<lang>": {…every key of ui.json's "en"…}}.
When every chapter is written in every language, clean the prose: call anti-slop:anti-slop through the Skill tool in file mode, once per chapter file you wrote or rewrote in this run. Name the sources you read in step 4 (the diff range, the PR, tickets, specs) as source:, so its fidelity pass checks each why against them. It changes prose only; markup, <code>, diff and tree blocks stay byte for byte, and step 7's check catches anything it breaks.
diagramSkill is null: draw the diagrams yourself by diagrams/lite.md, inline in the chapter.diagrams/lite.md describes, and place its SVG files with <figure class="svg" data-src="diagrams/<name>.svg">. When the skill does not exist or fails, fall back to the built-in style and say so in the report.node ${CLAUDE_SKILL_DIR}/scripts/assemble.mjs <workdir>
It writes <workdir>/story.html, fills in what git knows (head SHA, base, repo, counts, labels, meta), and runs check.mjs:
Fix every ERROR in the chapter files and run it again. Read each warn and fix the ones that are real; an identifier missing from the second language usually means a code name got translated. Publish only after check passed.
Publish <workdir>/story.html with the Artifact tool:
icon: "book" and a one-sentence description;url, so the link stays the same.When the publish is refused because a newer version exists, merge onto the version it hands back and publish again.
Without the Artifact tool, open the file locally (open on macOS, xdg-open elsewhere) and report its path.
Say in a few lines:
ask answered by its safe default;A new Artifact is private: say that it needs sharing before the link goes into a PR. End with exactly one result line, the last line of the reply, which pr-open reads:
CODE_STORY url=<artifact url|none> status=<created|updated|local> head=<sha> base=<ref> languages=<en[,xx]> chapters=<n> path=<story.html path>
NOTICE.md (opens in a new tab)diagrams/lite.md (opens in a new tab)diagrams/templates/flow.svg (opens in a new tab)diagrams/templates/sequence.svg (opens in a new tab)diagrams/templates/state.svg (opens in a new tab)references/craft.md (opens in a new tab)references/example.html (opens in a new tab)references/template.html (opens in a new tab)references/ui.json (opens in a new tab)scripts/assemble.mjs (opens in a new tab)scripts/check.mjs (opens in a new tab)scripts/parse-story.mjs (opens in a new tab)scripts/unpack.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub grixu/cc-toolkit --plugin code-storyOther plugins' skills for the same job