Install & Configure OpenCode
Install OpenCode, connect your first AI provider using /connect, initialize a project with AGENTS.md, and understand the interfaces available — TUI, desktop, and IDE.
Install OpenCode, connect your first AI provider using /connect, initialize a project with AGENTS.md, and understand the interfaces available — TUI, desktop, and IDE.
OpenCode is an open-source AI coding agent available as a terminal-based TUI, a desktop app, and an IDE extension. It supports 75+ LLM providers through the AI SDK and Models.dev, meaning you can connect Anthropic, OpenAI, Google, local models via Ollama, or any OpenAI-compatible endpoint.
Key facts:
# npm (global)
npm install -g opencode-ai
# Homebrew (macOS/Linux)
brew install anomalyco/tap/opencode
# Yarn
yarn global add opencode-ai
# Bun
bun install -g opencode-ai
# Arch Linux
sudo pacman -S opencodeOn Windows, the recommended approach is WSL (Windows Subsystem for Linux) for best performance and compatibility.
# Chocolatey
choco install opencode
# Scoop
scoop install opencode
# npm
npm install -g opencode-aiOpenCode's TUI works best in a modern terminal emulator:
Standard macOS Terminal and Windows Terminal work but may miss some rendering features.
Run opencode to open the TUI, then use /connect to add your first provider:
OpenCode Zen is a curated list of models tested and verified by the OpenCode team. It removes the need to manage individual provider API keys when starting out.
/connect → select OpenCode Zen/models to see the curated model list (includes Qwen 3 Coder 480B and others)OpenCode lets you log in directly with existing subscriptions — no separate API keys needed:
| Subscription | How to connect |
|---|---|
| ChatGPT Plus/Pro | /connect → OpenAI → ChatGPT Plus/Pro (OAuth) |
| GitHub Copilot | /connect → GitHub Copilot → device flow |
| GitLab Duo | /connect → GitLab → OAuth |
For CI or scripting, set the API key as an environment variable:
# Anthropic
export ANTHROPIC_API_KEY="sk-ant-..."
# OpenAI
export OPENAI_API_KEY="sk-..."
# Or any provider key — opencode picks it up automatically
opencodeAPI keys added via /connect are stored in ~/.local/share/opencode/auth.json — local to your machine, not synced anywhere.
Navigate to your project and run /init:
/init scans your repo and creates AGENTS.md with:
Commit AGENTS.md to Git so every team member and every future OpenCode session benefits from the same context.
After connecting a provider, run /models to switch:
OpenCode uses a small model (defaults to a lightweight Zen model) for utility tasks like generating session titles. Your main model choice only applies to the coding conversation itself.
OpenCode installs in seconds via the install script or your package manager. /connect walks you through adding any of 75+ providers — or use OpenCode Zen for a curated, no-fuss experience. Run /init in every new project to generate a committed AGENTS.md that gives OpenCode durable project context. The next module covers the core workflow: Plan mode, Build mode, @file references, and undo/redo.