Skip to content

feat: add offline mode to disable non-essential outbound connections#18235

Open
dgruzd wants to merge 1 commit intoanomalyco:devfrom
dgruzd:feat/offline-mode
Open

feat: add offline mode to disable non-essential outbound connections#18235
dgruzd wants to merge 1 commit intoanomalyco:devfrom
dgruzd:feat/offline-mode

Conversation

@dgruzd
Copy link
Copy Markdown

@dgruzd dgruzd commented Mar 19, 2026

Issue for this PR

Closes #18233

Type of change

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

What does this PR do?

Adds a single "kill switch" for non-essential outbound connections, useful in privacy-sensitive or restricted-network environments.

Three equivalent ways to enable it:

// opencode.json
{ "offline": true }
OPENCODE_OFFLINE=true opencode
opencode --offline
opencode run --offline "fix the tests"
opencode serve --offline

When enabled, the following are disabled:

Connection Effect
opencode.ai/install auto-update check Skipped
opncd.ai session sharing Disabled; /share command hidden in TUI
app.opencode.ai web UI proxy Returns 503

Intentionally not affected: models.dev (essential model metadata) and Exa search (user-initiated, already gated by a permission prompt).

The existing granular flags (OPENCODE_DISABLE_AUTOUPDATE, OPENCODE_DISABLE_SHARE, OPENCODE_DISABLE_APP_PROXY) continue to work independently — OPENCODE_OFFLINE is a superset that implies all of them.

Implementation note: offline flags are implemented as Object.defineProperty getters rather than plain constants, because flag.ts is imported before the CLI handler or config loading has a chance to set OPENCODE_OFFLINE in the environment.

Inspired by the rolandcode fork, which patches these out entirely — this PR adds a first-class opt-in instead.

How did you verify your code works?

  • Added test/flag/offline.test.ts — 5 tests covering: env var activation, granular flag independence, OPENCODE_OFFLINE as superset, and dynamic runtime behavior (getters pick up env changes after module load)
  • Updated test/cli/tui/thread.test.ts to include offline: false in the expected args shape
  • bun test — all tests pass
  • bun typecheck — no errors

Screenshots / recordings

Not applicable — no UI changes (the /share command disappearing from the TUI when offline is the only visual effect, and it's a removal rather than something screenshot-worthy).

Checklist

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

Introduces OPENCODE_OFFLINE=true env var, offline: true config option, and
--offline CLI flag that act as a single kill switch for non-essential
outbound connections:

- opencode.ai/install auto-update check
- opncd.ai session sharing (also forces share: "disabled" so the TUI
  hides the /share command)
- app.opencode.ai web UI proxy

Exa search (mcp.exa.ai) is intentionally excluded — it is user-initiated
and already gated by a permission prompt. models.dev is excluded as it
provides essential model metadata.

Existing granular env vars (OPENCODE_DISABLE_AUTOUPDATE,
OPENCODE_DISABLE_SHARE, OPENCODE_DISABLE_APP_PROXY) still work
independently. OPENCODE_OFFLINE is a superset that enables all of them.

The offline flags use Object.defineProperty getters rather than plain
constants because flag.ts is imported before the CLI handler or config
loading sets process.env.OPENCODE_OFFLINE.

Docs: added Offline mode section to config.mdx.
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

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

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

@zhehuaf
Copy link
Copy Markdown

zhehuaf commented Mar 19, 2026

nice!! this is what I want, offline mode;)

@rekram1-node
Copy link
Copy Markdown
Collaborator

We ofc need to ship something with this shape, internally we talked about some approaches briefly, ill need to sync back w/ them to see what they think is best next week

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.

[FEATURE]: Offline mode: disable non-essential outbound connections at runtime

3 participants