Deepwork Reconcile
Rebuild the active session's state.json from its event log (events.jsonl) using a full hash-chain replay.
When to invoke:
frontmatter-gateemitsEVENT_HEAD_MISMATCHorSTATE_DIVERGENCEstate.jsonis suspected corrupt or has been manually edited- After a crash that may have left
state.jsonandevents.jsonlout of sync - Any time you want to verify event log integrity without modifying state
Steps
- Locate the active instance state file:
Glob: ${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/*/state.json
If no file is found, report "No active deepwork session" and stop.
- Run the replay:
bash "${CLAUDE_PLUGIN_ROOT}/scripts/state-transition.sh" replay \
--state-file "${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/<instance-id>/state.json"
The replay subcommand:
- Reads
events.jsonlfrom the same directory asstate.json - Verifies the hash chain from GENESIS through every event
- Reduces all events into a new state snapshot
- Atomically overwrites
state.jsonwith the reduced state - Recomputes
state_integrity_hashandevent_head - Prints a reconciliation report to stdout
-
Display the reconciliation report verbatim. It includes:
- Number of events processed
- Final
event_headhash
-
If the command exits non-zero:
- Exit code 1: events.jsonl missing or unreadable, invalid JSON at a specific line, or hash chain break — report the error message from stderr;
state.jsonwas not overwritten
- Exit code 1: events.jsonl missing or unreadable, invalid JSON at a specific line, or hash chain break — report the error message from stderr;
On a clean reconciliation, report: "Reconcile complete — state.json rebuilt from N events, hash chain valid."