# Claude Code Extension: Fix Auto-Attach (Version 2.1.273+)

> Source: <https://gist.github.com/Morpheus0x/1dc3d4a5eac6674fbc05dd3b7f5f454e>
> Published: 2026-09-16 02:16:05+00:00

This is the latest fix for the stupid, annoying file attachment "feature" in claude code. I tested if it only is a visual fix by asking claude for the important information inside the open file in vs code. The following is the readme and python script for the fix (created by claude code, using caveman plugin).

Minimal patcher. Verified on `anthropic.claude-code-2.1.273`.

Edits `webview/index.js` in every installed Claude Code extension with version **≥ 2.1.273**:

```
applySelectionUpdate($){          →   applySelectionUpdate($){/*no-auto-ctx*/$=void 0;
```

`applySelectionUpdate` is the only writer of `session.selection`, which `send()` turns into the
`<ide_opened_file>` / `<ide_selection>` block. Nulling its argument means nothing is ever
attached and the footer "Showing Claude your current file selection" chip never appears.
`@`-mentions and drag/drop attachments are unaffected.

- Backup written to `index.js.orig` before patching (never overwritten on rerun).
- Refuses to write unless the anchor matches exactly once.
- Idempotent: rerun skips already-patched files.
- Older versions (< 2.1.273) skipped.

Searched dirs: `~/.vscode`, `~/.vscode-oss`, `~/.vscode-server`, `~/.vscode-insiders`.

```
python3 patch.py
```

Then **Developer: Reload Window** in VS Code.

Revert:

```
cd ~/.vscode/extensions/anthropic.claude-code-<ver>/webview && mv index.js.orig index.js
```

Update replaces the extension directory → rerun `patch.py`. Or disable auto-update for the
extension (Extensions view → gear → "Ignore Updates").

Terminal `claude` CLI connected to the IDE via MCP — the CLI binary builds the tag itself.

``` bash
#!/usr/bin/env python3
"""
Disable auto-attached <ide_opened_file>/<ide_selection> context in the
Claude Code VS Code extension webview.

Patch: applySelectionUpdate($){  ->  applySelectionUpdate($){$=void 0;

Only touches extensions with version >= 2.1.273. Backs up to index.js.orig first.
"""
import glob
import json
import os
import re
import shutil
import sys

MIN_VERSION = (2, 1, 273)
MARK = "/*no-auto-ctx*/"
ANCHOR = re.compile(r"applySelectionUpdate\((?P<p>[A-Za-z0-9_$]+)\)\{")

EXT_DIRS = [
    "~/.vscode/extensions",
    "~/.vscode-oss/extensions",
    "~/.vscode-server/extensions",
    "~/.vscode-insiders/extensions",
]

def ext_version(ext_dir):
    with open(os.path.join(ext_dir, "package.json"), encoding="utf-8") as f:
        v = json.load(f)["version"]
    return tuple(int(x) for x in v.split(".")[:3])

def patch(ext_dir):
    path = os.path.join(ext_dir, "webview", "index.js")
    if not os.path.isfile(path):
        return 0

    v = ext_version(ext_dir)
    if v < MIN_VERSION:
        print(f"[skip] {'.'.join(map(str, v))} < 2.1.273: {path}")
        return 0

    with open(path, encoding="utf-8") as f:
        src = f.read()

    if MARK in src:
        print(f"[skip] already patched: {path}")
        return 0

    matches = list(ANCHOR.finditer(src))
    if len(matches) != 1:
        print(f"[fail] expected 1 anchor, found {len(matches)}: {path}", file=sys.stderr)
        return 1

    m = matches[0]
    patched = src[: m.start()] + f"applySelectionUpdate({m.group('p')}){{{MARK}{m.group('p')}=void 0;" + src[m.end():]

    bak = path + ".orig"
    if not os.path.exists(bak):
        shutil.copy2(path, bak)
    with open(path, "w", encoding="utf-8") as f:
        f.write(patched)
    print(f"[ok]   patched: {path}  (backup: {bak})")
    return 0

def main():
    dirs = []
    for d in EXT_DIRS:
        dirs.extend(glob.glob(os.path.join(os.path.expanduser(d), "anthropic.claude-code-*")))
    if not dirs:
        print("no claude-code extension found", file=sys.stderr)
        return 1
    return max(patch(d) for d in sorted(dirs))

if __name__ == "__main__":
    sys.exit(main())
```


