Fix Claude fork cwd drift
Summary
- Preserve Claude hook
transcriptPathon restorable snapshots. - Use the transcript project directory for Claude resume/fork cd prefixes when hook cwd has drifted.
Testing
./scripts/reload.sh --tag cldforkpassed.- AWS targeted xcodebuild test was attempted, but the runner's xcodebuild crashed during Swift package resolution before compiling.
Issues
- Related: Claude Code fork command failed with
No conversation found with session IDwhen the transcript lived under the original project cwd but the hook cwd had moved to a worktree.
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.
[!NOTE]
Medium Risk
Changes how Claude resume/fork shell commands choose the working directory; incorrect matching could still run Claude from the wrong folder, though scope is limited to restorable Claude sessions and regression tests were added.
Overview
Fixes Claude resume/fork when the hook cwd has moved (e.g. into a worktree) but the conversation transcript still lives under the original project folder.
Restorable snapshots now carry Claude transcriptPath from hook records into SessionRestorableAgentSnapshot, and AgentResumeCommandBuilder uses it when building the shell cd prefix for Claude resume/fork commands.
For Claude only, the builder reads the encoded project directory name from the transcript path (…/projects/<encoded>/session.jsonl) and picks a working directory by matching that name against encodeClaudeProjectDir on hook/launch cwd candidates (with tilde expansion)—not by reversing hyphens to slashes. If nothing matches, behavior falls back to the previous cwd logic.
SessionIndexStore drops its local encodeClaudeProjectDir duplicate in favor of RestorableAgentSessionIndex.encodeClaudeProjectDir. New tests cover cwd drift and avoiding lossy decode on hyphenated project dir names.
Reviewed by Cursor Bugbot for commit 170a021311a1e676a422a22c465b2c411b749516. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes Claude resume/fork when the hook cwd drifts by deriving the cd prefix from the transcript’s project directory using a shared encoder for consistent matching. Also avoids lossy decoding of encoded transcript project folders, preventing bad cd paths and the “No conversation found with session ID” error.
- Bug Fixes
- Preserve Claude
transcriptPathon restorable snapshots so resume/fork can locate the original project. - Compute the cd prefix by matching the transcript’s encoded project folder to candidate cwds with a shared encoder; if no match, fall back to the previous cwd (no hyphen→slash decoding).
- Add regression tests for transcript project cwd selection and for avoiding lossy decoding.
- Preserve Claude
Summary by CodeRabbit
-
New Features
- Resume and fork now carry optional transcript information so sessions can better restore context; snapshots persist transcript info.
-
Bug Fixes
- Improved working-directory resolution to prefer transcript-derived project directories where applicable and avoid embedding drifted hook paths.
-
Tests
- Added coverage for transcript-based working-directory behavior and hardened transcript writing in tests.