opencode run --fork --dir does not set session working directory correctly #127
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
When forking a session with
opencode run --fork --session <base> --dir <worktree>, the--dirflag sets the directory for the initial command only. The forked session'sdirectorycolumn in opencode's SQLite DB inherits from the parent session's shell working directory, not from--dir.Impact
All agents forked via
kugetsu startorkugetsu continuerun from the base session's directory (e.g.~/repositories/projector/tmp), completely ignoring the intended worktree. This makes isolated per-issue sessions unusable.Root Cause
The
--dirflag inopencode runonly affects the subprocess's working directory for that specific command — it does not update the session's storeddirectoryvalue in opencode's SQLite DB.Findings
v0.1.10 partial fix
cmd_startwas updated to wrap the command in a subshell with explicitcd:This ensures the session is created with the correct working directory. Verified working in v0.1.10 + re-init.
cmd_continuestill affectedcmd_continueuses the same--dirpattern but WITHOUT the subshellcd:The
--dirflag does not update the session's persistent directory on--continue.Recommended Fix
Apply the same subshell pattern to
cmd_continue:Workaround (for users)
Session existence check to avoid duplicate sessions and use correct command: