Every time you open a new chat in Claude Code extension, it automatically attaches your currently-open file as context.
This wastes tokens, can leak sensitive files (like .env), and adds noise to every prompt.
This guide shows you how to turn off that feature.
Based on community fix from:
Important
Disable auto-update for the "Claude Code for VS Code" extension, otherwise auto-updates will silently overwrite your patched file.
Go to the Extensions tab (Ctrl+Shift+X / Cmd+Shift+X), find "Claude Code for VS Code", and uncheck Auto Update.
When you want to update:
- Disable "Claude Code for VS Code" extension
- Update to the latest version
- Re-enable the extension
- Restart Extension
- Re-run the script
-
Download or save the script to a file, e.g.
fix-auto-attach.ps1. -
Open PowerShell in the folder where you saved the script and run:
# The -Force parameter skips the user confirmation prompt to speed things up Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force .\fix-auto-attach.ps1
Or apply directly with a one-liner (no script download needed). The script auto-detects your bundle format (legacy ≤2.1.177 vs modern ≥2.1.211), but for the one-liner use:
$f = (Get-ChildItem "$env:USERPROFILE\.vscode\extensions\anthropic.claude-code-*\webview\index.js" -Recurse | Select-Object -Last 1).FullName; $c = Get-Content $f -Raw; if ($c -match '=(\w+)\.useRef\(!0\),\[(\w+),(\w+)\]=(\w+)\.useState\(!0\)') { $c = $c -replace '=(\w+)\.useRef\(!0\),\[(\w+),(\w+)\]=(\w+)\.useState\(!0\)', '=$1.useRef(!0),[$2,$3]=$4.useState(!1)' } else { $c = $c -replace '=(\w+)\(!0\),\[(\w+),(\w+)\]=(\w+)\(!0\)', '=$1(!0),[$2,$3]=$4(!1)' }; Set-Content $f $c -NoNewline
❗ Important: For Cursor replace
\.vscodewith\.cursor, and for VSCodium with\.vscode-oss.Custom path & dry run:
# Preview the patch against a specific bundle without writing anything .\fix-auto-attach.ps1 -Path "C:\path\to\index.js" -DryRun # Apply to a specific bundle (a file, or a directory containing webview\index.js) .\fix-auto-attach.ps1 -Path "C:\path\to\index.js"
-
Reload VS Code / VSCodium / Cursor:
- Press
Ctrl+Shift+P - Type and run: Developer: Reload Window
- Press
Run the fix in one command (auto-detects legacy ≤2.1.177 vs modern ≥2.1.211 format):
WV=$(find ~/.vscode{,-server}/extensions -path '*anthropic.claude-code-*/webview/index.js' 2>/dev/null | tail -1)
cp "$WV" "$WV.bak"
perl -i -pe 'if(s{useRef\(!0\),\[(\w+),(\w+)\]=(\w+)\.useState\(!0\)}{useRef(!0),[$1,$2]=$3.useState(!1)}){}else{s{=(\w+)\(!0\),\[(\w+),(\w+)\]=(\w+)\(!0\)}{=$1(!0),[$2,$3]=$4(!1)}}' "$WV"❗ Important: For Cursor replace ~/.vscode with ~/.cursor, and for VSCodium replace with ~/.vscode-oss.
Then press Cmd+Shift+P → Developer: Reload Window.
Caution
🚨 USE AT YOUR OWN RISK! 🚨
If you want to be absolutely certain that files can't be auto-injected – even if you accidentally click the toggle – use Hardcore mode. It removes the injection code entirely. The toggle button remains visible but does nothing.
PowerShell:
.\fix-auto-attach.ps1 -HardcoreBash:
WV=$(find ~/.vscode{,-server}/extensions -path '*anthropic.claude-code-*/webview/index.js' 2>/dev/null | tail -1)
cp "$WV" "$WV.bak"
perl -0 -i -pe 's{if\(([A-Za-z_\$][\w\$]*)\)if\(\1\.selectedText\)([A-Za-z_\$][\w\$]*)\.push\(\{type:"text",text:`<ide_selection>[\s\S]*?</ide_selection>`\}\);else \2\.push\(\{type:"text",text:`<ide_opened_file>[\s\S]*?</ide_opened_file>`\}\);}{}g' "$WV"❗ Important: For Cursor replace ~/.vscode with ~/.cursor, and for VSCodium replace with ~/.vscode-oss.
Then Developer: Reload Window (Ctrl+Shift+P / Cmd+Shift+P).
Want to undo the patch? Restore the backup and reload:
PowerShell:
Get-ChildItem "$env:USERPROFILE\.vscode\extensions\anthropic.claude-code-*\webview\index.js.bak" | ForEach-Object {
Copy-Item -Path $_.FullName -Destination (Join-Path $_.DirectoryName "index.js") -Force
}❗ Important: For Cursor replace \.vscode with \.cursor, and for VSCodium with \.vscode-oss.
Bash:
WV=$(find ~/.vscode{,-server}/extensions -path '*anthropic.claude-code-*/webview/index.js' 2>/dev/null | tail -1) && cp -f "$WV.bak" "$WV"❗ Important: For Cursor replace ~/.vscode with ~/.cursor, and for VSCodium replace with ~/.vscode-oss.
Then Developer: Reload Window (Ctrl+Shift+P / Cmd+Shift+P).
Note
If the extension auto-updated since you applied the patch, the .bak file may be a version behind and causing errors when the extension runs.
In that case, reinstall the extension to get a fresh index.js, or download the same version manually from Open VSX (under Resources) and copy webview/index.js into the extension's webview/ folder.
The Claude Code webview uses React state (useState(true)) to decide whether to inject the open file. The patch flips the default to useState(false). That's it. The toggle button still works – you can turn attachment ON for individual chats when you want it.
No. The patch only changes a default value. All features remain functional. The only difference: your open file won't be auto-attached to new conversations.
Auto-updates revert the patch because the extension files get replaced. After an update, just run the script again. The script tells you if the pattern wasn't found.
The script tries two patterns — legacy (≤2.1.177, namespace hooks like Ke.useRef) and modern (≥2.1.211, direct aliases like Se=useRef). If both fail, the extension was updated and the variable names changed.
To debug, unpack the bundle with webcrack:
npx webcrack <path-to-webview>/index.js -o ./unpackedThen search for ide_opened_file in ./unpacked/deobfuscated.js — the function containing it is your injection producer. Look for the React component that calls it; the chip's useState(!0) / ne(!0) is in that same component.
Check the original GitHub comment for updates, or file an issue linking back to it.
No. Only the automatic <ide_opened_file> and <ide_selection> injection. Manual attachments still work as expected.
Yes. The PowerShell script automatically searches .vscode, .vscode-server, .vscode-oss, .cursor, and .cursor-server extension directories and picks the most recent bundle.
| Action | Command |
|---|---|
| Apply fix (Windows) | .\fix-auto-attach.ps1 |
| Apply fix (Mac/Linux) | Run the perl one-liner above |
| Apply fix to a custom bundle | .\fix-auto-attach.ps1 -Path "C:\path\to\index.js" |
| Preview without writing (dry run) | .\fix-auto-attach.ps1 -DryRun |
| Hardcore mode (Windows) | .\fix-auto-attach.ps1 -Hardcore |
| Unpack bundle for inspection | npx webcrack <path>/index.js -o ./unpacked |
| Revert | Restore .bak file, reload window |
| Reload window | Ctrl+Shift+P → Developer: Reload Window |
The auto-attach chip state lives in a minified React component inside the extension's webview/index.js. There are two bundle formats the script handles:
Hooks called via a React namespace variable (e.g. Ke.useRef, Ke.useState):
_=Ke.useRef(!0),[v,x]=Ke.useState(!0) // true = ON by defaultThe patch flips the useState default:
_=Ke.useRef(!0),[v,x]=Ke.useState(!1) // false = OFF by defaultThe =Ke.useRef(!0) anchor (with leading =) uniquely identifies this useState among the many useState(!0) calls in the bundle.
Hooks destructured as local aliases (e.g. Se=useRef, ne=useState):
_=Se(!0),[C,y]=ne(!0) // true = ON by defaultPatched:
_=Se(!0),[C,y]=ne(!1) // false = OFF by defaultAgain the leading = anchors to the useRef-alias assignment, making the match unique.
The script auto-detects which format your bundle uses and applies the correct pattern. In both cases, the toggle button remains fully functional — only the default changes.
Tested on: Claude Code for VS Code 2.1.233