OpenCode と Ollama の設定方法:ローカル coding agent 実践ガイド
OpenCode、Ollama、context window、repository 権限を分けて理解し、安全にローカルモデルを使います。
このガイドの内容
OpenCode は terminal 上の coding agent、Ollama は model runtime です。公式の最短手順は ollama launch opencode ですが、安定運用には 64K 程度の context、hardware に合う model、正しい working directory、慎重な command 権限が必要です。
ollama launch opencode で開始
OpenCode と Ollama を確認し、ollama list で model が見える状態にします。対象 repository に移動して ollama launch opencode を実行します。
公式 launcher は model 取得、integration、64K context、OpenCode 起動をまとめて処理するため、最初に試す方法です。
各レイヤーの役割
OpenCode は agent UI、Ollama は model runtime です。repository の file と command 権限は別の security boundary です。
小さな test repository、clean な Git、backup から始め、read-only の確認後に限定的な edit を許可します。
launcher が設定する内容
interactive menu で OpenCode と推奨 model を選ぶと Ollama-backed 接続が準備されます。
local model は RAM/VRAM を使い、cloud model は local 負荷を減らす代わりに internet と data transfer が必要です。
opencode.json の手動設定
launcher が model を見つけない場合や endpoint を固定したい場合は manual config を使います。OpenCode は OpenAI-compatible adapter と local v1 endpoint を案内しています。
your-model を ollama list の正確な tag に置き換えます。
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama (local)",
"options": { "baseURL": "http://localhost:11434/v1" },
"models": { "your-model": { "name": "your-model" } }
}
}
}
64K context の設定
context が小さいと tool call 品質低下や OOM が起きます。coding agent には 64K 以上が推奨されています。
manual model は Modelfile で num_ctx を設定します。memory が足りない場合は model と対象 file を小さくします。
FROM your-model
PARAMETER num_ctx 65536
用途と hardware で model を選ぶ
editor、index、test、context cache を含めても安定する model を選びます。まず小型 model で実 task を試します。
cloud model は大規模 task に有効ですが privacy と network 条件が変わります。
| 状況 | 最初の選択 | 理由 |
|---|---|---|
| RAM が少ない | 小型 local coding model | context と editor の余裕を残す |
| 強い GPU | 大型 local model | latency が許容できれば reasoning を強化 |
| 大規模 repository | Ollama cloud model | local memory 制限を回避。internet が必要 |
| 機密 repository | local model と限定権限 | data と command risk を抑える |
接続トラブルの切り分け
model が出ない場合は Ollama service、ollama list、base URL、tag を順に確認します。
停止する場合は scope と model を縮小し、command failure は permission と working directory を確認します。
安全な最初の coding task
最初は repository の説明と plan のみ依頼し、1つの限定 patch と test を許可します。最後に git diff を確認します。
Ollama endpoint を無防備に公開せず、secret を prompt に含めないでください。
OpenCode Ollama よくある質問
公式設定資料
- Ollama OpenCode integration - quick launch、manual config、context の公式説明。
- Ollama launch announcement - launcher の公式発表。
- OpenCode Ollama provider docs - Ollama provider の公式設定。
- Ollama context length docs - context size の公式ガイド。
関連する local AI ガイド
- Local AI coding agent workflow - repository context と permission を設計します。
- 16GB RAM 向け local coding model - workflow 全体の memory を考えて選びます。
- Cursor と Ollama - editor-first と OpenCode terminal を比較します。
- Odysseus AI Ollama 設定 - 共通 runtime と endpoint を確認します。
最終更新:2026年7月14日
Odysseus AI Wiki に戻る