Skip to content

Generate a Runbook from Scattered Docs

Turn READMEs, wiki pages, code comments, and prior incident notes into one condensed, conforming runbook — a how-to / troubleshooting guide that doubles as scoped context for an operational agent. /runbook-gen is the generation sibling of /doc-audit: where the auditor grades what exists, the generator produces.

TL;DR

bash
# Inside Claude Code — generate a draft from a topic + sources
/runbook-gen topic="recover a stuck warp-drive" runbooks/ docs/how-to/warp-drive.md

# Review the staged draft, then promote it into runbooks/
node ~/.claude/scripts/runbook-gen/promote.js runbooks/.drafts/recover-a-stuck-warp-drive.md

# Resolve a topic to its runbook (for an agent, or to check coverage)
node ~/.claude/scripts/runbook-gen/resolve.js "recover a stuck warp-drive" --print

Nothing lands in runbooks/ until you promote it — the draft is the review buffer.

How it works

The flow splits deterministic work (scripts) from judgement (the agent). Scripts guarantee identical inputs produce identical context and gate results; the agent does only the condensation.

StageOwnerWhat happens
Collectcollect.jsGather files / dirs / globs into one provenance-tagged bundle; missing sources are reported, not dropped.
Scaffoldscaffold.jsEmit a conforming skeleton (frontmatter + Purpose / When to use / Prerequisites / Steps / Troubleshooting / Escalation). Date via timelord.
Condensethe agentRead the bundle, rewrite the placeholders into a real runbook — inverted-pyramid lede, imperative steps with expected output and decision points, merged duplicates.
Validatevalidate.jsGate against the documentation standard: frontmatter contract, type: how-to, required sections, kebab filename. Errors block; warnings advise.
Stagethe skillWrite the draft to runbooks/.drafts/<slug>.md (git-ignored) and hand off for review.
Promotepromote.jsRe-validate, refuse to clobber without --force, then move the draft into runbooks/.

Steps

1. Run the command with a topic and sources

bash
/runbook-gen topic="<topic>" <source...>

A <source> is a file, a directory (recursed for .md/.txt), or a simple glob. Give it everything relevant — the generator condenses, so over-supplying sources is cheaper than missing one.

2. Review the staged draft

The draft lands at runbooks/.drafts/<slug>.md and is validated before you see it. Read it: are the steps right, the decision points real, the troubleshooting accurate? The draft is git-ignored — it exists only to be reviewed.

3. Promote it

bash
node ~/.claude/scripts/runbook-gen/promote.js runbooks/.drafts/<slug>.md

Promotion re-validates (an invalid draft cannot land), enforces the kebab filename, and refuses to overwrite an existing runbook without --force. On success the file moves into runbooks/ and the draft is removed. Commit it when ready.

4. (Optional) Use it as agent context

A promoted runbook is loadable as scoped procedural context for an operational agent (e.g. incident triage). Resolve a topic to its runbook without knowing the filename:

bash
node ~/.claude/scripts/runbook-gen/resolve.js "<topic>" --print   # content for inline context
node ~/.claude/scripts/runbook-gen/resolve.js "<topic>" --json    # ranked matches

Exit 1 means no runbook covers the topic yet — a signal to generate one.

Troubleshooting

SymptomLikely causeFix
collect: ... 0 sourcesAll sources missing or wrong extensionCheck paths; pass --ext if sources aren't .md/.txt.
Validator reports Missing YAML frontmatterEditing a legacy runbook that predates the standardGenerated runbooks carry frontmatter; add the type/owner/last_reviewed block.
promote refused: ... already existsA runbook of that name is already trackedReview the diff; pass --force to overwrite intentionally.
no runbook matches topicNo promoted runbook overlaps the topicGenerate one with /runbook-gen.

See also