Skip to content

feat(lsp): add OPENCODE_DISABLE_LSP env var to skip all LSP servers#16271

Open
marcusquinn wants to merge 1 commit intoanomalyco:devfrom
marcusquinn:feat/disable-lsp-env-var
Open

feat(lsp): add OPENCODE_DISABLE_LSP env var to skip all LSP servers#16271
marcusquinn wants to merge 1 commit intoanomalyco:devfrom
marcusquinn:feat/disable-lsp-env-var

Conversation

@marcusquinn
Copy link

@marcusquinn marcusquinn commented Mar 6, 2026

Issue for this PR

Closes #16269

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds OPENCODE_DISABLE_LSP=true environment variable to completely skip LSP server initialization.

Headless opencode run sessions don't benefit from LSP diagnostics — the LLM doesn't use them. But each session spawns its own set of LSP servers. On shell-heavy projects, bash-language-server's hardcoded --external-sources flag causes exponential ShellCheck memory growth (3-5 GB RSS per process, never terminates). With multiple concurrent sessions, this compounds rapidly — we observed 73 concurrent shellcheck processes consuming 17.8 GB RAM on a 64 GB machine.

The flag is checked at the top of the LSP state initializer, before the existing cfg.lsp === false config check. When set, it returns an empty state with no servers — no LSP processes are spawned, no downloads attempted, no memory consumed.

This complements the existing controls:

  • OPENCODE_DISABLE_LSP_DOWNLOAD — prevents downloading LSP binaries but still runs already-installed ones
  • config.lsp: false / per-server disabled: true — config-file based control
  • OPENCODE_DISABLE_LSP (new) — env var to skip everything, ideal for headless/CI use
OPENCODE_DISABLE_LSP=true opencode run "implement feature X"

Related: #5363, #13041, #13796, #4957, #12976, #8947

How did you verify your code works?

  • OPENCODE_DISABLE_LSP=true bun dev — confirmed zero LSP processes spawned
  • bun dev without the flag — LSP servers start normally
  • bun turbo typecheck — zero errors

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Headless `opencode run` sessions don't benefit from LSP diagnostics,
but each session spawns its own LSP servers. On shell-heavy projects,
bash-language-server's hardcoded --external-sources flag causes
exponential ShellCheck memory growth (3-5 GB per process).

This adds OPENCODE_DISABLE_LSP=true to skip all LSP initialization,
complementing the existing OPENCODE_DISABLE_LSP_DOWNLOAD flag and
the per-server config.lsp disable option.

Closes anomalyco#16269
@marcusquinn
Copy link
Author

Note: the root cause of the --external-sources memory explosion is upstream in bash-language-server, not opencode. We've submitted a fix there too:

This PR (OPENCODE_DISABLE_LSP) is still valuable as the opencode-side mitigation — headless sessions don't need LSP at all, regardless of which language servers are involved.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@marcusquinn
Copy link
Author

Upstream root cause fix merged

bash-lsp/bash-language-server#1376 has been merged. bash-language-server now supports shellcheckExternalSources: false (config) / SHELLCHECK_EXTERNAL_SOURCES=false (env var) to omit the --external-sources flag.

This PR is still useful — headless opencode run sessions don't benefit from LSP diagnostics regardless of which language servers are involved. But the specific shellcheck memory explosion can now also be addressed by bumping the bash-language-server dependency and exposing the new config.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bash-language-server hardcodes --external-sources causing unbounded ShellCheck memory growth

1 participant