Skip to content

Conversation

@tobocop2
Copy link

@tobocop2 tobocop2 commented Nov 11, 2025

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 #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

@tobocop2 tobocop2 force-pushed the add-ollama-command branch 3 times, most recently from eae5c72 to 857f6e0 Compare November 11, 2025 03:15
@tobocop2 tobocop2 changed the title Add ollama init command to auto-generate config Add ollama init command to auto-generate opencode.json config Nov 11, 2025
@tobocop2 tobocop2 changed the title Add ollama init command to auto-generate opencode.json config feat: Add ollama init command to auto-generate opencode.json config Nov 11, 2025
@tobocop2 tobocop2 changed the title feat: Add ollama init command to auto-generate opencode.json config feat: add ollama init command to auto-generate opencode.json config Nov 11, 2025
@tobocop2 tobocop2 force-pushed the add-ollama-command branch 4 times, most recently from 747523f to 837b42e Compare November 11, 2025 22:15
@tobocop2 tobocop2 changed the title feat: add ollama init command to auto-generate opencode.json config feat: add ollama init cli command to generate opencode.json config dynamically Nov 11, 2025
@tobocop2 tobocop2 changed the title feat: add ollama init cli command to generate opencode.json config dynamically feat(cli): add ollama init cli command to generate opencode.json config dynamically Nov 11, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

Hey! Your PR title feat(cli): add ollama init cli command to generate opencode.json config dynamically doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@tobocop2 tobocop2 changed the title feat(cli): add ollama init cli command to generate opencode.json config dynamically feat(opencode): add ollama init cli command to generate opencode.json config dynamically Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants