{"slug": "claude-code-extension-fix-auto-attach-version-2-1-273", "title": "Claude Code Extension: Fix Auto-Attach (Version 2.1.273+)", "summary": "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.", "body_md": "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).\n\nMinimal patcher. Verified on `anthropic.claude-code-2.1.273`.\n\nEdits `webview/index.js` in every installed Claude Code extension with version **≥ 2.1.273**:\n\n```\napplySelectionUpdate($){          →   applySelectionUpdate($){/*no-auto-ctx*/$=void 0;\n```\n\n`applySelectionUpdate` is the only writer of `session.selection`, which `send()` turns into the\n`<ide_opened_file>` / `<ide_selection>` block. Nulling its argument means nothing is ever\nattached and the footer \"Showing Claude your current file selection\" chip never appears.\n`@`-mentions and drag/drop attachments are unaffected.\n\n- Backup written to `index.js.orig` before patching (never overwritten on rerun).\n- Refuses to write unless the anchor matches exactly once.\n- Idempotent: rerun skips already-patched files.\n- Older versions (< 2.1.273) skipped.\n\nSearched dirs: `~/.vscode`, `~/.vscode-oss`, `~/.vscode-server`, `~/.vscode-insiders`.\n\n```\npython3 patch.py\n```\n\nThen **Developer: Reload Window** in VS Code.\n\nRevert:\n\n```\ncd ~/.vscode/extensions/anthropic.claude-code-<ver>/webview && mv index.js.orig index.js\n```\n\nUpdate replaces the extension directory → rerun `patch.py`. Or disable auto-update for the\nextension (Extensions view → gear → \"Ignore Updates\").\n\nTerminal `claude` CLI connected to the IDE via MCP — the CLI binary builds the tag itself.\n\n``` bash\n#!/usr/bin/env python3\n\"\"\"\nDisable auto-attached <ide_opened_file>/<ide_selection> context in the\nClaude Code VS Code extension webview.\n\nPatch: applySelectionUpdate($){  ->  applySelectionUpdate($){$=void 0;\n\nOnly touches extensions with version >= 2.1.273. Backs up to index.js.orig first.\n\"\"\"\nimport glob\nimport json\nimport os\nimport re\nimport shutil\nimport sys\n\nMIN_VERSION = (2, 1, 273)\nMARK = \"/*no-auto-ctx*/\"\nANCHOR = re.compile(r\"applySelectionUpdate\\((?P<p>[A-Za-z0-9_$]+)\\)\\{\")\n\nEXT_DIRS = [\n    \"~/.vscode/extensions\",\n    \"~/.vscode-oss/extensions\",\n    \"~/.vscode-server/extensions\",\n    \"~/.vscode-insiders/extensions\",\n]\n\ndef ext_version(ext_dir):\n    with open(os.path.join(ext_dir, \"package.json\"), encoding=\"utf-8\") as f:\n        v = json.load(f)[\"version\"]\n    return tuple(int(x) for x in v.split(\".\")[:3])\n\ndef patch(ext_dir):\n    path = os.path.join(ext_dir, \"webview\", \"index.js\")\n    if not os.path.isfile(path):\n        return 0\n\n    v = ext_version(ext_dir)\n    if v < MIN_VERSION:\n        print(f\"[skip] {'.'.join(map(str, v))} < 2.1.273: {path}\")\n        return 0\n\n    with open(path, encoding=\"utf-8\") as f:\n        src = f.read()\n\n    if MARK in src:\n        print(f\"[skip] already patched: {path}\")\n        return 0\n\n    matches = list(ANCHOR.finditer(src))\n    if len(matches) != 1:\n        print(f\"[fail] expected 1 anchor, found {len(matches)}: {path}\", file=sys.stderr)\n        return 1\n\n    m = matches[0]\n    patched = src[: m.start()] + f\"applySelectionUpdate({m.group('p')}){{{MARK}{m.group('p')}=void 0;\" + src[m.end():]\n\n    bak = path + \".orig\"\n    if not os.path.exists(bak):\n        shutil.copy2(path, bak)\n    with open(path, \"w\", encoding=\"utf-8\") as f:\n        f.write(patched)\n    print(f\"[ok]   patched: {path}  (backup: {bak})\")\n    return 0\n\ndef main():\n    dirs = []\n    for d in EXT_DIRS:\n        dirs.extend(glob.glob(os.path.join(os.path.expanduser(d), \"anthropic.claude-code-*\")))\n    if not dirs:\n        print(\"no claude-code extension found\", file=sys.stderr)\n        return 1\n    return max(patch(d) for d in sorted(dirs))\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n```\n\n", "url": "https://wpnews.pro/news/claude-code-extension-fix-auto-attach-version-2-1-273", "canonical_source": "https://gist.github.com/Morpheus0x/1dc3d4a5eac6674fbc05dd3b7f5f454e", "published_at": "2026-09-16 02:16:05+00:00", "updated_at": "2026-09-17 08:23:37.004775+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents"], "entities": ["Claude Code", "Anthropic", "Visual Studio Code", "MCP"], "alternates": {"html": "https://wpnews.pro/news/claude-code-extension-fix-auto-attach-version-2-1-273", "markdown": "https://wpnews.pro/news/claude-code-extension-fix-auto-attach-version-2-1-273.md", "text": "https://wpnews.pro/news/claude-code-extension-fix-auto-attach-version-2-1-273.txt", "jsonld": "https://wpnews.pro/news/claude-code-extension-fix-auto-attach-version-2-1-273.jsonld"}}