Skip to the content.

OpenCode

Information

OpenCode is an open-source AI coding assistant and autonomous agent designed to accelerate software development across terminal and IDE workflows. It inspects repository structure and context to generate code, execute refactorings, write tests, and resolve development tasks using various LLM backends.

Key Features

Use Cases

Installation

Install OpenCode via npm or installation script:

# Using npm
npm install -g @opencode-ai/cli

# Or using the installer script
curl -fsSL https://opencode.ai/install.sh | bash

Usage

Starting OpenCode in a Project

cd /path/to/project
opencode

Passing Direct Tasks

# Run a specific task
opencode "Refactor the authentication middleware to use JWT tokens"

# Run tests and fix failures
opencode "Run test suite and fix any failing test cases"

Configuring LLM Providers

Configure environment variables for cloud or local model providers:

# Cloud providers
export OPENAI_API_KEY="your-api-key"
export ANTHROPIC_API_KEY="your-api-key"

# Local models via Ollama
export OPENCODE_LLM_PROVIDER="ollama"
export OLLAMA_BASE_URL="http://localhost:11434"

Tinker backend

In the SMI toolset OpenCode is used with the Tinker backend: a custom tinker provider in the OpenCode config with TINKER_API_KEY in the environment, serving Qwen and Llama models, including your own fine-tuned ones. The Tinker client itself installs with smi-install-package tinker.

Passing a logged-in session to another machine

After opencode auth login, the credentials are stored in ~/.local/share/opencode/auth.json. Copy that file to the same path on the target machine and the CLI is logged in there without a second login. The headless alternative is a provider API key in the environment, for example ANTHROPIC_API_KEY or OPENAI_API_KEY, as shown above. Non-interactive execution: opencode run "prompt".

For a CLI executor such as Argo Workflows or Dagu, a pre step exports the key into the process environment, then starts the agent, for example through smi-agent. Distributing the secret itself is planned later through a secret tool such as OpenBao: the pre step reads the current key from there.

See also