OpenCode is an open-source AI coding agent with a terminal interface, desktop app, and editor extensions.
This cheat sheet covers the CLI commands, TUI slash commands, keyboard shortcuts, configuration options, agents, permissions, MCP servers, Skills, and automation workflows you’ll most likely look up while using OpenCode.
Last updated: September 14, 2026.
OpenCode quick reference
Input syntax
| Syntax | Action |
|---|---|
| Plain text | Send a prompt to the current agent. |
/command | Run a built-in or custom TUI command. |
@path/to/file | Find a project file and include its contents in the prompt. |
@alias/path | Browse a configured reference root. |
!command | Run a shell command and attach its output to the conversation. |
@agent | Invoke a subagent by name. |
Tab / Shift+Tab | Cycle primary agents. |
ctrl+x | Start the default leader-key sequence. |
Common tasks
| Command or shortcut | Action |
|---|---|
opencode | Start OpenCode. |
opencode /path/to/project | Open another project. |
opencode --continue | Continue the latest session. |
/connect | Connect a provider. |
/models | Pick a model. |
/init | Create or update AGENTS.md. |
/new or ctrl+x n | Start a new session. |
/sessions or ctrl+x l | Resume a session. |
/compact or ctrl+x c | Compact context. |
/undo or ctrl+x u | Undo the latest turn. |
/redo or ctrl+x r | Redo an undone turn. |
opencode run "Your prompt" | Run one prompt from the shell. |
opencode run -f file.ts "Review this file" | Attach a file to a shell run. |
opencode models | List models. |
opencode mcp list | List MCP servers. |
opencode debug config | Inspect merged config. |
opencode stats | Show usage and cost stats. |
opencode upgrade | Update OpenCode. |
OpenCode CLI commands
Start the TUI
| Syntax or flag | Purpose |
|---|---|
opencode [project] | Start the TUI in the current directory or a project path. |
--continue, -c | Continue the latest session. |
--session, -s | Continue a specific session ID. |
--fork | Fork a continued session. |
--prompt | Start with a prompt. |
--model, -m | Select a provider/model ID. |
--agent | Select a primary agent. |
--auto | Approve requests that are not explicitly denied. |
opencode --continue
opencode --session ses_123 --fork
opencode --model anthropic/claude-sonnet-4-5 --agent plan
opencode --autoAuthentication
| Command | Purpose |
|---|---|
opencode auth login | Add credentials for a provider. |
opencode auth list | List authenticated providers. |
opencode auth logout | Remove provider credentials. |
opencode auth login --provider <id> | Select a provider for login. |
Models
Model IDs use the provider/model-id format.
| Command | Purpose |
|---|---|
opencode models | List models from configured providers. |
opencode models <provider> | List models from one provider. |
opencode models --refresh | Refresh the cached model list. |
opencode models --verbose | Include model metadata. |
Run a prompt from the shell
opencode run executes a prompt without opening the TUI.
| Command or flag | Purpose |
|---|---|
opencode run [message...] | Send a non-interactive prompt. |
--continue, -c | Continue the latest session. |
--session, -s | Continue a selected session. |
--fork | Fork a continued session. |
--model, -m | Select a model. |
--agent | Select an agent. |
--file, -f | Attach one or more files. |
--format json | Emit JSON events for scripts or CI. |
--command | Run a custom command. |
--title | Set the session title. |
--auto | Auto-approve requests that are not denied. |
opencode run "Explain the authentication flow"
opencode run -f src/auth.ts "Review this file for security issues"
opencode run --format json "List the failing tests"
opencode run --agent plan "Review the changed files"Sessions
| Command | Purpose |
|---|---|
opencode session list | List saved sessions. |
opencode session list -n 10 | Show the newest 10 sessions. |
opencode session list --format json | Return session data as JSON. |
opencode session delete <sessionID> | Delete a session. |
MCP
| Command | Purpose |
|---|---|
opencode mcp add | Add an MCP server through the wizard. |
opencode mcp list | List MCP servers and connection status. |
opencode mcp auth <name> | Start OAuth for a server. |
opencode mcp auth list | List MCP authentication status. |
opencode mcp logout <name> | Remove stored OAuth credentials. |
opencode mcp debug <name> | Test connectivity and OAuth discovery. |
Agents
opencode agent create opens the agent wizard. opencode agent list shows the available agents.
opencode agent create
opencode agent listOther useful CLI commands
| Command | Purpose |
|---|---|
opencode stats | Show token usage and cost statistics. |
opencode export [sessionID] | Export a session as JSON. |
opencode export --sanitize [sessionID] | Export with sensitive transcript and file data redacted. |
opencode import <file-or-url> | Import a session. |
opencode debug config | Show the resolved configuration. |
opencode pr <number> | Check out a GitHub pull request and start OpenCode. |
opencode upgrade | Update OpenCode. |
opencode --help | Show CLI help. |
opencode <command> --help | Show help for one command. |
TUI slash commands
Type / in the prompt to open command autocomplete.
| Command | Alias or shortcut | Action |
|---|---|---|
/connect | None | Add a provider and API key. |
/compact | /summarize, ctrl+x c | Compact the current session. |
/details | None | Toggle tool execution details. |
/editor | ctrl+x e | Compose the current message in $EDITOR. |
/exit | /quit, /q, ctrl+x q | Exit OpenCode. |
/export | ctrl+x x | Export the conversation to Markdown and open it. |
/help | None | Open the help dialog. |
/init | None | Create or update AGENTS.md. |
/models | ctrl+x m | Open the model picker. |
/new | /clear, ctrl+x n | Start a new session. |
/redo | ctrl+x r | Redo an undone message and its file changes. |
/sessions | /resume, /continue, ctrl+x l | List and switch sessions. |
/share | None | Share the current session. |
/themes | ctrl+x t | Choose a theme. |
/thinking | None | Show or hide thinking blocks. |
/undo | ctrl+x u | Remove the latest user message, responses, and file changes. |
/unshare | None | Remove the current session share. |
Essential keyboard shortcuts
The default leader key is ctrl+x. Press the leader first, then the second key.
| Shortcut | Action |
|---|---|
ctrl+p | Open the command list. |
<leader>n | Start a new session. |
<leader>l | Open the session list. |
<leader>c | Compact the current session. |
<leader>u | Undo the latest turn. |
<leader>r | Redo an undone turn. |
<leader>x | Export the session. |
<leader>e | Open the external editor. |
<leader>m | Open the model list. |
<leader>a | Open the agent list. |
Tab | Cycle primary agents. |
Shift+Tab | Cycle primary agents backward. |
ctrl+t | Cycle the model variant. |
F2 | Cycle recent models. |
Escape | Interrupt the current session. |
<leader>y | Copy the selected message. |
ctrl+c, ctrl+d, or <leader>q | Exit OpenCode. |
Return | Submit the prompt. |
Shift+Return, Ctrl+Return, Alt+Return, or Ctrl+J | Insert a new line. |
Install and update
| Command | Method |
|---|---|
curl -fsSL https://opencode.ai/install | bash |
npm install -g opencode-ai | npm |
bun install -g opencode-ai | Bun |
pnpm install -g opencode-ai | pnpm |
brew install anomalyco/tap/opencode | Homebrew tap |
scoop install opencode | Scoop on Windows |
choco install opencode | Chocolatey on Windows |
docker run -it --rm ghcr.io/anomalyco/opencode | Docker |
opencode --version
opencode upgrade
opencode upgrade --method npmSessions, files, and context
Session lifecycle
| TUI command | CLI command | Action |
|---|---|---|
/new | opencode | Start a new session. |
/sessions | opencode --continue | Continue the latest session. |
/sessions | opencode --session <id> | Continue a known session. |
| Session controls | opencode --session <id> --fork | Fork a session. |
| Session list | opencode session list | List sessions. |
| Session list | opencode session delete <id> | Delete a session. |
/export | opencode export <id> | Export a session. |
| Status view | opencode stats | Show usage and cost statistics. |
Files and attachments
Use @ to fuzzy-search project files from the TUI.
Explain the error handling in @src/api/index.ts
Compare @package.json with @docs/architecture.mdAttach files to a shell run with repeated --file flags:
opencode run --file src/api/index.ts --file tests/api.test.ts "Review this change"Undo and redo
/undo removes the latest user message, responses, and associated file changes. /redo restores an undone turn. File rollback uses Git-backed snapshots, so the project must be a Git repository.
Configuration
OpenCode accepts JSON and JSONC. Project configuration normally lives in opencode.json. User-wide configuration lives at ~/.config/opencode/opencode.json. TUI appearance and keybind settings use tui.json.
{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"autoupdate": true
}Common config locations
| Location | Use |
|---|---|
~/.config/opencode/opencode.json | User-wide configuration. |
opencode.json | Project configuration. |
.opencode/agents/ | Project agents. |
.opencode/commands/ | Project custom commands. |
.opencode/skills/ | Project Skills. |
.opencode/plugins/ | Project plugins. |
tui.json | TUI settings and keybinds. |
Common config keys
| Option | Purpose |
|---|---|
model | Default provider/model-id. |
small_model | Lightweight model for small internal tasks. |
agent | Agent definitions. |
default_agent | Default primary agent. |
permission | Approval rules. |
mcp | MCP server definitions. |
instructions | Additional instruction files. |
command | Custom commands. |
share | Session sharing behavior. |
snapshot | File snapshot behavior. |
autoupdate | Update behavior. |
provider | Provider options and model overrides. |
Environment and file substitutions
Use {env:NAME} to load an environment variable and {file:path} to load file contents into config.
{
"$schema": "https://opencode.ai/config.json",
"model": "{env:OPENCODE_MODEL}",
"instructions": ["{file:./instructions.md}"],
"provider": {
"openai": {
"options": {
"apiKey": "{env:OPENAI_API_KEY}"
}
}
}
}Models and providers
Use /models in the TUI or opencode models in the shell. Model names use the provider/model-id format.
opencode models
opencode models anthropic
opencode models --refresh
opencode --model openai/gpt-5
opencode run --model openai/gpt-5 "Review the error boundary"Agents
OpenCode has primary agents for the main conversation and subagents for delegated work.
| Agent | Mode | Role |
|---|---|---|
build | Primary | Development work with file and shell tools. |
plan | Primary | Planning and analysis; file edits and shell commands require approval by default. |
general | Subagent | Complex research and multi-step work. |
explore | Subagent | Fast read-only codebase exploration. |
scout | Subagent | External documentation and dependency research. |
Cycle primary agents with Tab and Shift+Tab. Invoke a subagent with @name.
@explore Find every route that writes to the users table
@general Review the migration plan and list unresolved risksCreate a custom agent
Run the wizard:
opencode agent createProject agents can also live in .opencode/agents/ as Markdown files:
---
description: Review code without edits
mode: subagent
model: anthropic/claude-sonnet-4-5
permission:
edit: deny
bash: ask
---
Inspect the code and report defects, edge cases, and missing tests.Permissions
Permission rules use three values:
| Value | Behavior |
|---|---|
allow | Run without an approval prompt. |
ask | Ask before the action. |
deny | Block the action. |
Common permission keys include read, edit, bash, task, external_directory, webfetch, websearch, and skill.
{
"$schema": "https://opencode.ai/config.json",
"permission": {
"bash": {
"*": "ask",
"git status *": "allow",
"git push *": "deny"
},
"edit": {
"*": "deny",
"src/**": "allow"
}
}
}Rules are evaluated in order, and the last matching rule wins. --auto approves actions that would otherwise ask for permission. Explicit deny rules continue to block the action.
Project instructions, custom commands, and Skills
Project instructions
AGENTS.md stores project instructions. Run /init to create or update it.
The instructions config can load additional files:
{
"$schema": "https://opencode.ai/config.json",
"instructions": [
"CONTRIBUTING.md",
"docs/guidelines.md",
".cursor/rules/*.md"
]
}Custom commands
Store project commands in .opencode/commands/ and global commands in ~/.config/opencode/commands/. The filename becomes the slash command name.
---
description: Run tests and explain failures
agent: build
---
Run the test suite. Report each failure with its file, root cause, and a focused fix.Run this file as /test.
Useful substitutions:
| Syntax | Result |
|---|---|
$ARGUMENTS | All text after the command name. |
$1, $2, $3 | Positional arguments. |
! followed by a backtick command | Insert shell output. |
@path/to/file | Insert file contents. |
Agent Skills
Project Skills live in .opencode/skills/<name>/SKILL.md. Global Skills live in ~/.config/opencode/skills/<name>/SKILL.md. OpenCode can also discover compatible Skills under .claude/skills/ and .agents/skills/.
---
name: git-release
description: Create consistent releases and changelogs
---
Draft release notes from merged pull requests and propose a version bump.MCP servers
OpenCode can connect to local process MCP servers and remote HTTP MCP servers.
Manage MCP servers
opencode mcp add
opencode mcp list
opencode mcp auth my-server
opencode mcp logout my-server
opencode mcp debug my-serverLocal MCP server
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"local-tools": {
"type": "local",
"command": ["npx", "-y", "my-mcp-command"],
"environment": {
"MY_API_KEY": "{env:MY_API_KEY}"
},
"enabled": true
}
}
}Remote MCP server
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"remote-tools": {
"type": "remote",
"url": "https://mcp.example.com/mcp",
"enabled": true,
"headers": {
"Authorization": "Bearer {env:MY_API_KEY}"
}
}
}
}Automation and remote use
One-off and CI runs
opencode run "Explain this repository"
opencode run --agent plan --format json "Review the changed files"
opencode run --file src/api.ts "Review this API change"Persistent backend
Start a backend:
opencode serve --port 4096 --hostname 127.0.0.1Send a run to it:
opencode run --attach http://127.0.0.1:4096 "Run the focused test suite"Attach a TUI:
opencode attach http://127.0.0.1:4096Set OPENCODE_SERVER_PASSWORD when the backend needs HTTP basic authentication.
Common environment variables
| Variable | Purpose |
|---|---|
OPENCODE_CONFIG | Custom config file path. |
OPENCODE_TUI_CONFIG | Custom TUI config file path. |
OPENCODE_CONFIG_DIR | Custom .opencode-style config directory. |
OPENCODE_CONFIG_CONTENT | Inline JSON config. |
OPENCODE_SERVER_PASSWORD | Server basic-auth password. |
OPENCODE_SERVER_USERNAME | Server basic-auth username. |
OPENCODE_DISABLE_AUTOUPDATE | Disable update checks. |
OPENCODE_DISABLE_AUTOCOMPACT | Disable automatic context compaction. |
OPENCODE_GIT_BASH_PATH | Git Bash executable on Windows. |
Troubleshooting
opencode is not recognized
Open a new shell and run opencode --version. Check that the installation directory is on PATH.
Provider or model is missing
Run:
opencode auth list
opencode models --refreshCheck the exact provider/model-id spelling and review enabled_providers or disabled_providers if the provider is absent.
A TUI command fails in a shell
Slash commands run inside the TUI. Use their CLI equivalents from the shell. For example, use opencode models in place of /models and opencode session list in place of /sessions.
A permission prompt blocks a tool
Run:
opencode debug configCheck the global permission rule, agent-specific rules, and later matching patterns. The last matching rule wins.
Undo does not restore files
Confirm that the project is a Git repository and snapshots are enabled.
An MCP server is disconnected
Run:
opencode mcp list
opencode mcp debug <name>Check the command or URL, environment variables, timeout, and authentication status.
The context becomes too large
Use /compact or ctrl+x c. Disable MCP servers that are not needed for the current task and avoid attaching large unrelated files.
FAQs
What is the difference between Build and Plan?
Build is the primary development agent. Plan focuses on analysis and planning, with file edits and shell commands requiring approval by default.
Does --auto override denied permissions?
No. --auto approves permission requests that would normally ask. Explicit deny rules continue to block the action.
What is the difference between a custom command and an Agent Skill?
A custom command creates a slash command for a repeatable prompt. An Agent Skill stores reusable instructions that an agent can load through the native Skill system.
What does /thinking do?
It shows or hides thinking blocks from models that provide them. It does not change the model’s reasoning capability. Use ctrl+t to cycle provider-specific model variants.
Official OpenCode resources
Related resources
- Claude Code Commands Cheat Sheet
- OpenAI Codex Commands Cheat Sheet
- Most Popular Agent Skills on GitHub for Coding Agents









