{"id":"add-ollama-provider","name":"add-ollama-provider","summary":"NanoClawエージェントのグループをAnthropic APIではなくローカルのOllamaモデルにルーティングしてください。","body":"# Add Ollama Provider\n\nRoutes an agent group to a local Ollama instance instead of the Anthropic API.\nSee `docs/ollama.md` for how this works and the tradeoffs involved.\n\n## Prerequisites\n\n1. **Ollama is installed and running** on the host — verify: `curl -s http://localhost:11434/api/tags`\n2. **A model is pulled** — e.g. `ollama pull gemma4` or `ollama pull qwen3-coder`\n3. **The agent group already exists** — run `/init-first-agent` first if needed\n\n## 1. Check source support\n\nThe feature requires two fields in `ContainerConfig` (`env` and `blockedHosts`) and their\ncorresponding wiring in `container-runner.ts`. Check if already present:\n\n```bash\ngrep -c 'blockedHosts' src/container-config.ts src/container-runner.ts\n```\n\nIf either count is 0, apply the changes in steps 1a and 1b. Otherwise skip to step 2.\n\n### 1a. Extend ContainerConfig\n\nIn `src/container-config.ts`, add to the `ContainerConfig` interface:\n\n```typescript\nenv?: Record<string, string>;\nblockedHosts?: string[];\n```\n\nAnd in `readContainerConfig`, add inside the returned object:\n\n```typescript\nenv: raw.env,\nblockedHosts: raw.blockedHosts,\n```\n\n### 1b. Wire into container-runner\n\nIn `src/container-runner.ts`, after the `NANOCLAW_MCP_SERVERS` block, add:\n\n```typescript\n// Per-agent-group env overrides — applied last to win over OneCLI values.\nif (containerConfig.env) {\n  for (const [key, value] of Object.entries(containerConfig.env)) {\n    args.push('-e', `${key}=${value}`);\n  }\n}\n\n// Blocked hosts: resolve to 0.0.0.0 so they are unreachable inside the container.\nif (containerConfig.blockedHosts) {\n  for (const host of containerConfig.blockedHosts) {\n    args.push('--add-host', `${host}:0.0.0.0`);\n  }\n}\n```\n\n### 1c. Fix home directory permissions (if not already done)\n\nThe container may run as your host uid (not uid 1000). Check the Dockerfile:\n\n```bash\ngrep 'chmod.*home/node' container/Dockerfile\n```\n\nIf it shows `chmod 755`, change it to `chmod 777` so any uid can write there.\nThen rebuild the container image: `./container/build.sh`\n\n## 2. Identify the setup\n\nAsk the user (plain text, not AskUserQuestion):\n\n1. **Which agent group?** List available groups: `pnpm exec tsx scripts/q.ts data/v2.db \"SELECT folder, name FROM agent_groups;\"`\n2. **Which Ollama model?** List available: `curl -s http://localhost:11434/api/tags | grep '\"name\"'`\n3. **Block Anthropic API?** Recommended yes — prevents accidental spend if config drifts.\n\nRecord as `FOLDER`, `MODEL`, and `BLOCK_ANTHROPIC`.\n\n## 3. Configure container.json\n\nRead `groups/<FOLDER>/container.json`. Add (or merge into) an `env` block and optionally `blockedHosts`:\n\n```json\n{\n  \"env\": {\n    \"ANTHROPIC_BASE_URL\": \"http://host.docker.internal:11434\",\n    \"ANTHROPIC_API_KEY\": \"ollama\",\n    \"NO_PROXY\": \"host.docker.internal\",\n    \"no_proxy\": \"host.docker.internal\"\n  },\n  \"blockedHosts\": [\"api.anthropic.com\"]\n}\n```\n\nOmit `blockedHosts` if the user declined step 2.\n\n**Why these vars:** `ANTHROPIC_BASE_URL` redirects the Anthropic SDK to Ollama.\n`ANTHROPIC_API_KEY=ollama` satisfies the SDK's key requirement (Ollama ignores it).\n`NO_PROXY` bypasses the OneCLI HTTPS proxy for requests to `host.docker.internal`\nso they reach Ollama directly instead of going through the credential gateway.\n\n## 4. Set the model\n\nRead the agent group's shared Claude settings:\n\n```bash\n# Find the agent group ID\nAG_ID=$(pnpm exec tsx scripts/q.ts data/v2.db \"SELECT id FROM agent_groups WHERE folder='<FOLDER>';\")\nSETTINGS=data/v2-sessions/$AG_ID/.claude-shared/settings.json\n```\n\nAdd `\"model\": \"<MODEL>\"` to that settings file. Create the file if it doesn't exist:\n\n```json\n{\n  \"model\": \"gemma4:latest\"\n}\n```\n\nIf the file already has content, merge the `model` key in — don't overwrite existing keys.\n\n**Why here and not container.json:** Claude Code reads its model from its own settings\nfile, not from env vars. This file is bind-mounted into the container as `~/.claude/settings.json`.\n\n## 5. Build and restart\n\nRun from your NanoClaw project root:\n\n```bash\nexport PATH=\"/opt/homebrew/bin:$PATH\"\npnpm run build\nsource setup/lib/install-slug.sh\nlaunchctl unload ~/Library/LaunchAgents/$(launchd_label).plist\nlaunchctl load   ~/Library/LaunchAgents/$(launchd_label).plist\n# Linux: systemctl --user restart $(systemd_unit)\n```\n\n## 6. Verify\n\nSend a message to the agent. Then confirm:\n\n```bash\n# Ollama shows the model as active\ncurl -s http://localhost:11434/api/ps | grep '\"name\"'\n\n# Container has the right env vars\nCTR=$(docker ps --filter \"label=nanoclaw-group-folder=<FOLDER>\" --format \"{{.Names}}\" | head -1)\ndocker inspect \"$CTR\" --format '{{json .HostConfig.ExtraHosts}}'\ndocker exec \"$CTR\" env | grep ANTHROPIC\n```\n\nExpected: `api.anthropic.com:0.0.0.0` in ExtraHosts, `ANTHROPIC_BASE_URL=http://host.docker.internal:11434`.\n\n## Reverting to Claude\n\nTo switch back to the Anthropic API:\n\n1. Remove the `env` and `blockedHosts` keys from `groups/<FOLDER>/container.json`\n2. Remove `\"model\"` from the shared settings file\n3. Restart the service\n\nNo rebuild needed — both files are read at container spawn time.\n\n## Troubleshooting\n\n**Agent hangs, no response:** Ollama may be loading the model cold (large models take 10–30s).\nWatch `curl -s http://localhost:11434/api/ps` — the model appears once loaded.\n\n**\"model not found\" error in container logs:** The model name in settings.json doesn't match\nwhat Ollama has. Run `ollama list` on the host and use the exact name shown.\n\n**Responses claim to be Claude:** The model was trained on data that includes Claude conversations.\nAdd a line to `groups/<FOLDER>/CLAUDE.md` telling it what model it runs on.\n\n**Agent responds but Ollama shows no activity:** `NO_PROXY` may not have taken effect for\n`http_proxy` (lowercase). Add both `NO_PROXY` and `no_proxy` to the env block.","author":"@nanocoai","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/nanocoai/nanoclaw/tree/main/.claude/skills/add-ollama-provider","license":"MIT","category":"document","lang":"en","tokens":1548,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[{"code":"code.chmod-777","kind":"dangerous-code","where":"SKILL.md:67","excerpt":"chmod 777","message":"sets world-writable permissions","severity":"warn"}],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":["host.docker.internal"]}}