[FEATURE] Emit OSC 7 on agent-focus-change so new terminal tabs inherit the focused agent's cwd
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When running multiple background agents via the agent view, each agent has its own working directory (often a different subdirectory of the repo). The outer terminal that hosts claude only ever sees the cwd of the shell that spawned it, so opening a new tab/split lands in the launch directory regardless of which agent is currently focused.
Proposed Solution
It would be great if Claude Code emitted an OSC 7 escape sequence to the host terminal whenever the focused agent changes (and on initial focus), reporting that agent's cwd. Terminals that honour OSC 7 (iTerm2, Terminal.app, WezTerm, Ghostty, Kitty, …) would then open new tabs in the focused agent's directory — which is almost always what you want when juggling agents across subdirectories.
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
I keep my repos under ~/projects/. I launch claude from there and dispatch two agents, each scoped to a different project:
- one in
~/projects/acme-api/— fixing a failing test - one in
~/projects/acme-web/— implementing a UI tweak
Step by step today:
- In the agent view, I focus the
acme-apiagent to watch it work. - I want a real shell next to it to run the failing test myself, so I hit ⌘T in iTerm.
- The new tab opens at
~/projects/— not~/projects/acme-api/. - I type
cd acme-api && pytest tests/test_orders.py. Then later, when I switch focus toacme-weband ⌘T again, I have to remember tocd acme-web— and occasionally I run the wrong project's tooling in the wrong repo.
With OSC 7 on focus-change:
- Focus the
acme-apiagent → ⌘T → new tab is in~/projects/acme-api/. Runpytestdirectly. - Switch focus to
acme-web→ ⌘T → new tab is in~/projects/acme-web/. Runnpm run devdirectly.
Zero cds, no wrong-repo mistakes.
Additional Context
Adjacent gap: there's no hook event for agent-focus-change either (CwdChanged only fires within a session). Exposing such a hook would let users script this themselves if a built-in OSC 7 emit isn't desirable.
Related: #61546 (launch-time cwd in Agent View TUI) — same problem space, different point in the lifecycle.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗