Skip to main content
coreydaley.dev
Docs menu

Dot-graph skills

Most multi-phase skills in agent-config are built on one pattern: the skill’s flow is a graph, not a linear procedure. The graph is the source of truth, per-node prose lives in markdown sidecars, and a shared walker (lib/graph_walker.py) enforces transitions mechanically. Drift from the documented flow becomes structurally impossible, not a vibes-level guarantee.

The full reference is docs/DOT-GRAPH-SKILL-PATTERN.md in the repo; this page covers the essentials. The dot-graph state machines post tells the story of why it exists.

Layout

A graph-driven skill is a directory under skills/<skill>/:

<skill>/
  SKILL.md          # entry doc + frontmatter
  graph.dot         # source of truth (Graphviz DOT)
  graph.svg         # rendered visualization (humans only)
  nodes/            # per-node prose, one file per node
    <id>.md         # what the node does, how its edges resolve
  scripts/
    render.sh       # graph.dot → graph.svg
    validate.py     # structural integrity check
    walk.sh         # thin wrapper around lib/graph_walker.py
  references/       # optional skill-specific extras

The skill’s behaviour is the union of two things: the DOT graph, which defines node IDs, edges and edge condition labels, and the per-node sidecars, which say in prose what each node does and how its outgoing conditions are evaluated. The agent running the skill reads nodes/<current>.md, does the work, evaluates the outgoing edges, records the transition, and repeats until it reaches a terminal node.

Here is the rendered graph.svg for /feature-create: a linear backbone, a discuss loop, two user-input gates and a single terminal sink that every cancel route converges on.

Directed graph for the feature-create skill: blue process nodes from init through discuss, coral diamond gates ask-wrap-up and ask-create, a user_revise back-edge to discuss, and every cancel route ending at a green terminal node

Why a graph

Drift is mechanically impossible. The walker reads graph.dot and refuses transitions that aren’t on the graph. If a node’s prose says “transition to foo” but there’s no such edge, the walker rejects it with an error listing the valid alternatives. The contract between prose and routing is hard, not a hopeful comment.

The graph is reviewable. A 17-node skill’s macro flow fits on one screen as a rendered SVG. Reviewers see fork points, cleanup sinks, loops and dead ends at a glance, instead of routing decisions scattered across hundreds of lines of SKILL.md.

Resume support falls out for free. The walker’s state file records the current node, the transition history with timestamps, and per-skill extra fields. A crashed session’s .walk-state.json tells the next session exactly where work stopped.

The cost is honest: more files to author and some upfront design thinking. The payoff is that complex skills stay maintainable past the point where procedural prose would have started rotting.

The walker

lib/graph_walker.py is skill-agnostic: it parses any graph.dot, maintains a state file, and validates every transition against the graph. Each skill’s scripts/walk.sh hardcodes that skill’s graph so node prose stays terse:

scripts/walk.sh init       --state "$STATE"
scripts/walk.sh transition --state "$STATE" --from <id> --to <id> [--condition <label>]
scripts/walk.sh where      --state "$STATE"
scripts/walk.sh history    --state "$STATE"
scripts/walk.sh set        --state "$STATE" --key <name> --value "<value>"
scripts/walk.sh get        --state "$STATE" --key <name>

The state file lives wherever the skill’s per-run output lives (a report folder under ~/Reports/, or $TMPDIR/.claude-walker/<skill>/ for skills without one):

{
  "graph_path": "skills/<skill>/graph.dot",
  "current_node": "<id>",
  "started_at": "2026-05-07T10:30:00Z",
  "history": [
    {"from": "<id>", "to": "<id>", "condition": "<label>", "at": "..."}
  ],
  "extra": {"session_dir": "..."}
}

extra is the escape hatch for run-scoped state: anything a node needs to pass to later nodes goes through walk.sh set and walk.sh get.

A refused transition is a real error, not a hint. Either the node’s prose is out of sync with the graph, or the agent is trying to take a route that doesn’t exist. Never bypass the walker by editing the state file or skipping the call. The refusal lists the legal moves:

ERROR: no edge from 'compute_diff' to 'address'. Valid transitions
from 'compute_diff':
  compute_diff -> independent_reviews

Node types

Four node types, each with a consistent shape and colour. The walker doesn’t care about style; the conventions are for humans reading graph.svg.

TypeDOT shapeFillUsed for
Processrounded boxlight blue #e1f5feNodes that do work, with a single outgoing edge (or routing on persisted state)
Decisiondiamondamber #ffe0b2Pure routing on observable state, no user input
User-inputdiamondcoral #ffccbcNodes that ask the user; the answer picks the route
Terminaldouble circlegreen #c8e6c9Sink, with no outgoing edges

The two kinds of diamond read differently: a decision diamond’s edge is chosen by the agent evaluating state, a user-input diamond’s by the user’s answer.

Edge condition labels

When a node has several outgoing edges, each carries a short, lowercase, snake_case condition label:

ask_approval -> implement    [label="user_approve"];
ask_approval -> discuss_plan [label="user_discuss"];
ask_approval -> terminal     [label="user_cancel"];
discuss_plan -> ask_approval [label="discussion_done"];

Labels are scoped to their source node, so user_cancel from one gate needn’t be globally unique. A node with exactly one outgoing edge needs no label. Common ones across the suite: user_approve / user_revise / user_cancel, prior_exists / no_prior, setup_ok / setup_failed, keep_iterating / iter_cap.

Recurring shapes

  • Linear backbone. A chain of process nodes, with decision and user-input nodes as the forks.
  • Gate, then act. A user-input node asks; a separate process node downstream does the work. The gate validates intent, the act executes.
  • Discuss loop. A gate with approve / discuss / cancel exits and a back-edge from the discuss node. The user can iterate freely; the gate is always the exit.
  • Decision before a destructive step. A decision node re-checks preconditions right before anything irreversible, because time has passed since the last check.
  • Cleanup sink before terminal. When a node creates state that needs teardown (a worktree, a temp dir), every later path routes through cleanup. The walker rejects a shortcut straight to terminal.
  • Parallel delegation. One node launches several fresh sub-agents and waits for all of them; the parallelism is internal to the node.
  • Per-item loop inside a node. Walking N items (commit groups, findings, sub-issues) happens inside one node rather than one graph node per iteration.

When not to use it

The pattern earns its overhead when a skill has five or more phases, user-input gates that affect routing, loops or conditional branches, or per-run artifacts that benefit from a session folder. It’s overkill for thin CLI wrappers like gh and orbstack, which are one-shot operations with no internal state machine.

A useful test: if you’d be tempted to write the SKILL.md as a flowchart anyway, the pattern fits. If it would be a list of independent commands, leave it procedural.

Authoring a skill

The /skill-creator skill walks through this end to end. By hand, the loop is:

  1. Sketch the topology (process nodes, decisions, gates, loops, cleanup sinks) and agree on it before writing any sidecars.

  2. Write graph.dot using the shape and label conventions above.

  3. Copy scripts/ from an existing graph-driven skill.

  4. Render and validate; validate.py lists the sidecars that are still missing.

    bash scripts/render.sh
    python3 scripts/validate.py   # → "OK: N nodes, M edges, 1 terminal node(s)."
  5. Write each nodes/<id>.md (inputs, steps, outputs, outgoing edges, failure modes), re-validating as you go.

  6. Write SKILL.md: frontmatter, help mode, external-content handling, the state machine, walker semantics, artifacts and a “Don’ts” list.

  7. Smoke-test the walker on the happy path, every gate’s branches, every loop, and one illegal transition to confirm it’s refused.

validate.py checks that every edge’s nodes are declared, every node has a sidecar, terminal nodes have no outgoing edges, and every node except init has an incoming edge.