/agent-almanac:create-workflowfrom agent-almanac
Guides authoring a self-contained `.mjs` orchestration script for Claude Code's Workflow tool. Covers template setup, naming conventions, frontmatter, injected primitives, capability contracts, and validation.
Ships in agent-almanac. 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.
Author a workflow — the fifth content type — as a self-contained workflows/<name>.mjs script run by Claude Code's Workflow tool. A workflow fixes its phases, fan-out, and verification structure in JavaScript: its control flow is deterministic and rereadable, while the outputs of its agent() calls are LLM subagents and remain nondeterministic. This skill is the procedure for authoring one; guides/creating-workflows.md is the API reference it draws on.
Vendor-API caveat. The Workflow run model is generally available on paid Claude Code plans (~v2.1.154+), but the script-authoring surface (the injected
agent()/parallel()/pipeline()/phase()/log()/workflow()primitives and theargs/budgetglobals) is an evolving vendor API — accurate as observed in Claude Code v2.1.x, subject to change, never CI-enforced.
workflows/ library, or authoring a personal workflow for .claude/workflows/.review-changes). This becomes the filename stem, the sidecar name:, and meta.name — all three must be identical.pipeline() vs barrier parallel()).args (default them so it runs with no input).A workflow is one of five content types. Choose deliberately:
Expected: A one-line justification for why this is a workflow and not a team or a single skill.
On failure: If the coordination must adapt turn-by-turn, stop and use create-team. If only one agent acts, use create-skill.
Start from the canonical scaffold — never a blank file:
cp workflows/_template.mjs workflows/<name>.mjs
For a personal (non-library) workflow, copy into .claude/workflows/<name>.js instead: the Workflow tool does not discover a .mjs file there (Step 9). Read workflows/<name>.mjs in the commands of Steps 3 and 8 as that file, and skip Step 9's copy, but not its collision check. The template carries the sidecar block, a pure-literal meta, a phase(), a pipeline() fan-out, an agent({ schema }) call, and the hard constraints inline.
Expected: A new .mjs file (.js for a personal workflow) that is a verbatim copy of the template.
On failure: If workflows/_template.mjs is missing, you are on a pre-Phase-1 checkout — fetch main.
Rename in the three places that must stay identical — the filename stem, the sidecar // name:, and the meta.name literal:
grep -n "name:" workflows/<name>.mjs # sidecar + meta.name must equal the filename stem
That triple equality (filename ↔ sidecar name ↔ meta.name) is this repository's convention, and integrity check A7 enforces it for workflows/. It is not how the Workflow tool finds a workflow: the tool registers a workflow under its meta.name, not under its file name (Step 9).
Expected: All three read the same kebab-case name.
On failure: If integrity check A7 reports a mismatch, re-check all three. A Workflow "<name>" not found error at runtime is a different fault; Step 9 covers it.
meta and Sidecarexport const meta must be a pure literal — no variables, function calls, spreads, or template interpolation. Required fields: name and description. phases (one entry per phase the workflow uses, whether opened by a global phase() call or a stage's per-call phase: option) is optional but recommended. Mirror name, description, and the phases titles in the top-of-file sidecar comment block — the sidecar is the catalog source of truth (the analogue of YAML frontmatter on the other content types), readable by grep without a JS parser.
Expected: meta is a literal object; the sidecar agrees with it; phases ⊇ every title passed to phase() or a stage phase:.
On failure: A meta must be a pure literal error means a value references a variable or call — inline it.
The body runs inside an async wrapper — use top-level await and a top-level return directly. Compose with the injected globals (no imports):
pipeline(items, ...stages) — the default: each item flows through every stage with no barrier between stages (wall-clock = slowest single chain).parallel(thunks) — a barrier: use only when a stage needs every prior result at once (dedup, an early-exit count, a synthesis step).agent(prompt, { schema, label, phase, agentType }) — spawn one subagent; with { schema } it returns a validated object.phase(title), log(message), and the args / budget globals. Default args so the workflow runs with no input.Pass a JSON Schema as { schema } to force structured output (no free-text parsing). See guides/creating-workflows.md for the full primitive reference.
Decide the durability model before writing the body. The script cannot touch
the filesystem, so it cannot checkpoint itself: an interrupted Workflow(...) call
returns nothing whichever fan-out primitive it used, and resumeFromRunId is
same-session only (the tool's own contract; observed here for process death) —
once the launching session is gone, so is the run. Answer in one line: what survives
if this run dies halfway? The invariant is that every expensive result is on disk
before the run can die; the two ways to get there differ in where that write
happens and compose freely. Either the agents write validator-gated artifacts to
disk as they go (the batch-generate-waves
model — a stage that dies then loses only its unfinished items), or the invoker
splits the run into batches and persists each batch's results between
Workflow(...) calls, or both. Salvaging a run that did neither means hand-parsing
~/.claude/projects/<project-slug>/<session-id>/subagents/workflows/<runId>/journal.jsonl,
which recovers the results that finished, not the run. Full treatment:
guides/creating-workflows.md § Surviving an
Interrupted Run.
Expected: A body that defaults its inputs, fans out with the right primitive, returns a value, and a one-line answer to what survives if the run dies halfway.
On failure: If you reach for parallel() only to flatten or map between stages, that barrier is not justified — do the transform inside a pipeline() stage. If the honest answer to the durability question is "nothing", changing the primitive will not help: move the writing into the agents, or split the run into batches the invoker persists between.
agent({ agentType }) names the spawn type per call — the workflow's native expression of the persona-vs-spawn decoupling. The intent rule applies:
isolation: 'worktree') must target an implementing agent type.Explore).Set agentType explicitly on every stage so the contract is visible, not implied.
Expected: Every agent() call names an agentType whose capability matches what the stage does.
On failure: A mutating stage targeting an advisory type cannot write — switch it to an implementing type such as general-purpose.
If your workflow verifies candidate findings (the classify → refute → synthesize spine), bake in the three lessons the review-changes seed encodes:
agent() returns null when a subagent is skipped or dies, so filter(Boolean) before counting and require a majority of confirmations to survive (confirmedVotes >= Math.floor(n / 2) + 1). Surviving when "few enough refuted" inverts the fail-safe — a dead refuter would let an unverified finding through.Expected: Survival gates on a confirmation quorum, verifiers share the proposer's evidence, and null results are filtered.
On failure: If real findings vanish, check that verifiers aren't starved of context (lesson 2); if junk survives, check the gate counts confirmations, not refutations (lesson 1).
Workflow scripts use a top-level return, which the runtime accepts (it wraps the body in an async function) but raw ESM rejects — so plain node --check reports Illegal return statement on a valid workflow. Use the wrap-then-check recipe:
{ echo '(async()=>{'; \
sed 's/^[[:space:]]*export const meta/const meta/' workflows/<name>.mjs; \
echo '})()'; } | node --check -
The authoritative check is running it once installed (Step 9): Workflow({ name: '<name>' }).
Expected: The wrap-check passes with no syntax error.
On failure: Do not "fix" a top-level return to pass raw node --check — that would cripple the script. Use the wrap-check; debug any other syntax error normally.
The Workflow tool discovers a project workflow in .claude/workflows/ from a .js file; a .mjs file there is not discovered, and the not-found error does not mention it. It registers the workflow under its meta.name, not its file name (tests/results/2026-10-14-workflow-loader-probe/RESULT.md). In Phase 1, install by hand. The source in workflows/ keeps .mjs, and the installed copy changes extension:
cp workflows/<name>.mjs .claude/workflows/<name>.js
Then invoke Workflow({ name: '<name>' }) or the /<name> slash command, where <name> is the meta.name. .claude/workflows/ is user-writable and the save-flow writes there. The copy keeps the source's meta.name, and two files with the same meta.name collide silently: one slash command is registered, only one body runs, and nothing warns. Before copying, check that no workflow already in .claude/workflows/ uses that meta.name. A file-name prefix such as almanac-<name>.js does not prevent a collision, because the workflow is registered under its meta.name; it only stops cp from overwriting a file. How a curated install should namespace is left to the deferred CLI install adapter (#293).
Expected: The workflow runs end-to-end and returns its value.
On failure: If the call reports Workflow "<name>" not found, check that the file is in .claude/workflows/, that its name ends in .js rather than .mjs, and that <name> is its meta.name. If a different workflow's body runs, another file in .claude/workflows/ carries the same meta.name.
Phase-2-pending. A
workflows/_registry.yml, CI validation of the sidecar, and a CLI install adapter are deferred behind the #288 promotion gate (~8–10 workflows + a real install request). Until they land, a library workflow needs no registry entry — the sidecar frontmatter is its catalog metadata, and an installed copy is found by itsmeta.name(Step 9). When the registry exists, this step becomes "add an entry derived from the sidecar."Workflows are excluded from i18n. Unlike skills/agents/teams/guides, a workflow is executable code, not prose — do not scaffold translations for it.
If contributing a reviewed seed to agent-almanac, place it in workflows/, cross-reference it from guides/creating-workflows.md, and carry the vendor-API caveat in any prose you add.
Expected: A library workflow lives in workflows/ with an accurate sidecar; no registry or translation steps are attempted in Phase 1.
On failure: If a tool expects workflows/_registry.yml, you are ahead of the promotion gate — stop and confirm Phase 2 has shipped.
The advisory/implementing contract in Step 6 governs the declared agent type, not what a Bash-capable agent writes to the working tree. Combine three complementary controls (full rationale and mechanics in containment-notes.md):
Name a write location in every Bash-capable stage prompt — copy the template's WRITE_LOCATION (or narrow it as <PREFIX>_WRITE_LOCATION for stages that also write a declared output dir; integrity check A7b looks for the identifier). Include read-only-by-intent stages, which otherwise pollute by inherited cwd.
Bracket the run with repo-guard around the Workflow(...) call (compares HEAD, branch, status, changed/untracked file contents, and index flags; ignores ignored paths):
npm run guard:snapshot # before launching the workflow
npm run guard:verify # after it returns
npm run guard:release # when the run is genuinely over
Prepend REPO_SAFETY from workflows/_template.mjs to every shell-capable stage prompt (verifiers included). In template order:
mktemp -d, never a shared fixed path.
cd "${DIR:?}" || exit 1 (braced so unset/empty DIR aborts).
Braced absolute paths under $DIR in destructive commands (rm -rf "${DIR:?}/fixtures").
A braced cwd assertion before git add, git commit, or write-flagged tools:
[ "$(git rev-parse --show-toplevel)" = "${DIR:?}" ] || exit 1
Never git commit, git update-index, or git checkout -- against the repository itself, and never a repo tool with a write flag there.
Prefer isolation: 'worktree' for mutating stages. Instruction prevents a compliant agent from writing where it stands; worktree isolation contains expected writers; repo-guard detects what neither caught. See containment-notes.md for edge cases (#493, bash/zsh :? behavior, and guard:release lifecycle).
Expected: npm run guard:verify exits 0 after the run.
On failure: Exit 1 prints what moved and the recovery command. A stray commit
is recoverable while unpushed: confirm it is unpushed, state what the reset
destroys, then git reset --mixed <recorded-head> and remove the stray files.
Exit 2 means the guard could not compare — re-snapshot and re-run rather than
treating it as a pass.
workflows/<name>.mjs (or .claude/workflows/<name>.js for personal use).name:, and meta.name are identical (triple-name convention).export const meta is a pure literal; sidecar mirrors name/description/phases.phases: ⊇ every title passed to phase() or a stage phase: option.args, uses an appropriate fan-out primitive, and returns a value.Workflow(...) calls.agent() call sets an agentType whose capability matches the stage (advisory vs implementing).filter(Boolean) null results.Date.now(), Math.random(), argless new Date(); no TypeScript syntax; no filesystem/Node APIs.node --check recipe passes.npm run guard:snapshot / guard:verify, and agents with shell access carry the REPO_SAFETY preamble (Step 11).Bash-capable stage prompt names where that agent may write (Step 11).workflows/_registry.yml entry or translation scaffold was created (both are Phase 2 / i18n-excluded).null/dead refuter pass an unverified finding through. Gate on a majority of affirmative confirmations.return. It is valid Workflow dialect; rewriting it to satisfy raw node --check breaks the script. Use the wrap-check.Date.now() / Math.random() / argless new Date() break workflow resume. Pass timestamps via args; vary randomness by agent index or label.workflows/_registry.yml or scaffold translations for a workflow — registries/CLI/validation are gated, and workflows are i18n-excluded./tmp" prevents a compliant agent from writing where it stands, which is worth its one sentence (Step 11) — but an agent can follow it exactly and still write to the repository when its cd fails, and no amount of specificity changes that. Pair it with worktree isolation, a cwd assertion, and a HEAD check; never substitute it for them.$SCRATCH/fixture.sh between the first agent writing it and running it turns a correct invocation into someone else's script — the first agent then runs the second's file, believing it ran its own.git status proves a fan-out was read-only. It cannot see an agent that committed. Compare HEAD, and treat unexplained staleness in any generated artifact derived from the corpus as evidence the corpus moved.Workflow(...) call returns nothing whether it fanned out with parallel() or pipeline(): the script cannot persist what already came back, and resumeFromRunId is same-session only. pipeline() buys wall-clock, not survival. Decide the durability model in Step 5 — gated artifacts on disk, or batches the invoker persists between calls.create-skill — author a SKILL.md (the how for one agent); the meta-pattern sibling.create-agent — define an agent persona; workflows spawn agents by agentType.create-team — compose a declarative, model-driven roster (the adaptive counterpart to a workflow).commit-changes — commit the new workflow file.review-codebase / review-pull-request — the single-reviewer skills the review-changes workflow coordinates many of.What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (pjt222/agent-almanac) — no native marketplace selected
npx claudepluginhub p/pjt222-agent-almanac377 skills in this plugin
/adapt-architectureExecute structural metamorphosis using strangler fig migration, chrysalis phases, and interface preservation. Covers transformation planning, parallel running, progressive cutover, rollback design, and post-metamorphosis stabilization for system architecture evolution. Use when assess-form has classified the system as READY for transformation, when migrating from monolith to microservices, when replacing a core subsystem while dependents continue operating, or when any architectural change must be gradual rather than big-bang.
/adapticMaster skill composing the 5-step synoptic cycle for panoramic synthesis across multiple domains. Orchestrates meditate, expand-awareness, observe, awareness, integrate-gestalt, and express-insight into a coherent process that produces unified understanding rather than sequential compromise. Use when a problem genuinely spans 3+ domains and the interactions between domains matter more than depth in any one, when sequential analysis feels like compromise rather than integration, or before major architectural decisions affecting multiple stakeholders.
/add-puzzle-typeScaffold a new puzzle type across all 10+ pipeline integration points in jigsawR. Creates the core puzzle module, wires it into the unified pipeline (generation, positioning, rendering, adjacency), adds ggpuzzle geom/stat layers, updates DESCRIPTION and config.yml, extends the Shiny app, and creates a comprehensive test suite. Use when adding a completely new puzzle type to the package or following the 10-point integration checklist to ensure nothing is missed end-to-end.
Other plugins' skills for the same job