Repository navigation
Description
Context
Extends #829 (afx workspace recover — process revival for builders after machine reboot). #829's initial scope was process revival only: respawn a fresh claude process in the right worktree and let porch state bridge the protocol-level continuity. Conversation context — what the builder was thinking, what was tried, what feedback the user had given — was explicitly out of scope and acknowledged as a "larger separate issue."
This issue covers the conversation-resume work that was ultimately bundled into the same PR. Tracked separately so the design and implementation history are easy to find.
Problem
After process revival, the respawned builder started with no memory of its prior session. Useful at approval gates (porch's external memory bridges the gap), but materially worse for mid-phase crashes — the builder had to reconstruct intent from the worktree diff and protocol state, often re-deriving conclusions or undoing partial work.
Mechanism
Claude Code automatically persists every interactive session to
~/.claude/projects/<encoded-cwd>/<session-uuid>.jsonl
where the encoding replaces both / and . in the absolute cwd with -. The data for every prior builder session is on disk; we just hadn't been looking.
On --resume, spawn.ts now:
- Computes the encoded directory for the worktree
- Picks the most-recently-modified
*.jsonlby mtime - Passes the UUID through to
startBuilderSession - The launch script runs
claude --resume <uuid>(no role injection, no initial prompt — both are already part of the saved conversation)
Backwards-compatible by design: existing builders (spawned before this code shipped) already have their jsonl on disk and resume cleanly on the first revival.
If no jsonl exists (truly fresh worktree, deleted history, etc.), spawn falls back to the prior behavior — fresh session with a generic resume-notice prompt.
Why jsonl discovery over a sidecar
Discussed at length in the #829 conversation. Trade-offs in short:
- No spawn-time state to maintain. Claude writes the jsonl as a side effect of the original session; we only read it. No sidecar file, no SQLite column, no schema migration.
- Backwards compat for free. Existing builders work the first time the new code runs because their jsonl was already on disk.
- One mechanism, not two. Same helper extends to architects (single-architect workspaces; multi-architect ambiguity is a known limitation tracked separately in Workspace recover: revive Tower-managed architects after machine reboot #830).
The trade-off: when multiple jsonl files live in the same encoded-cwd directory (a worktree was reused for unrelated work), the newest wins by mtime. For builder worktrees — protocol-scoped, typically host one logical conversation — this is right nearly always. The Claude session: <prefix>… (resuming conversation) log line surfaces which UUID was picked so any mismatch is visible.
Scope
- In: Builder conversation resume on the
afx spawn --resumepath. Triggered transitively byafx workspace recover. Backwards-compatible for existing builders. - Out: Architect conversation resume (covered by Workspace recover: revive Tower-managed architects after machine reboot #830). Multi-architect disambiguation. Per-builder session UUID storage / sidecar approaches.
Reference
- afx workspace recover: revive builders after machine reboot/crash #829 — original
afx workspace recoverfeature, where this conversation-resume implementation landed. - Helper module:
packages/codev/src/agent-farm/utils/claude-session-discovery.ts. - Threading:
packages/codev/src/agent-farm/commands/spawn.ts(read jsonl on--resume),packages/codev/src/agent-farm/commands/spawn-worktree.ts(different launch script whenresumeSessionIdis provided). - Tests: 9 unit tests in
packages/codev/src/agent-farm/__tests__/claude-session-discovery.test.tscovering encoding, missing dir, no-jsonl dir, mtime selection, and ignored non-jsonl entries.
Activity
amrmelsayed commentedon May 23, 2026
Status update — implementation landed in PR #833.
Mechanism: Claude Code automatically persists every interactive session to
~/.claude/projects/<encoded-cwd>/<uuid>.jsonl, where the encoding replaces/and.with-. Onafx spawn --resume, look up that directory for the worktree, pick the newest jsonl by mtime, and pass the UUID through tostartBuilderSession. The launch script then runsclaude --resume <uuid>(no role injection, no initial prompt — both already in the saved conversation).Backwards-compatible by design: existing builders' jsonl files were already on disk before this code landed, so revival picks them up automatically — no migration needed.
Coverage: all five revivable protocols. SPIR/ASPIR/AIR go through
spawnSpec; bugfix/PIR go throughspawnIssueDrivenBuilder. Both spawn sites now call the shareddiscoverResumeSessionhelper (extracted during the round-2 cmap-3 review when reviewers caught that onlyspawnSpechad the resume wiring originally).Helper layering:
findLatestSessionId(cwd)— pure I/O utility inutils/claude-session-discovery.ts. No logging, no gates. Importable from Tower (server-side) too.discoverResumeSession(worktreePath, isResume)— spawn-CLI wrapper. Gates on--resume, delegates to the utility, logs the result. Used by both spawn callsites.Tests: 9 unit tests in
claude-session-discovery.test.tscover encoding edge cases, missing dir, no-jsonl dir, multi-file mtime selection, and ignored non-jsonl entries.Closing once PR #833 merges.
[Issue cluesmith#830] feat(tower): resume main architect's Claude con…