Configure opencode with environment variables

configuration

// what it does

opencode reads several OPENCODE_-prefixed variables: OPENCODE_CONFIG points at an alternate config file, OPENCODE_CONFIG_CONTENT holds inline JSON (highest precedence, ideal for CI), OPENCODE_CONFIG_DIR relocates the config directory, and OPENCODE_MODEL sets the default model. Feature toggles like OPENCODE_DISABLE_CLAUDE_CODE and OPENCODE_DISABLE_LSP_DOWNLOAD turn off specific behaviors.

// shell

$ export OPENCODE_MODEL=anthropic/claude-sonnet-4-5
$ export OPENCODE_CONFIG=~/.config/opencode/work.json
$ OPENCODE_DISABLE_CLAUDE_CODE=1 opencode

// gotcha

OPENCODE_CONFIG_CONTENT overrides every file-based config, so a leftover export in your shell profile silently wins over both global and project files — a confusing reason a config change appears to do nothing.

// resources