fix: resume uses snapshot directory instead of caller's cwd#7
Merged
aannoo merged 1 commit intoaannoo:mainfrom Mar 8, 2026
Merged
fix: resume uses snapshot directory instead of caller's cwd#7aannoo merged 1 commit intoaannoo:mainfrom
aannoo merged 1 commit intoaannoo:mainfrom
Conversation
When resuming an agent with `hcom r <name>`, the agent now starts in the directory where it was originally launched, not the directory where the resume command is run. This prevents database corruption and incorrect working directory issues. Changes: - resume.rs: extract `directory` from stopped snapshot, compute effective_cwd with priority: --dir flag > fork=cwd > resume=snapshot > fallback with warning - instances.rs: add cwd_override parameter to initialize_instance_in_position_file() so the DB records the correct directory from pre-registration (no stale window) - launcher.rs: pass working_dir as cwd_override - New --dir flag for explicit directory override (validated and canonicalized) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hcom r <name>now starts the agent in the directory where it was originally launched, not where the resume command is run--dirflag for explicit directory override on resume/forkThe Bug
When resuming an agent with
hcom r <name>from a different directory than the original launch, two things go wrong:cwdinstead of the directory stored in the stopped snapshot. This breaks relative paths, project-specific configs, andCLAUDE.md/.claude/settings.jsonresolution.initialize_instance_in_position_file()independently readscurrent_dir()and writes it to thedirectoryfield in the DB. If the agent is later stopped and resumed again, the corrupted directory propagates through snapshots.Reproduction
The Fix
1.
resume.rs— Use snapshot directory for resumedo_resume()now extracts thedirectoryfield from the stopped snapshot and computeseffective_cwdwith this priority:--dir /pathflaghcom f)current_dir()(fork = fresh start)current_dir()with stderr warning2.
instances.rs— Eliminate stale directory windowinitialize_instance_in_position_file()now accepts an optionalcwd_overrideparameter. When provided, it uses the override instead of callingcurrent_dir()independently. This eliminates the window where the DB records the wrong directory during pre-registration.3.
launcher.rs— Pass correct cwd to pre-registrationThe
launch()function now passesworking_dir(fromLaunchParams.cwd) toinitialize_instance_in_position_file(), ensuring the DB directory is correct from the moment the instance is created.4. New
--dirflagResume and fork now support
--dir <path>(and--dir=<path>) to explicitly override the working directory:The
--dirpath is validated (is_dir()check) and canonicalized to an absolute path.Files Changed
src/commands/resume.rseffective_cwd, add--dirflagsrc/instances.rscwd_override: Option<&str>parametersrc/launcher.rsworking_dirascwd_overridesrc/commands/start.rsNonefor new parameter (2 call sites, no behavior change)Testing
All scenarios verified with isolated
HCOM_DIR:--dir /tmpoverride--dir /nonexistent→ error messageWorks for all tool types (Claude, Codex, Gemini, OpenCode) — the directory logic is in the common path before tool-specific branching.
🤖 Generated with Claude Code