feat(opencode): add ollama init cli command to generate opencode.json config dynamically
Problem
Setting up opencode with ollama requires manually creating a config file and copying model names from ollama list. Unlike cloud providers that auto-configure through auth login, local providers like Ollama have no automated setup.
This is an alternative to https://github.com/sst/opencode/pull/3726 but it is run conditionally by the user. I don't think opencode should look for ollama unless the user explicitly wants the support. My solution is an implementation of that and it's still configuration file driven. It is also thoroughly tested, cross platform and doesn't rely on an the arbitrary ollama base url and port but rather the ollama executable being found in the $PATH instead. I have been using a bash function to generate the opencode.json for me but I figured it would be helpful to others if this was just part of the opencode cli.
Run tests via
bun test test/cli/cmd/ollama.test.ts
Solution
Adds opencode ollama init to automatically generate config from installed models.
opencode ollama init -g # global config
opencode ollama init # local config
opencode ollama init config.json --base-url <url> # custom options
Key features:
- Auto-discovers models from ollama list
- --global flag writes to ~/.config/opencode/opencode.json
- Merges with existing config (preserves other providers)
- eliminates JSON syntax errors from manual configurations
Changes
- New CLI command: src/cli/cmd/ollama.ts
- Tests: test/cli/cmd/ollama.test.ts (9 tests)
- Docs: Updated Ollama section in providers.mdx