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 | Read-only agent for analysis and code exploration (edits denied by default) |
Subagents
Invoked automatically or via @mention in messages.
| Agent | Description |
|---|---|
| General | Full-access agent for complex searches and multi-step tasks |
| Explore | Fast, read-only agent for codebase exploration |
Custom agents
Define custom agents in opencode.json or as markdown files in .opencode/agents/ (project) or ~/.config/opencode/agents/ (global):
Keyboard shortcuts
OpenCode uses a leader key (default: Ctrl+X) for most shortcuts. Press the leader, then the action key.
| Shortcut | Action |
|---|---|
| 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 s | Share session |
Ctrl+X b | Toggle sidebar |
Ctrl+X h | Help |
| Tab | Cycle 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 | Generate AGENTS.md for the project |
/new | Start a new session |
/sessions | List and switch sessions |
/undo | Undo last message and revert file changes |
/redo | Redo a previously undone message |
/compact | 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 | Toggle model reasoning visibility |
/help | Show help |
/exit | 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 |
|---|---|
glob | Find files by pattern |
grep | Search file contents |
ls | List directory contents |
view | View file contents |
write | Write to files |
edit | Edit files |
patch | Apply diffs to files |
diagnostics | Get LSP diagnostics |
Other
| Tool | Description |
|---|---|
bash | Execute shell commands |
fetch | Fetch data from URLs |
sourcegraph | Search code across public repos |
agent | Delegate sub-tasks to a subagent |
Non-interactive mode
Run a single prompt without the TUI:
LSP support
OpenCode uses LSP for code intelligence. Install the server for your language, then configure:
MCP servers
OpenCode supports MCP via stdio, http, and sse transports:
Custom instructions
OpenCode reads project instructions from AGENTS.md at the project root. Generate it with /init.
You can also provide global instructions at ~/.config/opencode/agents/.
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) | β
(stdio, http, sse) |
| LSP | β | β |
| TUI | Minimal | Rich (Bubble Tea) |
| Desktop app | β | β (beta) |
| GitHub integration | Native (PRs, issues, search) | Via MCP |
| Session management | β | β |
| Plan mode | β
/plan | β Plan agent (Tab) |
| Fleet / parallel agents | β
/fleet | β |
| Custom commands | β | β |
| Themes | β | β |
| Undo / redo file changes | /rewind | /undo /redo (git-based) |