Skip to content

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

Merged
selfcontained merged 3 commits into
mainfrom
worktree-fix-agent-cwd-detection
Mar 15, 2026
Merged

Fix agent CWD detection to read from CLI process instead of shell#66
selfcontained merged 3 commits into
mainfrom
worktree-fix-agent-cwd-detection

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)
  • End-to-end verified with live dev server: post-log-message agent now correctly shows worktree: post-log-guidance and branch worktree-post-log-guidance (was showing "main repository" / branch "main")

🤖 Generated with Claude Code

selfcontained and others added 3 commits March 15, 2026 16:05
tmux pane_current_path only tracks the shell's working directory, 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.

Walk the process tree to find the agent CLI child process and read its
actual CWD via lsof, falling back to pane_current_path when the CLI
process can't be found.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Remove the "Git" label, "Repository"/"Worktree" badge, and
"main repository" text. Now shows only:
1. Branch name (with tooltip)
2. Worktree name — only when in a linked worktree (with tooltip
   showing the full worktree path)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@selfcontained
selfcontained merged commit 35129ed into main Mar 15, 2026
1 check passed
@selfcontained
selfcontained deleted the worktree-fix-agent-cwd-detection branch March 15, 2026 22:43
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