設定
Config
OpenCode JSON 設定の使用。
JSON 設定ファイルを使用して OpenCode を設定できます。
Format
OpenCode は JSON と JSONC(コメント付き JSON)の両方の形式をサポートしています。
opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"autoupdate": true,
"server": {
"port": 4096,
},
}
Locations
設定を配置できる場所がいくつかあり、それぞれ異なる優先順位を持っています。
[!NOTE] 設定ファイルは マージされ、置き換えられません。
設定ソースは以下の順序で読み込まれます(後のソースが前のソースを上書き):
- リモート設定(
.well-known/opencodeから) - 組織のデフォルト - グローバル設定(
~/.config/opencode/opencode.json) - ユーザー設定 - カスタム設定(
OPENCODE_CONFIG環境変数) - カスタムの上書き - プロジェクト設定(プロジェクトの
opencode.json) - プロジェクト固有の設定 .opencodeディレクトリ - agents、commands、plugins- インライン設定(
OPENCODE_CONFIG_CONTENT環境変数) - ランタイムの上書き - 管理対象設定ファイル(macOS の
/Library/Application Support/opencode/) - 管理者管理 - macOS 管理設定(MDM 経由の
.mobileconfig) -最高優先度、ユーザーが上書き不可
Remote
組織は .well-known/opencode エンドポイント経由でデフォルト設定を提供できます。
opencode.json
{
"mcp": {
"jira": {
"type": "remote",
"url": "https://jira.example.com/mcp",
"enabled": true
}
}
}
Global
グローバル OpenCode 設定を ~/.config/opencode/opencode.json に配置します。
Per project
プロジェクトのルートに opencode.json を追加します。
[!TIP] プロジェクト固有の設定はプロジェクトのルートに配置します。
Custom path
OPENCODE_CONFIG環境変数を使用してカスタム設定ファイルパスを指定します。
export OPENCODE_CONFIG=/path/to/my/custom-config.json
opencode run "Hello world"
Custom directory
OPENCODE_CONFIG_DIR 環境変数を使用してカスタム設定ディレクトリを指定します。
export OPENCODE_CONFIG_DIR=/path/to/my/config-directory
opencode run "Hello world"
Managed settings
組織はユーザーが上書きできない設定を強制できます。
| Platform | Path |
|---|---|
| macOS | /Library/Application Support/opencode/ |
| Linux | /etc/opencode/ |
| Windows | %ProgramData%\opencode |
Schema
サーバー/ランタイム設定スキーマは opencode.ai/config.json で定義されています。
エディターはスキーマに基づいて検証とオートコンプリートができるはずです。
TUI
TUI 固有の設定には専用の tui.json(または tui.jsonc)ファイルを使用します。
tui.json
{
"$schema": "https://opencode.ai/tui.json",
"scroll_speed": 3,
"diff_style": "auto",
"mouse": true,
"attention": {
"enabled": true,
"notifications": true,
"sound": true,
"volume": 0.4
}
}
Server
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"server": {
"port": 4096,
"hostname": "0.0.0.0",
"mdns": true,
"mdnsDomain": "myproject.local",
"cors": ["http://localhost:5173"]
}
}
利用可能なオプション:
port- リスニングポートhostname- リスニングホスト名、mdns 有効時はデフォルトで0.0.0.0mdns- mDNS サービス発見を有効にし、LAN 内の他のデバイスが OpenCode サーバーを検出できるようにするmdnsDomain- カスタム mDNS ドメイン名、デフォルトはopencode.localcors- 追加の CORS 許可元、値は完全な起点である必要がある(scheme + host + オプションの port)
Shell
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"shell": "pwsh"
}
Tools
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"tools": {
"write": false,
"bash": false
}
}
Models
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"provider": {},
"model": "anthropic/claude-sonnet-4-5",
"small_model": "anthropic/claude-haiku-4-5"
}
Provider オプション:
timeout- リクエストタイムアウト(ミリ秒)、デフォルト 300000chunkTimeout- ストリーミング応答ブロック間のタイムアウトsetCacheKey- 指定された provider のキャッシュキーを常に設定することを確実にする
Policies
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"experimental": {
"policies": [
{
"effect": "deny",
"action": "provider.use",
"resource": "openai"
}
]
}
}
Image attachments
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"attachment": {
"image": {
"auto_resize": true,
"max_width": 2000,
"max_height": 2000,
"max_base64_bytes": 5242880
}
}
}
Themes
tui.json
{
"$schema": "https://opencode.ai/tui.json",
"theme": "tokyonight"
}
Agents
opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"agent": {
"code-reviewer": {
"description": "Reviews code for best practices and potential issues",
"model": "anthropic/claude-sonnet-4-5",
"prompt": "You are a code reviewer.",
"tools": {
"write": false,
"edit": false,
},
},
},
}
Default agent
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"default_agent": "plan"
}
Sharing
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"share": "manual"
}
"manual"- コマンドで手動共有を許可(デフォルト)"auto"- 新規会話を自動共有"disabled"- 共有を完全に無効化
Commands
opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"command": {
"test": {
"template": "Run the full test suite with coverage report.",
"description": "Run tests with coverage",
"agent": "build",
"model": "anthropic/claude-haiku-4-5",
},
},
}
Keybinds
tui.json
{
"$schema": "https://opencode.ai/tui.json",
"keybinds": {
"command_list": "ctrl+p"
}
}
Snapshot
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"snapshot": false
}
Autoupdate
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"autoupdate": false
}
false- 自動更新を無効化"notify"- 自動更新しないが、新しいバージョンがあるときに通知
Formatters
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"formatter": true
}
LSP Servers
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"lsp": true
}
Permissions
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"permission": {
"edit": "ask",
"bash": "ask"
}
}
Compaction
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"compaction": {
"auto": true,
"prune": false,
"reserved": 10000
}
}
auto- コンテキストがいっぱいになったときに自動コンパクション(デフォルト true)prune- 古いツール出力を削除してトークンを節約(デフォルト false)reserved- コンパクション時に保持するトークンバッファ
Watcher
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"watcher": {
"ignore": ["node_modules/**", "dist/**", ".git/**"]
}
}
MCP servers
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"mcp": {}
}
Plugins
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-helicone-session", "@my-org/custom-plugin"]
}
Instructions
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"instructions": ["CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md"]
}
Disabled providers
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"disabled_providers": ["openai", "gemini"]
}
Enabled providers
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"enabled_providers": ["anthropic", "openai"]
}
[!NOTE]
disabled_providersはenabled_providersより優先順位が高い
Experimental
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"experimental": {}
}
Variables
Env vars
{env:VARIABLE_NAME} を使用して環境変数を参照します:
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"model": "{env:OPENCODE_MODEL}",
"provider": {
"anthropic": {
"models": {},
"options": {
"apiKey": "{env:ANTHROPIC_API_KEY}"
}
}
}
}
Files
{file:path/to/file} を使用してファイル内容を参照します:
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"instructions": ["./custom-instructions.md"],
"provider": {
"openai": {
"options": {
"apiKey": "{file:~/.secrets/openai-key}"
}
}
}
}