| opencode | Start the TUI in the current directory |
| opencode /path | Start in a specific project |
| opencode run "…" | One-shot, non-interactive prompt |
| opencode auth login | Add a provider & API key |
curl -fsSL https://opencode.ai/v2/install | bash npm install -g @opencode/cli brew install anomalyco/tap/opencode-v2
| @ file | Attach a file; add #20-45 for a line range |
| @ agent | Invoke a subagent (e.g. @explore) |
| ! command | Enter shell mode; output joins the context |
| / command | Run a built-in or custom slash command |
Press Ctrl+X, then the key — 2 s window (leader_timeout). While it works, Ctrl+X Enter queues a prompt.
| n | New session /new |
| l | List / switch sessions /sessions |
| m | Select model /models |
| a | Select agent /agents |
| c | Compact / summarize session |
| u | Undo last message + changes |
| r | Redo undone work |
| x | Export session to editor |
| e | Edit prompt in $EDITOR |
| g | Session timeline |
| s | Status view |
| t | Toggle terminal pane |
| w | Close session tab |
| y | Copy message |
| q | Exit OpenCode |
No leader: F2 models · Ctrl+A providers
Ctrl+Tab tabs · Ctrl+T variant · Ctrl+R rename
| Enter | Send prompt |
| Shift+Enter | New line — also Ctrl/Alt+Enter, Ctrl+J |
| Ctrl+A / E | Start / end of line |
| Alt+B / F | Word backward / forward |
| Ctrl+K / U | Kill to end / start of line |
| Ctrl+W | Kill previous word |
| Esc | Interrupt the running session |
| /new /clear | New session |
| /sessions | Resume a session /resume |
| /models | List models |
| /agents | Switch primary agent |
| /compact | Compact context /summarize |
| /undo · /redo | Revert / restore messages & files |
| /editor · /export | Compose or export via $EDITOR |
| /diff | Review changed files |
| /btw <q> | Side question; answer stays out of context |
| /highlights | What's new in this release |
| /connect | Add a provider |
| /help · /exit | Help dialog / quit |
Drop a Markdown file in .opencode/commands/ (project) or ~/.config/opencode/commands/ (global). File name = command name.
--- .opencode/commands/test.md --- description: Run tests with coverage agent: build model: anthropic/claude-sonnet-5-5 --- Run the suite. Focus on failures: $ARGUMENTS Recent commits: !`git log --oneline -10`
Placeholders: $ARGUMENTS, $1, $2… · !`cmd` injects output · @file injects a file.
| build · primary | Default. All tools, may ask questions |
| plan · primary | Edits denied except ~/.opencode/plan |
| general · sub | Full tools; no questions or subagents |
| explore · sub | Fast search; no edits or subagents |
Shift+Tab cycles agents. Invoke a subagent with @name. Navigate child sessions with ↓ to enter, ←/→ to cycle, ↑ to return.
opencode.json(c) | Project & server settings |
cli.json | CLI/TUI settings — global only |
~/.config/opencode/ | Agents, commands, plugins |
{ "$schema": "https://opencode.ai/v2/cli.json", "theme": { "name": "tokyonight", "mode": "system" }, "tabs": { "mode": "auto", "layout": "horizontal" }, "keybinds": { "leader": "ctrl+x" }, "leader": { "timeout": 2000 } }
Project settings live in opencode.json(c); cli.json has no project-local file and reloads live.
| opencode | Start the TUI |
| opencode run "…" | One-shot; --format json for scripts |
| opencode mini | Minimal interactive interface |
| opencode session | list · delete · export · import |
| opencode auth | login · list · logout · switch |
| opencode models | List provider/model pairs |
| opencode mcp | add · list · auth · logout |
| opencode plugin | add · list · update · check |
| opencode stats | Usage & cost (--days 7) |
| opencode serve | API server |
| opencode pair | Web/app link + QR (5 min) |
| opencode service | start · stop · status · set |
| opencode reload | Reload config, keep sessions |
| opencode api | Call the running server |
| opencode debug | config · paths · agents |
| opencode upgrade | Update alias: update |
In opencode.json(c). Ordered rules; the last match wins — each is action + resource + effect.
"permissions": [ { "action": "shell", "resource": "*", "effect": "ask" }, { "action": "shell", "resource": "git *", "effect": "allow" }, { "action": "shell", "resource": "rm *", "effect": "deny" } ]
| Actions | read edit glob grep shell subagent skill webfetch websearch external_directory question execute |
| Defaults | Base policy allows; .env reads ask; no match → ask |
| Approvals | once · always (saves a project rule) · reject |
Agent rules append via agents.<id>.permissions. opencode run --auto accepts whatever is not denied.
| Ctrl+Tab / Ctrl+Shift+Tab | Next / previous tab |
| Ctrl+X W / Ctrl+Shift+T | Close / reopen tab |
| Ctrl+O | Recent sessions & projects |
| Ctrl+X T | Toggle terminal pane |
| Ctrl+X ← / → | Focus session / right pane |
| Ctrl+X ↑ | Close terminal pane |
In /diff: d scope · j/k move · n/p file · m reviewed · v split · f fullscreen · ? help
OPENCODE_CLI_CONFIG_CONTENT | Inline cli.json settings |
OPENCODE_CONFIG | Path to a config file |
OPENCODE_CONFIG_DIR | Extra config directory |
OPENCODE_SERVER_PASSWORD | Server basic auth |