Skip to content

The chat starts opencode 2 with its Code Mode off - #235

Merged
endrix merged 2 commits into
mainfrom
feat/opencode-code-mode-off
Nov 24, 2026
Merged

endrix merged 2 commits into
mainfrom
feat/opencode-code-mode-off

Conversation

@endrix

@endrix endrix commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

What changes

opencode 2 has a "Code Mode": it hides a session's MCP tools behind one execute tool. The model writes a script that calls the tools and reads only what the script prints, so when a tool answers with a picture (the diagram server's diagram-png, untangle-start, untangle-try), the model never sees it.

With this PR, when the chat's connector is opencode and the binary is opencode 2, the chat starts opencode acp with Code Mode off. It puts {"permission": {"execute": "deny"}} in OPENCODE_CONFIG_CONTENT, a config layer opencode reads from its environment. The tools are then offered as themselves, and their results reach the model whole, pictures included.

  • Scope: the variable is set only on the process the chat spawns (and the opencode serve that one starts). The user's own opencode, and opencode in a terminal, are not touched.
  • Merge, not overwrite: if the user already has an OPENCODE_CONFIG_CONTENT (from the environment or the connector's env table), the key is added to it and the rest is kept. If their value already says permission.execute, theirs stands. If it does not parse as JSON (opencode also reads JSONC), it is left as it is and the log says so in one line.
  • opencode 1.x (no Code Mode, and it may refuse an unknown permission), an opencode whose version cannot be told (the log says so), and the claude, codex and gemini connectors are not touched. The version comes from the probe the client already runs; an opencode connector without the HTTP API is now probed too, by its command's name, its HTTP API still off.
  • The user's opencode.json: the env layer is read after it, so a permission.execute set there gives way to the chat's. The setting below is how to keep Code Mode.
  • Setting: dialogram.chat.opencodeCodeMode (default off) leaves Code Mode on. It is declared by the Dialogram extension itself, beside dialogram.chat.useGlspMcp and autoLayoutAfterEdits; every product depends on ebezati.dialogram, so no product needs a change. It takes effect when the chat next starts its agent.

Why not opencode's per-server codemode: false: the chat hands its MCP servers over through ACP newSession, and opencode's ACP adapter keeps only a server's url and headers.

Tests

  • opencode-code-mode.test.ts: no value; empty value; user value kept with the key added last; user value without permission; user permission.execute kept whatever it says; JSONC left as it is with a one-line note; non-object values and a one-rule permission left as they are.
  • acp-client.test.ts: opencode 2 spawns with execute denied (the probe still sees the env as it was); user value from the process and from the connector env merged; user execute kept; JSONC kept with one warn line; the setting on leaves it unset; opencode 1.x and an unknown flavour untouched; claude, codex and gemini untouched.
  • acp-client.test.ts (review): an opencode 2 connector without the HTTP API gets execute denied and no HTTP client; an opencode 1.x one gets no port; an unknown version logs one Code Mode line.
  • npm run typecheck 5/5, extension-core 681/681, neutrality 5/5.

Review

code-review medium found five nits, no bugs:

  1. opencode.json permission.execute is overridden in the chat (the env layer is read after it). Holds: the setting, the CHANGELOG and the module say so, and name the setting as the way to keep Code Mode.
  2. An agent's own permission with a wildcard allow lets execute back in. Holds as wording: the comment and the log line now say so. Not changed in behaviour: injecting rules into agents the chat does not know would be guesswork.
  3. An opencode connector without http_api was never probed, so an opencode 2 there kept Code Mode on, and an unknown version left no trace. Fixed: any connector whose command is opencode is probed (HTTP API still off without the flag), and an unknown version logs one line. Tests added.
  4. A JSONC OPENCODE_CONFIG_CONTENT is left alone. Not changed: that is the agreed behaviour (opencode reads JSONC; rewriting a value the chat cannot parse risks breaking it). The log line says so.
  5. The setting is read when the agent starts, with no restart on change. Not changed: it is the same as the acp.connector setting, and the description says it takes effect when the chat next starts its agent.

https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu

opencode 2 puts a session's MCP tools behind one `execute` tool, and a
picture a tool answers with never reaches the model. The `opencode acp`
the chat spawns on opencode 2 now carries `permission.execute: "deny"` in
OPENCODE_CONFIG_CONTENT, added to the user's own value; a value that says
permission.execute stands, one that does not parse is left as it is with
a line in the log. opencode 1.x and the other agents are not touched.
`dialogram.chat.opencodeCodeMode` (default off) leaves Code Mode on.

Claude-Session: https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu
…Code Mode may come back

Review of #235: an opencode connector without the HTTP API was never
probed, so an opencode 2 there kept Code Mode on; it is now asked by its
command's name, its HTTP API still off. An opencode whose version cannot
be told says in the log that Code Mode is left as its config says. The
setting, the CHANGELOG and the log line say that an opencode.json
permission.execute gives way to the chat's, and that an agent's own
wildcard allow lets execute back in.

Claude-Session: https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu
@endrix
endrix merged commit 5d2e73a into main Nov 24, 2026
1 check passed
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.

1 participant