Skip to content

Fix agent CWD detection to read from CLI process instead of shell#64

Closed
selfcontained wants to merge 1 commit into
mainfrom
worktree-cd-instruction
Closed

Fix agent CWD detection to read from CLI process instead of shell#64
selfcontained wants to merge 1 commit into
mainfrom
worktree-cd-instruction

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Summary

  • tmux pane_current_path only tracks the shell's CWD, but agent CLIs (claude/codex/opencode) may cd into worktrees internally without updating the parent shell
  • This caused the UI to show "main repository" and the wrong branch for agents working in worktrees
  • New resolveAgentProcessCwd() walks the process tree to find the agent CLI child process and reads its actual CWD via lsof, falling back to pane_current_path when unavailable

Test plan

  • Backend type check passes (tsc --noEmit)
  • Web type check passes (npm run check)
  • Unit tests pass (49/49)
  • E2E tests pass (25/25)
  • Verify post-log-message agent now shows correct worktree branch and status after server restart

🤖 Generated with Claude Code

The create_worktree MCP tool response now tells the agent to cd into
the new worktree path, so git context probes reflect the correct branch
instead of the main project directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@selfcontained
selfcontained deleted the worktree-cd-instruction branch April 9, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant