OpenCode
Open-source AI coding agent in the terminal. Built by Anomaly, 100% provider-agnostic.
Install
A desktop app is also available at opencode.ai/download.
Launch & authenticate
On first launch, use /connect to add a provider and enter your API key. OpenCode supports 75+ providers via the AI SDK.
Alternatively, set API keys via environment variables:
| Variable | Provider |
|---|---|
ANTHROPIC_API_KEY | Anthropic |
OPENAI_API_KEY | OpenAI |
GEMINI_API_KEY | Google Gemini |
GROQ_API_KEY | Groq |
OPENROUTER_API_KEY | OpenRouter |
GITHUB_TOKEN | GitHub Copilot |
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY | AWS Bedrock |
AZURE_OPENAI_API_ENDPOINT / AZURE_OPENAI_API_KEY | Azure OpenAI |
Agents
OpenCode includes built-in agents you can switch between with Tab.
Primary agents
| Agent | Description |
|---|---|
| Build | Default agent, full tool access for development work |
| Plan | Analysis and planning agent (file edits and bash default to ask) |
Subagents
Invoked automatically (via the task tool) or with an @mention in messages, e.g. @general. Each runs in a child session: enter it with Ctrl+X Down, cycle siblings with Left / Right, go back to the parent with Up.
| Agent | Description |
|---|---|
| General | Full-access agent for research and multi-step tasks, can run work in parallel |
| Explore | Fast, read-only agent for finding files and searching code |
| Scout | Read-only agent for external docs and dependency research |
Custom agents
Define custom agents in opencode.json, as markdown files in .opencode/agents/ (project) or ~/.config/opencode/agents/ (global), or interactively with opencode agent create:
The old tools map is deprecated — restrict an agent with permission instead. hidden: true hides a subagent from the @ menu.
Keyboard shortcuts
OpenCode uses a leader key (default: Ctrl+X) for most shortcuts. Press the leader, then the action key.
| Shortcut | Action |
|---|---|
| Ctrl+P | Command palette |
| Ctrl+T | Cycle model variants (reasoning effort) |
| Ctrl+C | Quit |
Ctrl+X n | New session |
Ctrl+X l | List / switch sessions |
Ctrl+X m | Select model |
Ctrl+X e | Open external editor |
Ctrl+X u | Undo last message + file changes |
Ctrl+X r | Redo |
Ctrl+X c | Compact (summarize) session |
Ctrl+X x | Export conversation to Markdown |
Ctrl+X t | Switch theme |
Ctrl+X b | Toggle sidebar |
Ctrl+X q | Quit |
| Tab | Cycle primary agents (Build ↔ Plan) |
| Esc | Cancel / close overlay |
@ | Reference files (fuzzy search) |
! | Run shell command directly |
Slash commands
| Command | Description |
|---|---|
/connect | Add a provider |
/models | List / select model |
/init | Create or update AGENTS.md for the project (guided) |
/new (alias /clear) | Start a new session |
/sessions (/resume, /continue) | List and switch sessions |
/undo | Undo last message and revert file changes (needs a Git repo) |
/redo | Redo a previously undone message |
/compact (alias /summarize) | Summarize conversation to reduce context |
/share | Share session via link |
/unshare | Remove shared session |
/export | Export conversation to markdown |
/editor | Compose message in external $EDITOR |
/themes | Switch UI theme |
/thinking | Show / hide reasoning blocks (use Ctrl+T to change the reasoning level) |
/details | Toggle tool execution details |
/help | Show help |
/exit (/quit, /q) | Quit |
Configuration
OpenCode uses JSON (or JSONC) config files, merged in this order (later overrides earlier):
- Remote config (
.well-known/opencode) - Global:
~/.config/opencode/opencode.json - Custom:
$OPENCODE_CONFIG - Project:
opencode.jsonin project root
TUI-specific settings go in a separate tui.json.
Example config
TUI config
Workflow: plan then build
Custom commands
Define reusable prompts as commands in opencode.json or as markdown files in .opencode/commands/:
Then run with /test in the TUI. Commands support $ARGUMENTS, $1/$2 positional params, file references with @, and shell output with !`command`.
Tools available to the AI
File & code
| Tool | Description |
|---|---|
read | Read file contents (or a line range) |
write | Create or overwrite files |
edit | Replace exact text in a file |
apply_patch | Apply a patch to the codebase |
glob | Find files by pattern (sorted by modification time) |
grep | Search file contents with regex |
lsp | Definitions, references, hover via LSP (experimental) |
Other
| Tool | Description |
|---|---|
bash | Execute shell commands |
webfetch | Fetch and read a web page |
websearch | Search the web |
task | Delegate a sub-task to a subagent |
skill | Load a skill's SKILL.md |
todowrite | Track a task list during the session |
question | Ask you a question mid-task |
Permissions
Each tool can be set to allow, ask or deny, globally or per agent, with glob patterns for commands:
opencode --auto auto-approves everything not explicitly denied — sandboxes only.
Skills
Skills are folders with a SKILL.md (frontmatter name matching the folder, plus description), loaded on demand through the skill tool. OpenCode discovers them in .opencode/skills/, .agents/skills/ and .claude/skills/ (project, walking up to the git root) and in ~/.config/opencode/skills/, ~/.agents/skills/, ~/.claude/skills/ (global) — so Claude Code skills work as-is.
Non-interactive mode
Run a single prompt without the TUI:
Other CLI commands
LSP support
OpenCode ships built-in LSP servers (some auto-installed; disable downloads with OPENCODE_DISABLE_LSP_DOWNLOAD). LSP is disabled by default — once enabled, a server starts when a matching file is opened. Add or disable servers under lsp:
MCP servers
OpenCode supports local (stdio) and remote (HTTP, with OAuth auto-detection) MCP servers:
Note that command is an array. Each server also accepts timeout (ms, default 5000); remote ones take an oauth object (or false).
Custom instructions
OpenCode reads project instructions from AGENTS.md (walking up from the current directory) and global ones from ~/.config/opencode/AGENTS.md. Generate the project file with /init.
For Claude Code compatibility it falls back to CLAUDE.md / ~/.claude/CLAUDE.md when no AGENTS.md exists (disable with OPENCODE_DISABLE_CLAUDE_CODE=1). Extra files (paths, globs or URLs) can be added with the instructions config key:
Copilot CLI vs OpenCode
| Feature | Copilot CLI | OpenCode |
|---|---|---|
| License | Proprietary | Open source (MIT) |
| Auth | GitHub subscription | API keys (any provider) |
| Multi-provider | GitHub models only | 75+ providers (Anthropic, OpenAI, Gemini, Groq, Bedrock, Azure…) |
| MCP | ✅ (stdio) | ✅ (local, remote + OAuth) |
| LSP | ✅ | ✅ |
| TUI | Minimal | Rich (OpenTUI), plus web UI and headless server |
| Desktop app | ❌ | ✅ (beta) |
| GitHub integration | Native (PRs, issues, search) | Via MCP |
| Session management | ✅ | ✅ |
| Plan mode | ✅ /plan | ✅ Plan agent (Tab) |
| Fleet / parallel agents | ✅ /fleet | Subagents (@general, task tool) |
| Custom commands | ❌ | ✅ |
| Themes | ❌ | ✅ |
| Undo / redo file changes | /rewind | /undo /redo (git-based) |