[BUG] VS Code terminal steals focus even when running Claude Code externally with /ide (terminal not open)

Status Open
Maintainer reply None cached
Activity 22 comments · opened Sep 15, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When using Claude Code in an external terminal, while connected to VS Code with the /ide command, VS Code opens the integrated terminal and steals focus upon prompt submission in the external terminal.

What Should Happen?

With CLI running externally, VS Code should not reveal/focus the integrated terminal unless I explicitly open it.

Error Messages/Logs

2025-09-14 21:36:07.286 [info] Unregistered diagnostic client: client_5
2025-09-14 21:44:18.197 [info] New WS connection from: /
2025-09-14 21:44:18.198 [info] MCP server connected to transport
2025-09-14 21:44:18.198 [info] [DiagnosticStreamManager] Started streaming diagnostics
2025-09-14 21:44:18.198 [info] Registered diagnostic client: client_6
2025-09-14 21:44:19.296 [info] Closing all diff tabs in the editor...
2025-09-14 21:44:19.297 [info] Closed 0 diff tabs.
2025-09-14 21:44:19.871 [info] [DiagnosticStreamManager] Notifying 1 clients about diagnostics change for 1 files
2025-09-14 21:44:21.963 [info] WS client disconnected
2025-09-14 21:44:21.964 [info] [DiagnosticStreamManager] Unregistered client client_6. Total clients: 0
2025-09-14 21:44:21.964 [info] [DiagnosticStreamManager] Stopped streaming diagnostics
2025-09-14 21:44:21.964 [info] Unregistered diagnostic client: client_6
2025-09-14 21:45:02.704 [info] New WS connection from: /
2025-09-14 21:45:02.704 [info] MCP server connected to transport
2025-09-14 21:45:02.704 [info] [DiagnosticStreamManager] Started streaming diagnostics
2025-09-14 21:45:02.704 [info] Registered diagnostic client: client_7
2025-09-14 21:45:10.698 [info] Closing all diff tabs in the editor...
2025-09-14 21:45:10.698 [info] Closed 0 diff tabs.
2025-09-14 21:45:11.272 [info] [DiagnosticStreamManager] Notifying 1 clients about diagnostics change for 1 files

Steps to Reproduce

  1. Open VS Code with a workspace.
  2. Ensure the integrated terminal is closed.
  3. In an external terminal, run claude from the workspace root and connect with /ide.
  4. Type a prompt and press Enter.
  5. Tab back to VS Code and observe that the integrated terminal is now open.

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

Unsure

Claude Code Version

1.0.113

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other

Additional Information

Attached logs are from the CC extension in VS code.

GhostTTY Version Info:

Version: 1.1.3
Build: 9438
Commit: 889478f3

VS Code Version Info:

Version: 1.104.0 (Universal)
Commit: f220831ea2d946c0dcb0f3eaa480eb435a2c1260
Date: 2025-09-10T06:46:18.035Z
Electron: 37.3.1
ElectronBuildId: 12342881
Chromium: 138.0.7204.235
Node.js: 22.18.0
V8: 13.8.258.31-electron.0
OS: Darwin arm64 24.6.0

View original on GitHub ↗

22 Comments

github-actions[bot] · 1 year ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/1591
  2. https://github.com/anthropics/claude-code/issues/3419
  3. https://github.com/anthropics/claude-code/issues/6919

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

openclosure · 1 year ago

Not a duplicate. There are several references to this bug in JetBrains products but I haven't seen a report of this for VS Code/Cursor.

dzhlobo · 1 year ago

I can confirm the bug report, I observe the same behaviour.

I use latest Ghostty from main branch (version 0c63946bd, build 12105).

Claude Code version 1.0.112 (Claude Code).

VSCode version info:

Version: 1.104.0
Commit: f220831ea2d946c0dcb0f3eaa480eb435a2c1260
Date: 2025-09-10T06:46:18.035Z (5 days ago)
Electron: 37.3.1
ElectronBuildId: 12342881
Chromium: 138.0.7204.235
Node.js: 22.18.0
V8: 13.8.258.31-electron.0
OS: Darwin arm64 24.6.0
TouchSeyha · 11 months ago

Just confirming that this bug is still reproducible in November with Claude Code CLI 2.0.31.
The issue reported back in September seems to persist in the current release. But I'm using window platform.

dhaern · 11 months ago

Claude Code v2.0.36 and confirming this bug AGAIN, can you work a bit more instead doing nothing please?

github-actions[bot] · 10 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

etrippler · 10 months ago

This issue is still occuring!

Jay-523 · 10 months ago

Able to reproduce this issue with warp and cursor

MartinLoeper · 9 months ago

I think the best workaround here would be to just introduce a new vscode extension setting to opt-out of the current behaviour which seems to open the terminal panel and focus it.

ankit-kapur · 9 months ago

Still occurring, please fix

dcrew44 · 8 months ago

Still occurring, please fix

JoshChapnick · 8 months ago

Still running into this - please fix

ezeqviel · 8 months ago

issue persists on 2.1.42

jdvolk · 7 months ago

also confirming this. is there a way to disconnect clude-cli from the claude extention in vs code?

Nick-Lucas · 6 months ago

Happening for me on 2.1.79

yurukusa · 6 months ago

The focus-stealing happens because the /ide connection triggers VS Code to open/activate its terminal panel. Workarounds:
Workaround 1 — Prevent terminal auto-focus in VS Code:

// VS Code settings.json
{
  "terminal.integrated.focusAfterRun": "none",
  "terminal.integrated.showExitAlert": false
}

This prevents VS Code from auto-focusing the terminal panel when Claude Code sends commands through the IDE integration.
Workaround 2 — Use a separate VS Code window:
Keep your code in one VS Code window and let Claude's /ide connection go to a different window. Focus changes in the second window won't interrupt your work in the first.
Workaround 3 — Don't use /ide, use file paths instead:
If you primarily need Claude to edit files, it can do so via the Edit/Write tools without IDE integration:

<!-- CLAUDE.md -->
Edit files directly using the Edit tool. Do not use IDE integration.

The /ide connection is mainly useful for features like "go to definition" and inline diffs. If you don't need those, skipping /ide avoids the focus issue entirely.
Workaround 4 — Use the VS Code extension instead of external terminal + /ide:
The Native UI mode in the extension handles IDE integration without the focus-stealing issue, since Claude runs inside VS Code natively.

barafael · 6 months ago

now, (for me), it happens _twice_, on startup. That's quite disruptive.

dmcconachie · 6 months ago

https://github.com/anthropics/claude-code/issues/7618#issuecomment-4159655672

(1) does not work; see https://github.com/anthropics/claude-code/issues/23713 for an explanation

(2) This is very awkward; now I'm juggling 3 windows (VSCode 1 where I do my work, VSCode 2 whose only purpose is to feed context to CC, an external terminal running claude code). Also VSCode doesn't really like to have 2 windows open to the same project as far as I know, though I haven't tried it in some time. Historically the only way I've managed to do it was to have one window open to the folder, one window open to a VSCode workspace in the same folder.

(3) That also defeats the entire purpose of having ide integration. "Don't use the thing" is not a workaround

(4) Also defeats the entire purpose of /ide integration

PhilChen-6765 · 5 months ago

Still reproducible on Claude Code v2.1.126 / VS Code Claude Code extension v2.1.126 (macOS).

Environment

  • OS: macOS
  • External terminal: Ghostty
  • Claude Code CLI: v2.1.126
  • VS Code with Claude Code extension v2.1.126

Reproduction

  1. Run claude in Ghostty
  2. /ide → "Connected to Visual Studio Code"
  3. Send any prompt — even one that doesn't trigger any tool call
  4. VS Code's integrated terminal panel pops open / steals focus
  5. Happens on every prompt

New finding — narrows down the trigger
The pop-up only happens if at least one integrated terminal instance already exists in the current VS Code
session. Specifically:

| State of VS Code's integrated terminal | Pop-up on prompt? |
|---|---|
| Never opened in this VS Code session | ✅ No pop-up |
| Opened before, then hidden (Cmd+J) | ❌ Pops back |
| Opened and visible | ❌ Steals focus |

Workaround: restart VS Code and never manually open an integrated terminal. The pop-up does not occur as long as no
terminal instance exists.

grubstarstar · 4 months ago

This used to work a few weeks ago for me. Certainly way after the opening of this ticket. But it's been doing it every time for the last few weeks. I don't know the exact version.

samehhashy · 3 months ago

Almost a year later and this is still an issue.

nlebedenco · 21 days ago

Fable traced this in the current release (CLI 2.1.280, VS Code extension 2.1.280 linux-x64) and the focus grab does not depend on a diff or file being open. It is a two-step sequence between the CLI and the extension.

1. The CLI asks the extension to close all diff tabs at query start, unconditionally.

In the CLI bundle, when an IDE client is connected, the query start path calls a wrapper that sends the closeAllDiffTabs IDE RPC:

``js
async function LXr(e){try{await RAn("closeAllDiffTabs",{},e)}catch(o){}}
...
let En=ut.computeMcpClients();Phe.of(pt).handleQueryStart(En);let hr=QD(En);if(hr)LXr(hr)
``

It is sent whether or not any diff tab exists, which is why the extension log in the original report shows "Closing all diff tabs in the editor... Closed 0 diff tabs." right before focus moves.

2. The extension focuses the active terminal 500 ms after handling that RPC.

In extension.js the closeAllDiffTabs and close_tab tool handlers both schedule a helper that calls Terminal.show() on the active terminal without preserveFocus:

``js
function dQ(){try{let $=_14.window.activeTerminal;if($)$.show()}catch($){console.error("Error focusing terminal:",$)}}
...
K.tool("close_tab",{tab_name:j$.string()},async({tab_name:j})=>{return await $64(j,X),setTimeout(()=>{dQ()},500),{content:[{type:"text",text:"TAB_CLOSED"}]}})
K.tool("closeAllDiffTabs","Close all diff tabs in the editor",{},async()=>{let j=await e14(X);return setTimeout(()=>{dQ()},500),{content:[...
``

Terminal.show() with no argument takes keyboard focus. The same helper also runs after a diff is opened and when a diff is accepted or rejected, but the query-start path is the one that fires with
nothing open.

Effect

  • CLI in an external terminal with /ide (this issue): the VS Code terminal panel is revealed and focused even though the CLI is not running in it.
  • CLI in the VS Code integrated terminal: focus jumps from the editor you are typing in to the CLI prompt whenever a query starts, including mid-turn.

No setting covers it. None of the claudeCode.* extension settings, ~/.claude.json keys (diffTool, autoConnectIde) or VS Code terminal settings change this path. The only way to stop it is
to disable the IDE connection entirely with CLAUDE_CODE_AUTO_CONNECT_IDE=false, which also removes diffs, selection context and diagnostics.

Suggested fix

  • Extension: do not call activeTerminal.show() from the closeAllDiffTabs and close_tab handlers, or at least skip it when zero tabs were closed. Where the terminal is intentionally re-shown

after a diff is accepted or rejected, pass show(true) (preserveFocus) or gate it on a setting.

  • CLI: skip the closeAllDiffTabs RPC at query start when no diff was opened during the session.

Related: #23713 describes the terminal.show() behaviour in prose, and #87053 is the consolidated tracking issue.