[FEATURE] Emit OSC 7 on agent-focus-change so new terminal tabs inherit the focused agent's cwd

Resolved 💬 1 comment Opened May 26, 2026 by TomNaessens Closed Jun 27, 2026

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:

  1. In the agent view, I focus the acme-api agent to watch it work.
  2. I want a real shell next to it to run the failing test myself, so I hit ⌘T in iTerm.
  3. The new tab opens at ~/projects/ — not ~/projects/acme-api/.
  4. I type cd acme-api && pytest tests/test_orders.py. Then later, when I switch focus to acme-web and ⌘T again, I have to remember to cd acme-web — and occasionally I run the wrong project's tooling in the wrong repo.

With OSC 7 on focus-change:

  1. Focus the acme-api agent → ⌘T → new tab is in ~/projects/acme-api/. Run pytest directly.
  2. Switch focus to acme-web → ⌘T → new tab is in ~/projects/acme-web/. Run npm run dev directly.

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.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗