[BUG] `ide_selection` broken when filename starts with square brackets
Status Open
Reported on v2.1.215
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 4 comments · opened Jul 20, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When selecting multiple lines with a file with a filename built like [<string>].<ext>, the Claude Code VSCode extension doesn't see the ide selection (it just sees the file)
What Should Happen?
The extension should be able to see the the ide selection of the lines
Error Messages/Logs
Steps to Reproduce
- Create a file
[<string>].<ext>, for example [id].tsx - Add a few random lines to it
- Try to select some of them
- You'd see that the ide selection is not ok
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.215
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Other
Additional Information
_No response_
4 Comments
Confirming this on macOS, and I traced the root cause. The scope is broader than the title suggests.
It's not limited to filenames, or to leading brackets. The trigger is any glob metacharacter anywhere in the path — including a directory several levels above a plainly-named file. My case is
src/routes/{-$locale}/perimenopause/visits/book/index.tsx: the filename is an ordinaryindex.tsx, and the offending segment is a TanStack Router optional-segment directory. Braces fail exactly like brackets.Root cause
pfr()inextension.jsdecides whether a file is hidden/ignored by feeding the file's own relative path back intofindFilesas a glob pattern:A path containing
{}or[]does not self-match as a glob —{-$locale}parses as brace alternation,[id]as a character class.findFilesreturns 0 results, so the function returnstrue, "ignored".That result flows into the selection builder, which omits
selectedTextfor ignored files:Note that the
git check-ignorecall further down inpfr()answers this question correctly — it's just gated behind the brokenfindFilesprobe, which returns early.Secondary issue
The webview picks its tag based on the presence of
selectedText:nZ()computed correctstartLine/endLineand they're discarded here. Even for a genuinely gitignored file this is worse than lossy — it tells the model the file was merely "opened" when the user actually selected a range. Emitting<ide_selection>with the line range and omitting only the text would preserve the signal, and would have made this bug visible instead of silent.Verification
Against ripgrep, the engine backing
findFiles— each path is globbed against itself:Escaping the metacharacters (
[{]-$locale[}]) restores the match.git check-ignoreon the affected files exits 1 — they are not ignored.Suggested fix
Escape glob metacharacters (
{},[],*,?) inrbefore building theRelativePattern, or drop thefindFilesprobe entirely and rely on thegit check-ignorecall already present.Workaround
Alt+K(claude-vscode.insertAtMention) works on affected files — it bypasses the ignore check, and the@-mention resolver handles the metacharacters correctly.Environment
anthropic.claude-code-2.1.237-darwin-arm64, VS Code 1.134.0, macOS 26.6.2 arm64 — so this is not Windows-specific (issue is currently labeledplatform:windows) and is still present in 2.1.237.Identifiers above (
pfr,nZ) are from the minified bundle in that build.Possibly related
#83861 and #37392 are the same class of defect in the chat-link handler (paths with square brackets, e.g. Next.js
[locale]folders). A path-escaping audit would likely cover all of these together.@HiiiiD @kyle-pomelo hey, it seems this is fixed now in the latest version of vscode (1.139.0 as of now), can you confirm this? #83861 and #37392 however are still an issue.
I think it's fixed now (I still have an older vscode (1.133.0), but I updated the CC extension, which was probably the fault)
Confirmed fixed! Thank you!