claude-code - 💡(How to fix) Fix [FEATURE] Emit OSC 7 on agent-focus-change so new terminal tabs inherit the focused agent's cwd

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix / Workaround

I keep my repos under ~/projects/. I launch claude from there and dispatch two agents, each scoped to a different project:

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING