How It Works

Contents
  1. Phases
  2. Hooks
  3. Safety Valves
  4. Files and Ownership
  5. See Also

Documentation › How it works

specloop is a spec-driven development loop for Claude Code, built only from hooks, slash commands and a small Python state machine. You drop in a specification, start development by hand, and Claude is walked through plan → implement → review phases. A phase only completes when its check passes: the plan file exists, the tests are green, or the reviewer approves.

It runs inside your normal Claude Code session (CLI, desktop app or IDE), so it uses your Claude subscription. You don’t need API keys or a separate orchestrator.

Phases

Phase Claude does Gate (checked by the Stop hook) Edits allowed
plan Reads the spec, writes .claude/specloop/run/plan.md plan file exists and is non-empty only .claude/specloop/run/
implement Test-first implementation of the plan your test command exits 0 anything
review Reviews the diff (ideally via a subagent), writes review.md VERDICT: APPROVE → done; VERDICT: CHANGES_REQUESTED → back to implement only .claude/specloop/run/

The phases are a configurable graph: see Phases for the check types and for adding or removing a phase. A spec that is too big for one cycle is better run in feature mode, which splits it into steps with one commit each.

Hooks

The engine plugs into four hooks:

  • Stop: each time Claude tries to end its turn, it runs the current phase’s check. If the check fails, the stop is blocked and Claude gets the failure (for example the tail of the test output) and keeps working. If it passes, the workflow moves to the next phase and Claude gets that phase’s instructions.
  • PreToolUse: enforces per-phase edit restrictions. It blocks git push and gh pr create/merge until the workflow is done, and stops Claude from editing specloop’s own state. See Guard rails.
  • SessionStart / UserPromptSubmit: put the current phase and its instructions into context, so a new or resumed session picks up where the last one stopped.

Safety Valves

  • After maxIterations blocked stops (default 15) the workflow goes to stalled and Claude is allowed to stop. /sl-go resumes it.
  • /sl-pause turns the hooks off when you want to talk to Claude in between.
  • A spec or plan that looks too big for one plan → implement → review cycle triggers a warning (see Size warnings).
  • Setting SPECLOOP_DISABLED=1 makes every hook a no-op.
  • If the engine itself crashes, the hook logs to stderr and exits 0, so a crash never breaks your session.
  • An unreadable state.json is reported instead of ignored: Stop and the context hooks say that specloop is not enforcing anything, and /sl-reset clears it.

Files and Ownership

Files in <project>/.claude/specloop/:

File Owner Purpose
defaults.json kit (replaced on update) Default settings and phase graph.
config.json project Your overrides, deep-merged over defaults.json.
config.local.json person Your personal overrides, deep-merged over config.json. Git-ignored. See Configuration.
phases/<phase>.md kit (replaced on update) Shipped phase instructions.
presets/<name>.json kit (replaced on update) The quality presets /sl-quality init offers. Never applied by themselves.
overrides/<phase>.md project Your phase instructions; take precedence over phases/.
state.json, state.lock, run/ runtime Current state, its lock, plan and review files.
run/quality.md, run/quality/ runtime The quality gates report of the last gate run and each gate’s complete output. Both move to run/steps/<id>/ when a feature-mode step finishes.
run/quality-manual/ runtime The logs of /sl-quality run, kept apart from run/quality/. It does not move when a step finishes.
update.json, update.lock runtime Result of the last update check and the lock of a running check. See Updates.
manifest.json kit What the installer wrote: commands, agents (the installed subagent definitions), settings, stopTimeoutSec (the Stop hook’s timeout, which bounds the quality gates) and source, the clone the kit was installed from.

Everything in this directory except config.json and overrides/ is git-ignored.

Files in <project>/.claude/agents/:

File Owner Purpose
specloop-planner.md, specloop-implementer.md, specloop-reviewer.md, specloop-orchestrator.md kit (replaced on update) Subagent definitions for the planner, implementer and reviewer roles, and a main-thread orchestrator restricted to Agent, Read, Grep and Glob. Listed in manifest.json under agents and git-ignored.
any other file project Never touched by the installer.

state.json holds, besides the workflow position, the state of quality gates. qualityBaseline is one key: the value of each ratchet gate, measured once per run on the Stop that passes the planning phase and kept for the rest of the run. qualityFingerprints holds the SHA-256 of each protected file and of the merged quality block, stored on the first /sl-go; a gate compares against it before its command runs. qualityResults is the last result of each gate, qualityAccepted the hashes of the forbidden lines a person accepted (with qualityAcceptedLog, the accepted changes), and qualityWaived the gates /sl-advance skipped. pausedFor names the gate and the reason while a broken gate pauses the run. In single mode baseRef and preexistingUntracked, recorded on the first /sl-go in a git repository, give {changed_files} its comparison point; feature mode records them when it creates its branch.

See Also

View this page on GitHub