mcpField
O
opencode

opencode

github.com/dimitrigilbertエージェントワークフロー545 回インストール3 週間前に更新
リポジトリ

opencode について

opencode のコマンドライン、Web インターフェース、セッション、モデル、サーバーの使い方を案内するスキルです。対話操作とスクリプト自動化に対応し、MCP サーバー管理コマンドも扱います。

主な機能

  1. 01自動化向けの非対話実行
  2. 02ヘッドレスサーバーと Web UI
  3. 03セッションの再開、分岐、エクスポート
  4. 04モデルとエージェントの管理
  5. 05MCP サーバーの追加、認証、デバッグ

活用シーン

  1. 01CI/CD スクリプトで opencode タスクを実行
  2. 02過去のセッションを再開または確認
  3. 03稼働中サーバーに TUI を接続
  4. 04MCP サーバー接続を管理

MCP 対応

MCP サーバーの追加・一覧表示、認証やログアウト、OAuth 接続のデバッグに使うコマンドを説明します。

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dimitrigilbert/ai-skills --skill opencode

インストール後、Claude Code で/opencodeを入力して読み込まれたか確認します。

詳細

OpenCode CLI と Web サーバーのガイド

ユーザーから、ツールとしての opencode の使用方法(CLI コマンド、非対話モード、Web サーバー、セッション、モデル、または opencode <command> の使用方法)について質問された場合に、このスキルを読み込みます。

インストール

curl -fsSL https://opencode.ai/install | bash
# Or: npm install -g opencode-ai
# Or: brew install anomalyco/tap/opencode

グローバルオプション

すべてのコマンドで使用できるオプション:--help、--version、--print-logs、--log-level <DEBUG|INFO|WARN|ERROR>、--pure(プラグインを無効化)

TUI/サーバーモード用のグローバルフラグ:-m <provider/model>、-c / --continue(最後のセッションを再開)、-s <id> / --session(指定したセッションを再開)、--fork(再開時にコピー)、--agent <name>、--prompt <text>

非対話モード:opencode run

TUI を起動せずに opencode を実行します。スクリプト、CI/CD、自動化に最適です。

# Basic usage
opencode run "Explain async/await in TypeScript"

# With specific model
opencode run -m anthropic/claude-sonnet-4-20250514 "Refactor this function"

# Attach files to the prompt
opencode run -f src/index.ts "Explain this file"

# Continue last session
opencode run -c "Now add error handling"

# Fork a session (creates copy)
opencode run -c --fork "Try a different approach"

# Output raw JSON events (for piping/processing)
opencode run --format json "List all TODO comments"

# Share the session after completion
opencode run --share "Generate a README"
run のフラグ
フラグ説明
-m, --model <provider/model>使用するモデル
--agent <name>使用するエージェント
-c, --continue最後のセッションを続行
-s, --session <id>指定したセッションを再開
--fork続行前にセッションをフォーク
--share完了後にセッションを共有
--format <default|json>出力形式(デフォルト:整形済み)
-f, --file <path>メッセージにファイルを添付(複数指定可能)
--title <text>セッションのタイトル
--attach <url>実行中のサーバーに接続(例:http://localhost:4096)
-p, --password <pw>ベーシック認証のパスワード(環境変数:OPENCODE_SERVER_PASSWORD)
-u, --username <user>ベーシック認証のユーザー名(デフォルト:opencode)
--dir <path>作業ディレクトリ
--port <num>ローカルサーバーのポート(省略時はランダム)
--variant <level>モデルの推論レベル(例:high、max、minimal)
--thinking思考ブロックを表示
-i, --interactive直接対話する分割フッターモードで実行
--dangerously-skip-permissions拒否対象以外の権限を自動承認
--command <cmd>メッセージの代わりにスラッシュコマンドを実行
実行中のサーバーへの run の接続

実行中のサーバーに接続して、MCP のコールドブートを回避します。

# Terminal 1: start server
opencode serve

# Terminal 2: run commands against it
opencode run --attach http://localhost:4096 "Fix the lint errors"

ヘッドレスサーバー:opencode serve

TUI なしでヘッドレスサーバーを起動します。他のクライアント(run --attach、web、attach)が接続できます。

# Start with defaults (random port, localhost)
opencode serve

# Specify port
opencode serve --port 4096

# Expose on all interfaces
opencode serve --hostname 0.0.0.0 --port 4096

# Enable mDNS discovery
opencode serve --mdns --port 4096

# Allow CORS for specific origins
opencode serve --cors http://localhost:5173 --port 4096
serve のフラグ
フラグデフォルト説明
--port <num>0(ランダム)リッスンするポート
--hostname <addr>127.0.0.1バインドするアドレス
--mdnsfalsemDNS サービス検出を有効化
--mdns-domain <name>opencode.localカスタム mDNS ドメイン
--cors <origin>[]追加の CORS ドメイン(複数指定可能)
サーバー REST API

サーバーはバインドされたアドレスで REST API を公開します。主なエンドポイント:

  • GET /app — アプリケーションの詳細
  • POST /app/init — アプリケーションを初期化
  • GET /config/providers — 設定済みプロバイダーの一覧
  • GET /mode — 利用可能なモード
  • GET /session — セッションの一覧
  • POST /session/init — セッションを初期化
  • POST /session/summarize — セッションを要約
  • POST /session/abort — 実行中のセッションを中止
  • DELETE /session/delete — セッションを削除
  • GET /file/read?path=<path> — ファイルの内容を読み取る
  • GET /file/status — 変更されたファイルの状態
  • GET /find/file — ファイルを検索
  • GET /find/symbol — シンボルを検索
  • GET /find — テキストを検索

認証:-u / -p フラグ、または OPENCODE_SERVER_USERNAME / OPENCODE_SERVER_PASSWORD 環境変数を使用します。

Web インターフェース:opencode web

サーバーを起動し、ブラウザーで Web UI を開きます。フラグは serve と同じです。

opencode web
opencode web --port 4096 --hostname 0.0.0.0
opencode web --cors http://localhost:5173

同じ Web サーバーに TUI を接続できます。

# Terminal 1
opencode web --port 4096

# Terminal 2
opencode attach http://localhost:4096

サーバーに接続:opencode attach

実行中の serve または web インスタンスに TUI を接続します。

opencode attach http://localhost:4096

# With session resume
opencode attach http://localhost:4096 -c

# With specific session
opencode attach http://localhost:4096 -s <session-id>

# With auth
opencode attach http://localhost:4096 -u opencode -p secretpassword
フラグ説明
--dir <path>作業ディレクトリ
-c, --continue最後のセッションを続行
-s, --session <id>指定したセッションを再開
--fork再開時にフォーク
-p, --password <pw>認証パスワード
-u, --username <user>認証ユーザー名

ACP サーバー:opencode acp

Agent Client Protocol サーバーを起動します(--cwd を加え、フラグは serve と同じです)。

opencode acp --port 4096 --cwd /path/to/project

セッション管理

# List sessions
opencode session list
opencode session list -n 10 --format json

# Delete a session
opencode session delete <session-id>

# Export session as JSON
opencode export <session-id>
opencode export <session-id> --sanitize  # redact sensitive data

# Import session from file or share URL
opencode import session.json
opencode import https://opencode.ai/share/abc123

モデルとプロバイダー

# List all available models
opencode models

# Filter by provider
opencode models anthropic

# Verbose (includes cost info)
opencode models --verbose

# Refresh model cache
opencode models --refresh

# Manage providers
opencode providers list
opencode providers login
opencode providers logout

PR ワークフロー:opencode pr

GitHub PR のブランチを取得してチェックアウトし、opencode を開きます。

opencode pr 42

GitHub エージェント

opencode github install        # Install GitHub agent
opencode github run            # Run the agent
opencode github run --event '{"type":"issues","action":"opened",...}'
opencode github run --token github_pat_...

MCP サーバー

opencode mcp add               # Add an MCP server
opencode mcp list              # List servers and status
opencode mcp auth [name]       # Authenticate OAuth MCP server
opencode mcp logout [name]     # Remove OAuth credentials
opencode mcp debug <name>      # Debug OAuth connection

エージェント管理

# List agents
opencode agent list

# Create agent
opencode agent create --description "Review code" --mode subagent --tools "read,grep,glob"

# Create with model
opencode agent create -m anthropic/claude-sonnet-4-20250514 --mode primary

# Create at specific path
opencode agent create --path .opencode/agents/reviewer.md
create フラグ説明
--path <dir>出力ディレクトリ
--description <text>エージェントの機能
--mode <all|primary|subagent>エージェントモード
--tools <list>カンマ区切りの権限:bash,read,edit,glob,grep,webfetch,task,todowrite,websearch,lsp,skill
-m <model>provider/model 形式のモデル

統計とデバッグ

# Token usage and costs
opencode stats
opencode stats --days 7 --models --project myproject
opencode stats --tools 10

# Debug tools
opencode debug config           # Show resolved config
opencode debug paths            # Global paths (data, config, cache, state)
opencode debug info             # Debug information
opencode debug skill            # List available skills
opencode debug agent <name>     # Show agent config details
opencode debug startup          # Startup timing
opencode debug lsp              # LSP debugging
opencode debug rg               # Ripgrep debugging
opencode debug file             # File system debugging
opencode debug scrap            # List all known projects
opencode debug snapshot         # Snapshot debugging

データベースツール

opencode db                     # Interactive SQLite shell
opencode db "SELECT * FROM session LIMIT 5"  # Run query
opencode db path                # Print database path
opencode db migrate             # Migrate JSON data to SQLite
opencode db --format json "SELECT count(*) FROM message"

プラグインと拡張機能

# Install plugin
opencode plugin <npm-module>
opencode plugin <npm-module> --global
opencode plugin <npm-module> --force  # Replace existing version

アップグレードとアンインストール

# Upgrade
opencode upgrade
opencode upgrade 0.1.48
opencode upgrade --method curl

# Uninstall
opencode uninstall --dry-run       # Preview what gets removed
opencode uninstall -c -d -f        # Remove but keep config and data

シェル補完

opencode completion  # Generate completion script (bash/zsh/fish)

設定

設定ファイル
  • プロジェクト:.opencode/opencode.json
  • グローバル:~/.config/opencode/config.json
サーバー設定(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"]
  }
}
環境変数
変数説明
OPENCODE_AUTO_SHAREセッションを自動共有
OPENCODE_CONFIGカスタム設定パス
OPENCODE_DISABLE_CLAUDE_CODEClaude Code との互換性を無効化
OPENCODE_SERVER_PASSWORDデフォルトの認証パスワード
OPENCODE_SERVER_USERNAMEデフォルトの認証ユーザー名

TUI クイックリファレンス

opencode を対話形式で使用する場合(デフォルト、サブコマンドなし):

キー/コマンド動作
Tabビルド/プランモードを切り替え
Ctrl+Xショートカット用のリーダーキー
/helpヘルプを表示
/initAGENTS.md を作成
/connectAI プロバイダーを設定
/new新しいセッション
/sessionsセッション一覧
/modelsモデルを切り替え
/undo / /redoGit ベースの元に戻す/やり直し
/share / /unshareセッションを共有/共有解除
/compactコンテキストを圧縮
/details詳細を表示
/thinking思考を切り替え
/exportセッションをエクスポート
@fileファジー検索でファイルを参照
!commandシェルコマンドを実行

コメント