cd /news/ai-tools/claude-code-extension-fix-auto-attac… · home topics ai-tools article
[ARTICLE · art-132383] src=gist.github.com ↗ pub= topic=ai-tools verified=true sentiment=· neutral

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

A developer published a minimal Python patcher that disables the Claude Code VS Code extension's automatic file-context attachment by nulling the argument to applySelectionUpdate in webview/index.js, preventing the <ide_opened_file> and <ide_selection> blocks from being sent. The script targets extension versions 2.1.273 and later, backs up the original file, verifies a single anchor match before writing, and is idempotent on reruns; @-mentions and drag-and-drop attachments are unaffected.

by read2 min views1 publishedSep 16, 2026

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.

#!/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())
── more in #ai-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/claude-code-extensio…] indexed:0 read:2min 2026-09-16 ·