You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IDE/editor context persists after closing file #24184
Since 1.14.23, OpenCode shows the currently-open file in the TUI prompt area, e.g. testfile.py.
Problem:
When I close that file in the editor, OpenCode keeps showing/injecting the old file context. The LLM then assumes my unrelated prompt is about that stale file and tries to modify it.
Expected:
When the active editor file is closed, OpenCode should clear the editor context and stop injecting "user opened this file" or equivalent context into the prompt.
Plugins
No response
OpenCode version
1.14.23
Steps to reproduce
Open opencode in VSCode terminal
Open a file, select something in it. Filename should appear at the botton of opencode
Close this file, the filename doesn't disappear.
Screenshot and/or share link
we open file, testfile.py appears near the bottom:
I am also seeing the same issue in WSL. There is no obvious way around it, because once a selection is made it sticks, even if you then start opencode from the terminal.
I asked opencode to analyse the issue. This is what it diagnosed and i can confirm the workaround works
Root Cause
The editor.ts context introduced in v1.14.23 scans ~/.claude/ide/*.lock files — these are written by the Claude Code VS Code extension (not OpenCode's own extension). It finds the lock file for your workspace, opens a WebSocket to VS Code, and subscribes to selection_changed events.
The bug is that store.selection is never cleared. When you close the file or move away in VS Code, the WebSocket either goes silent (no selection_changed event fires to null the selection) or the connection drops and reconnects — but on reconnect there's no "clear selection" event, so the last known value persists in the store indefinitely.
Workarounds (no downgrade needed)
Most effective — delete the lock files: rm ~/.claude/ide/*.lock
I have a PR that addresses part of this behaviour #24323
but for what it's worth claude code extension never emits the info that the files are closed unfortunately
Thank you for identifing the root cause. I disbaled Claude Code extension in VSCode until this if fixed
thank for this report, acknowledged, I know what the issue is and I will fix it asap! will be fixed in the next version (either tonight or tomorrow morning)
by the way, if this feature worked as expected, do you find this feature useful?
@jlongster yes definitely. It worked great the first time i used it in a single focussed session. and after looking through your PR work i think theres tons of value with a nicely exposed API for other plugins to tap into.
I would find it quite useful. Even better if I could highlight a specific part of the file, like a function or whatever, and OC would see the file and my highlighted text. Could be a nice way to point it to specific things.
But as long as there is no stale context after closing the file, everything else is a bonus.
Thanks for quick response.
Even better if I could highlight a specific part of the file, like a function or whatever, and OC would see the file and my highlighted text
@gabethehuman that's exactly what it does! if you select some code you'll see the filename + the selected range and it will send that file, selection range, and the highlighted section as text as context
Sorry if this is a stupid question, but is there a way to disable this? My vscode is rarely ever in-sync with what im doing in opencode so it kinda seems like context pollution for those that dont want it.
Reacted by Vinícius Gonçalves de Oliveira, Gabriel Filipek and SD
#24661 improves this feature and adds the ability to disable it
The PR:
Improves the prompt to make it clear that might not be relevant
Only sends the context once. If you keep prompting, it won't send it again unless you move around in the editor
These changes should reduce the chance that this context will pollute anything. We'd like to keep this on because it's much more likely to be helpful and it's not very discoverable, but we've added a way to opt-out: you can open commands (ctrl+p) and select "Disable file context" to turn it off entirely (this will be global for your machine)
Regarding the original issue: unfortunately we aren't able to solve this right now. Most of you are using the Claude Code extension to host the server, and it doesn't send any event when the file closes and no new file is open. Until we develop our own plugins and have more control, we can't fix that
However, since we've tweaked the prompts and only send it once it'll only be sent with the next prompt, after which it will go away
Thank you @jlongster for providing option to disable this. I can see the use case of this feature. However, having the flexibility to enable/disable it is the way to go
Activity
dacarey commentedon Apr 25, 2026
I am also seeing the same issue in WSL. There is no obvious way around it, because once a selection is made it sticks, even if you then start opencode from the terminal.
Using /new does not clear it either
dacarey commentedon Apr 25, 2026
I asked opencode to analyse the issue. This is what it diagnosed and i can confirm the workaround works
Root Cause
The editor.ts context introduced in v1.14.23 scans
~/.claude/ide/*.lockfiles — these are written by the Claude Code VS Code extension (not OpenCode's own extension). It finds the lock file for your workspace, opens a WebSocket to VS Code, and subscribes toselection_changedevents.The bug is that
store.selectionis never cleared. When you close the file or move away in VS Code, the WebSocket either goes silent (noselection_changedevent fires tonullthe selection) or the connection drops and reconnects — but on reconnect there's no"clear selection"event, so the last known value persists in the store indefinitely.Workarounds (no downgrade needed)
Most effective — delete the lock files:
rm ~/.claude/ide/*.lockgabethehuman commentedon Apr 25, 2026
Thanks, the workaround seems to be working. But it's still annoying to do, and I'd rather see it fixed on OpenCode's side if possible.
iTzFaisal commentedon Apr 25, 2026
Please fix this. It's so annoying. the file is stuck in the context at all time. I'm having this behavior in Windows, macOS and WSL.
@dacarey Thank you for the workaround. This did the trick for the time being. 👍🏻
jjjermiah commentedon Apr 26, 2026
I have a PR that addresses part of this behaviour #24323
but for what it's worth claude code extension never emits the info that the files are closed unfortunately
iTzFaisal commentedon Apr 26, 2026
Thank you for identifing the root cause. I disbaled Claude Code extension in VSCode until this is fixed
bianpratama commentedon Apr 26, 2026
Yes, I did these things too for the time being:
rm ~/.claude/ide/*.lock.jlongster commentedon Apr 26, 2026
thank for this report, acknowledged, I know what the issue is and I will fix it asap! will be fixed in the next version (either tonight or tomorrow morning)
jlongster commentedon Apr 26, 2026
by the way, if this feature worked as expected, do you find this feature useful?
jjjermiah commentedon Apr 26, 2026
@jlongster yes definitely. It worked great the first time i used it in a single focussed session. and after looking through your PR work i think theres tons of value with a nicely exposed API for other plugins to tap into.
gabethehuman commentedon Apr 27, 2026
I would find it quite useful. Even better if I could highlight a specific part of the file, like a function or whatever, and OC would see the file and my highlighted text. Could be a nice way to point it to specific things.
But as long as there is no stale context after closing the file, everything else is a bonus.
Thanks for quick response.
jlongster commentedon Apr 27, 2026
@gabethehuman that's exactly what it does! if you select some code you'll see the filename + the selected range and it will send that file, selection range, and the highlighted section as text as context
gabethehuman commentedon Apr 27, 2026
Great :) If it disappears from the context after I close the file, then I will use the hell out of that feature :)
duerden commentedon Apr 27, 2026
Sorry if this is a stupid question, but is there a way to disable this? My vscode is rarely ever in-sync with what im doing in opencode so it kinda seems like context pollution for those that dont want it.
jlongster commentedon Apr 27, 2026
#24661 improves this feature and adds the ability to disable it
The PR:
These changes should reduce the chance that this context will pollute anything. We'd like to keep this on because it's much more likely to be helpful and it's not very discoverable, but we've added a way to opt-out: you can open commands (ctrl+p) and select "Disable file context" to turn it off entirely (this will be global for your machine)
jlongster commentedon Apr 27, 2026
Regarding the original issue: unfortunately we aren't able to solve this right now. Most of you are using the Claude Code extension to host the server, and it doesn't send any event when the file closes and no new file is open. Until we develop our own plugins and have more control, we can't fix that
However, since we've tweaked the prompts and only send it once it'll only be sent with the next prompt, after which it will go away
jlongster commentedon Apr 27, 2026
In the next version, you can select "Disable file context" from the command menu to disable it
iTzFaisal commentedon Apr 27, 2026
Thank you @jlongster for providing option to disable this. I can see the use case of this feature. However, having the flexibility to enable/disable it is the way to go
jlongster commentedon Apr 28, 2026
this should be released
jlongster commentedon Apr 28, 2026
my mistake, it wasn't released yet but we have a release going out now