概要
opencode + 自前ollama (gemma4-31b) を使って自前でコーディングエージェントを構築するハウツー
前提
ollamaが疎通可能なNWで動いていること
ray@kami:~$ curl http://192.168.0.97:11434/v1/models | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 835 100 835 0 0 465k 0 --:--:-- --:--:-- --:--:-- 815k
{
"object": "list",
"data": [
{
"id": "gemma4:latest",
"object": "model",
"created": 1781793873,
"owned_by": "library"
},
{
"id": "gemma4:31b",
"object": "model",
"created": 1775797746,
"owned_by": "library"
},
{
"id": "glm-4.7-flash:latest",
"object": "model",
"created": 1773826681,
"owned_by": "library"
},
{
"id": "olmo-3:32b",
"object": "model",
"created": 1766060501,
"owned_by": "library"
},
{
"id": "deepseek-r1:32b",
"object": "model",
"created": 1759021785,
"owned_by": "library"
},
{
"id": "mixtral:8x7b",
"object": "model",
"created": 1758984309,
"owned_by": "library"
},
{
"id": "phi4:14b",
"object": "model",
"created": 1758639295,
"owned_by": "library"
},
{
"id": "qwen3:32b",
"object": "model",
"created": 1758637355,
"owned_by": "library"
},
{
"id": "gemma3:27b",
"object": "model",
"created": 1758636814,
"owned_by": "library"
},
{
"id": "gpt-oss:20b",
"object": "model",
"created": 1758636489,
"owned_by": "library"
}
]
}
手順
1. opencodeをインストール
curl -fsSL https://opencode.ai/install | bash
2. 設定
martin-ray@Rays-MacBook-Pro ~ % cat .config/opencode/opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"model": "ollama/gemma4:31b",
"small_model": "ollama/gemma4:31b",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama (local)",
"options": {
"baseURL": "http://192.168.0.97:11434/v1"
},
"models": {
"gemma4:31b": {
"name": "gemma4:31b"
}
}
}
}
}
設定は以上
性能評価
claude sonetほどの速さは出ないし、回答も浅いが簡単なタスクなら全然任せられそうというお気持ち。
Please refer to the site and setup playwrite mcp. https://github.com/microsoft/playwright-mcp
+ Thought: 4.7s
%WebFetch https://github.com/microsoft/playwright-mcp
+ Thought: 14.3s
→Read opencode.json
+ Thought: 16.1s
→Read opencode.jsonc
+ Thought: 41.4s
← Edit opencode.jsonc
"name": "gemma4:31b"
}
}
}
},
"mcp": {
"playwright": {
"type": "local",
"command": [
"npx",
"@playwright/mcp@latest"
],
"enabled": true
}
}
}
Playwright MCP has been set up in your opencode.jsonc configuration.
▣ Build · gemma4:31b · 2m 11s
I set up the chrome playwrite extention and I think I need to paste the following env variable to some where. PLAYWRIGHT_MCP_EXTENSION_TOKEN=kvqWCaZ6hybIh8zN1BAD2qnX4BHhpg3Wnso63NKD3QA could you find the prper file to write the variable?
+ Thought: 14.6s
→Read opencode.jsonc
+ Thought: 32.4s
$ ls -a /Users/martin-ray/.config/opencode
.
..
.gitignore
__pycache__
calculator.py
node_modules
opencode.jsonc
package-lock.json
package.json
test_calculator.py
+ Thought: 50.6s
← Edit opencode.jsonc
"command": [
"npx",
"@playwright/mcp@latest"
],
"env": {
"PLAYWRIGHT_MCP_EXTENSION": "true",
"PLAYWRIGHT_MCP_EXTENSION_TOKEN": "kvqWCaZ6hybIh8zN1BAD2qnX4BHhpg3Wnso63NKD3QA"
},
"enabled": true
}
}
}
I have added the extension token and enabled the extension mode in your opencode.jsonc file.
▣ Build · gemma4:31b · 1m 43s
okay then please open blog.ingenboy.com from browser.
+ Thought: 7.8s
$ npx @playwright/mcp@latest browser_navigate --url "https://blog.ingenboy.com"
npm warn exec The following package was not found and will be installed: @playwright/mcp@0.0.79
error: unknown option '--url'
npm notice
npm notice New major version of npm available! 10.9.2 -> 12.0.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v12.0.2
npm notice To update run: npm install -g npm@12.0.2
npm notice
+ Thought: 1m 32s
I have configured the Playwright MCP server in your settings, but the tools are not yet appearing in my toolset. Please restart your opencode session so the client can initialize the server and provide the browser tools to me.
▣ Build · gemma4:31b · 1m 49s
how about now.
+ Thought: 24.9s
⚙playwright_browser_navigate [url=https://blog.ingenboy.com]
Opened https://blog.ingenboy.com.
▣ Build · gemma4:31b · 1m 20s
great! let's proceed to next step. opne https://blog.ingenboy.com and find the most interesting post.
+ Thought: 11.5s
⚙playwright_browser_snapshot
+ Thought: 10.0s
⚙playwright_browser_navigate [url=https://blog.ingenboy.com]
+ Thought: 9.8s
→Read .playwright-mcp/page-2026-08-18T13-25-23-800Z.yml
+ Thought: 47.3s
Based on the content, the most interesting post is "Opencode_on_ollama_backend" (August 18, 2026), as it provides a how-to on building a coding agent using opencode and a local ollama backend with gemma4-31b—exactly the setup we are using right now.
Other highly interesting posts include:
- "Openclaw": A deep dive into autonomous "resident" AI agents that act as AI secretaries.
- "OpenVPNとFRR(OSPF)...": A technical analysis of multi-site VPN routing limits.
- "MyMap": A guide to building a fully self-hosted map service using OpenStreetMap.
という感じで、まあ、claude codeに慣れてしまっているとどうしても遅いと感じてしまうが、完全OSSの自前でこの精度で動くのはなかなかすごいと思う。 いつかA100とか買ってもっと快適に動かしたいと思うね。しかし、A100買うお金があるのなら、大学に入ってA100を使わせてもらう方が断然お得かなというお気持ちもある。
最後に
playwriteのMCPはこちら。 github 割と設定方法は簡単だったというか、opencodeに丸投げしたらやってくれた感じだった。もうここまできてるんだなーという驚き。