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
LSP diagnostics from external projects leak into tool results and context window #16353
LSP.diagnostics() in packages/opencode/src/lsp/index.ts:291 aggregates diagnostics from ALL active LSP clients into a single Record<string, Diagnostic[]> with no workspace/project path filtering. This causes diagnostics from files outside the current project to appear in tool results.
Impact
Context window pollution — write.ts appends up to 5 "other files" diagnostics to the text output (what the model sees). These can come from completely unrelated projects, wasting context tokens and potentially confusing the model into "fixing" errors in the wrong codebase.
metadata.diagnostics — all three tools (write, edit, apply_patch) pass the entire unfiltered diagnostics map into metadata, which surfaces in UI clients.
Discovered while building a VS Code extension that consumes OpenCode CLI via SSE/SDK. When the agent reads files from an external project and then edits files in the current workspace, diagnostics from the external project leak into metadata.diagnostics and pollute the context window.
Plugins
No response
OpenCode version
checked 1.1.60 & v1.2.20
Steps to reproduce
Open a project (Project A)
Ask the agent to read/analyze files from a different project on disk (Project B)
Then ask the agent to edit a file in Project A
The tool result will contain LSP diagnostics from Project B files
This happens because TypeScript language server follows imports across project boundaries, and once it starts tracking external files, their diagnostics persist in the client's diagnostics map.
Root cause
// packages/opencode/src/lsp/index.ts:291exportasyncfunctiondiagnostics(){constresults: Record<string,LSPClient.Diagnostic[]>={}for(constresultofawaitrunAll(async(client)=>client.diagnostics)){for(const[path,diagnostics]ofresult.entries()){// No filtering — paths from any project end up hereconstarr=results[path]||[]arr.push(...diagnostics)results[path]=arr}}returnresults}
Same root cause as here: even though the UI only renders the edited file's diagnostics, all three tools (write, edit, apply_patch) still write the entire unfiltered diagnostics map into metadata.diagnostics, which is exactly where external-project entries leak in and get persisted.
Workaround while this is unaddressed: opencode-edit-diagnostics-pruner — https://github.com/one-pyy/opencode-edit-diagnostics-pruner — a tool.execute.after hook that trims metadata.diagnostics to only the files touched by the current call and leaves everything else (tool output, input, other metadata) intact. It resolves relative paths against the project directory and preserves the full map whenever a path cannot be resolved, so it fails safe. The same repo also ships a CLI to prune already-stored sessions.
Activity
fix: filter LSP diagnostics by client root
fix(lsp): filter diagnostics to current project paths only
fix: resolve 8 open bug reports from upstream tracker
github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
one-pyy commentedon Oct 5, 2026
Same root cause as here: even though the UI only renders the edited file's diagnostics, all three tools (
write,edit,apply_patch) still write the entire unfiltered diagnostics map intometadata.diagnostics, which is exactly where external-project entries leak in and get persisted.Workaround while this is unaddressed: opencode-edit-diagnostics-pruner — https://github.com/one-pyy/opencode-edit-diagnostics-pruner — a
tool.execute.afterhook that trimsmetadata.diagnosticsto only the files touched by the current call and leaves everything else (tool output, input, other metadata) intact. It resolves relative paths against the project directory and preserves the full map whenever a path cannot be resolved, so it fails safe. The same repo also ships a CLI to prune already-stored sessions.