← Claude Code Hub
Nov 30, 2026 · 5 min read ✦ Tip #296

Claude Code in VS Code sends your selection with every message: how to stop it

Claude Code in VS Code adds whatever you have selected in the editor to every message, related or not. claudeCode.attachSelection turns that off, and Alt+K still brings in the lines you choose.

Claude Code in VS Code with Attach Selection on and off: by default the same 15 lines of src/auth.ts ride along with every message and add 867 tokens of context; with "claudeCode.attachSelection": false only the open file's path arrives, and Alt+K brings the lines in when you ask

TL;DR In VS Code's User settings, set "claudeCode.attachSelection": false. When you do want Claude to see a few lines, select them and press Option+K (Mac) or Alt+K (Windows/Linux).

claudeCode.attachSelection decides whether the text selected in your editor goes out with your message. It's on by default: every message you send carries the current selection, even when you ask about something else, and those lines stay in the history Claude re-reads on every turn. Since v2.1.300 you can turn it off, in the extension's panel and when you run claude in VS Code's integrated terminal.

What Claude receives

With 15 lines of src/auth.ts selected and an unrelated question, on Claude Code v2.1.332:

❯ Unrelated question: what is 17 * 3? Answer in one line.
  ⎿  ⧉ Selected 15 lines from src/auth.ts in Visual Studio Code
● 17 × 3 = 51

What reached the model with each of those messages, quoted verbatim by Claude when asked (path shortened, lines trimmed):

The user selected the lines 10 to 24 from …/proj/src/auth.ts:
  const step10 = await TokenService.check(user, 10); // line 10
  [... 13 more lines]
  const step24 = await TokenService.check(user, 24); // line 24
This may or may not be related to the current task.

The last sentence tells Claude it may ignore the lines, but they're already in context. Leave a function selected while you ask about a test, and Claude has both in front of it and tends to lean on the one it can see.

What it costs

Measured with Sonnet 5.5 on the same short message, from the session's .jsonl. Context added per message, which gets re-read on every later turn:

What rides along Context added
A large selection in the terminal (cut at 2,000 characters) 867 tokens
Only the open file's path (Attach Selection off) 105 tokens
Nothing (selection dropped for that message) 15 tokens

Where you run Claude Code changes the cap:

  • In the integrated terminal, the binary cuts the selection at 2,000 characters and adds ... (truncated). Tried with a 4,800-character selection.
  • In the panel, the 2.1.332 extension's code puts the whole selection into the message. It only warns before sending past about 500 KB on a model with a 200K context window: The selection is about 500 KB, which may be too much for Claude to read. A selected 300-line function goes out whole, message after message.

How to turn it off

1. From the Settings UI

Open Settings (Cmd+, / Ctrl+,), search for attachSelection and uncheck Claude Code: Attach Selection on the User tab. In the extension's code the change applies at once, with no window reload.

2. Or in your user settings.json

Command Palette, Preferences: Open User Settings (JSON):

{
  "claudeCode.attachSelection": false
}

It only works in User settings. The extension's package.json declares it with "scope": "application", so VS Code ignores the value in a project's .vscode/settings.json: you can't set it per repo, and a cloned repo can't flip it for you.

3. Bring lines in when you want them

Select and press Option+K (Mac) or Alt+K (Windows/Linux). It inserts a mention like @auth.ts#10-24 and Claude gets those lines, in that message only. Since v2.1.330 it sends the range, not the whole file or its first 2,000 lines.

4. For one message, without touching the setting

In the panel, the X beside the line count drops that selection; it comes back when you select different text. In the terminal, Backspace on the [⧉ 15 lines selected] pill leaves it out of that message.

What still arrives with it off

With Attach Open File on, the default, Claude gets the path of the file you have open. With Attach Selection off, this was all that arrived:

The user opened the file …/proj/src/auth.ts in the IDE. This may or may not be related to the current task.

If you don't want that either, turn off claudeCode.attachOpenFile (v2.1.271 or later). With both off, Claude doesn't know what you're looking at, so "explain this file" needs the file's name or Alt+K. It's the same trade as the @ that sends only the path: you decide what goes in, and you have to say it.

Sensitive files

Turning the setting off isn't protection: switch it back on and a .env selection travels again. What blocks it is a Read deny rule:

{ "permissions": { "deny": ["Read(./.env)"] } }

With that rule on src/auth.ts in the project's .claude/settings.json, Claude got nothing, neither the selection nor the path, even though the terminal pill still read 15 lines selected. The panel also withholds the text of files matching files.exclude, search.exclude or .gitignore; the integrated terminal doesn't.

When to keep it on

If you mostly ask about what's in front of you ("why does this fail", "rename this variable"), the selection is the fastest pointer and saves typing paths. If you leave text selected out of habit, run long sessions, or keep whole functions highlighted in the panel, turn it off and use Alt+K: code goes in when you ask for it. What else the panel does differently from the terminal is in the extension's native panel.

Official docs: Use Claude Code in VS Code

Requirements

  • The Claude Code extension for VS Code, with Claude Code v2.1.300 or later.
  • Tried on Claude Code v2.1.332 through the integrated-terminal path, with a stand-in for VS Code that sends what the 2.1.332 extension sends in each case; the panel's behavior comes from that extension's code.

Found this useful? See more of wmedia.es in your Google results.

Add wmedia.es as a preferred source on Google
FREE GUIDE

You don't need Opus every time.

Model and effort are two settings, not one. 8 pages with the settings that actually move your bill, a three-question diagnostic for when something fails, and the price ladder.

  • 1. What "better" means capability, time and money
  • 2. Model who you send
  • 3. Effort how much rope you give
  • 4. Diagnostic three questions when something fails
  • 5. The bill where it comes from
Are you a professional Web developer?

You'll receive the guide by email · Unsubscribe anytime

of 8
#

Wmedia · 8 pages
FREE GUIDE · 8 pages · 2 dials

You don't need Opus every time.

Model and effort are two settings, not one. 8 pages with the settings that actually move your bill, a three-question diagnostic for when something fails, and the price ladder.

Are you a professional Web developer? · Unsubscribe anytime

Using Opus for everything? See when you don't need it.