This file documents the Claude Code driver for Forge. The hook re-injects the next iteration prompt after each Claude Code session exit.
Forge is directly inspired by Ralph Wiggum's loop pattern. The driver now uses
forge-loop.*.local.md as the primary loop-state file name while still
accepting legacy ralph-loop.*.local.md files for compatibility.
When Claude Code exits, the stop hook:
- Checks for an active
.claude/forge-loop.*.local.mdstate file bound to this session - Falls back to legacy
.claude/ralph-loop.*.local.mdstate files if needed - If found, reads the last assistant message from the transcript
- Checks for exact control lines (
FORGE_COMPLETE,FORGE_PAUSE, promise tags) - If not complete, increments the iteration counter and re-injects the prompt
- This creates the autoregressive loop — each new iteration sees the updated forge-state file
Add this to your ~/.claude/settings.json under the hooks key:
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "/path/to/forge-loop/hooks/stop-hook.sh"
}
]
}
]
}
}If you ran ./install.sh, the stable local path is:
"command": "$HOME/.claude/hooks/stop-hook.sh"Legacy Ralph state files and control markers are still accepted during migration.
No native Codex driver is shipped here. This hook is Claude Code-specific.
The stop hook checks for these exact control lines in the last assistant message:
FORGE_COMPLETE— all targets met, stop the loop and clean up state fileFORGE_PAUSE— user input needed, pause the loop and preserve the state file<promise>TEXT</promise>— completion promise fulfilled when emitted on its own line (if--completion-promisewas set)- Max iterations reached — safety limit, stop the loop
Legacy RALPH_COMPLETE and RALPH_PAUSE markers are still accepted.
Controls the iteration engine. Format:
---
active: true
session_id: "0320-1430-a3b2"
session_transcript: null
iteration: 1
max_iterations: 20
completion_promise: null
started_at: "2026-03-20T14:30:00Z"
---
[The prompt that gets re-injected each iteration]Key fields:
session_transcript: Set tonullinitially, claimed by the first session that runs the stop hook. Binds the state file to one Claude Code session.iteration: Incremented by the stop hook on each cycleactive: Set topausedonFORGE_PAUSE; paused loop files are ignored until you manually set them back totrueor start a fresh loop
Legacy .claude/ralph-loop.SESSION.local.md files are still accepted.
Tracks KPIs, strategies, and lessons across iterations. This is the autoregressive memory — read by the forge protocol on each ORIENT phase. See the skill docs for the full format.
Both files live in .claude/ which is typically gitignored. Stale files (>24h) are cleaned up automatically.
The stop hook requires:
jq— for parsing the hook input JSON and transcriptsed,awk,grep— standard Unix tools