Skip to main content

Module opencode_config

Module opencode_config 

Source
Expand description

Single source of truth for locating OpenCode’s global config file.

OpenCode accepts both opencode.json and opencode.jsonc. lean-ctx used to hardcode opencode.json in every writer, so a user whose config was opencode.jsonc got a second, competing global config containing nothing but the lean-ctx MCP entry and shadow-mode denies — their providers, models and foreign MCP servers appeared to vanish (#1585).

Resolution rule, applied by init, setup, doctor, the shadow-mode permission updater and uninstall alike:

  1. exactly one of the two exists → that file
  2. both exist → opencode.json (OpenCode’s own default name), reported via Resolved::ambiguous so callers can warn instead of silently picking
  3. neither exists → opencode.json, to be created

Structs§

Resolved
Where the OpenCode config lives, plus whether the choice was ambiguous.

Constants§

CODE_MODE_KEY
OpenCode 2.x per-server MCP key: “Expose this server’s tools through Code Mode. Defaults to true.” Under Code Mode the model sees only part of a server’s tools, as functions inside execute, so ctx_read and ctx_search drop out of view (#2295). lean-ctx sets it to false.

Functions§

code_mode_key_supported
Whether the installed OpenCode accepts CODE_MODE_KEY (2.x or newer).
code_mode_key_supported_by
Whether an OpenCode with this --version output accepts CODE_MODE_KEY. An unknown version does not: a key OpenCode 1.x rejects breaks the whole config, while a missing one only leaves Code Mode on.
config_dir
Resolve OpenCode’s global config directory.
disable_code_mode
Put codemode: false on a lean-ctx MCP server entry that has no codemode value yet. A value the user set is kept. Returns whether the entry changed.
major_version
Major version from opencode --version output such as 2.2.1 or v1.2.15.
resolve
Resolve the global OpenCode config for a given home directory.
resolve_in_dir
Resolve the config inside an OpenCode config directory.