Skip to content

IDE/editor context persists after closing file #24184

Description

@gabethehuman

Description

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

  1. Open opencode in VSCode terminal
  2. Open a file, select something in it. Filename should appear at the botton of opencode
  3. Close this file, the filename doesn't disappear.

Screenshot and/or share link

we open file, testfile.py appears near the bottom:
Image

we close this file, testfile.py remains
Image

Operating System

WSL2 inside Windows 11, latest versions.

Terminal

Bash inside VSCode, WSL2

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Apr 24, 2026
  2. dacarey commented on Apr 25, 2026

    @dacarey

    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

  3. dacarey commented on Apr 25, 2026

    @dacarey

    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

  4. gabethehuman commented on Apr 25, 2026

    @gabethehuman
    Author

    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.

  5. iTzFaisal commented on Apr 25, 2026

    @iTzFaisal

    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. 👍🏻

  6. jjjermiah commented on Apr 26, 2026

    @jjjermiah
    Contributor

    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

  7. iTzFaisal commented on Apr 26, 2026

    @iTzFaisal

    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 is fixed

  8. bianpratama commented on Apr 26, 2026

    @bianpratama

    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

    Yes, I did these things too for the time being:

    • Disable the Claude Code VS Code extension.
    • Delete the lock files: rm ~/.claude/ide/*.lock.
  9. jlongster commented on Apr 26, 2026

    @jlongster
    Collaborator

    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)

  10. jlongster commented on Apr 26, 2026

    @jlongster
    Collaborator

    by the way, if this feature worked as expected, do you find this feature useful?

  11. jjjermiah commented on Apr 26, 2026

    @jjjermiah
    Contributor

    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.

  12. gabethehuman commented on Apr 27, 2026

    @gabethehuman
    Author

    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.

  13. jlongster commented on Apr 27, 2026

    @jlongster
    Collaborator

    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

  14. gabethehuman commented on Apr 27, 2026

    @gabethehuman
    Author

    Great :) If it disappears from the context after I close the file, then I will use the hell out of that feature :)

  15. duerden commented on Apr 27, 2026

    @duerden

    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.

  16. jlongster commented on Apr 27, 2026

    @jlongster
    Collaborator

    #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)

  17. jlongster commented on Apr 27, 2026

    @jlongster
    Collaborator

    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

  18. jlongster commented on Apr 27, 2026

    @jlongster
    Collaborator

    In the next version, you can select "Disable file context" from the command menu to disable it

  19. iTzFaisal commented on Apr 27, 2026

    @iTzFaisal

    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

  20. jlongster commented on Apr 28, 2026

    @jlongster
    Collaborator

    this should be released

  21. jlongster commented on Apr 28, 2026

    @jlongster
    Collaborator

    my mistake, it wasn't released yet but we have a release going out now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentuiwindows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions