v2
OpenCode Cheat Sheet
OpenCode v2 — the open source AI coding agent for your terminal. Talk to your codebase, run tools, edit files, and ship — with any model, any provider, fully local-first.
Get Started
opencodeStart the TUI in the current directory
opencode /pathStart in a specific project
opencode run "…"One-shot, non-interactive prompt
opencode auth loginAdd a provider & API key
Install
curl -fsSL https://opencode.ai/v2/install | bash
npm install -g @opencode/cli
brew install anomalyco/tap/opencode-v2
Prompt Syntax
@ fileAttach a file; add #20-45 for a line range
@ agentInvoke a subagent (e.g. @explore)
! commandEnter shell mode; output joins the context
/ commandRun a built-in or custom slash command
Leader Key Ctrl + X, then…

Press Ctrl+X, then the key — 2 s window (leader_timeout). While it works, Ctrl+X Enter queues a prompt.

nNew session /new
lList / switch sessions /sessions
mSelect model /models
aSelect agent /agents
cCompact / summarize session
uUndo last message + changes
rRedo undone work
xExport session to editor
eEdit prompt in $EDITOR
gSession timeline
sStatus view
tToggle terminal pane
wClose session tab
yCopy message
qExit OpenCode

No leader: F2 models · Ctrl+A providers
Ctrl+Tab tabs · Ctrl+T variant · Ctrl+R rename

Input & Editing
EnterSend prompt
Shift+EnterNew line — also Ctrl/Alt+Enter, Ctrl+J
Ctrl+A / EStart / end of line
Alt+B / FWord backward / forward
Ctrl+K / UKill to end / start of line
Ctrl+WKill previous word
EscInterrupt the running session
Slash Commands
/new /clearNew session
/sessionsResume a session /resume
/modelsList models
/agentsSwitch primary agent
/compactCompact context /summarize
/undo · /redoRevert / restore messages & files
/editor · /exportCompose or export via $EDITOR
/diffReview changed files
/btw <q>Side question; answer stays out of context
/highlightsWhat's new in this release
/connectAdd a provider
/help · /exitHelp dialog / quit
Custom Commands

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.

Agents
build · primaryDefault. All tools, may ask questions
plan · primaryEdits denied except ~/.opencode/plan
general · subFull tools; no questions or subagents
explore · subFast search; no edits or subagents

Shift+Tab cycles agents. Invoke a subagent with @name. Navigate child sessions with ↓ to enter, ←/→ to cycle, ↑ to return.

Configuration
opencode.json(c)Project & server settings
cli.jsonCLI/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.

CLI Commands
opencodeStart the TUI
opencode run "…"One-shot; --format json for scripts
opencode miniMinimal interactive interface
opencode sessionlist · delete · export · import
opencode authlogin · list · logout · switch
opencode modelsList provider/model pairs
opencode mcpadd · list · auth · logout
opencode pluginadd · list · update · check
opencode statsUsage & cost (--days 7)
opencode serveAPI server
opencode pairWeb/app link + QR (5 min)
opencode servicestart · stop · status · set
opencode reloadReload config, keep sessions
opencode apiCall the running server
opencode debugconfig · paths · agents
opencode upgradeUpdate alias: update
Permissions

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" }
]
Actionsread edit glob grep shell subagent skill webfetch websearch external_directory question execute
DefaultsBase policy allows; .env reads ask; no match → ask
Approvalsonce · always (saves a project rule) · reject

Agent rules append via agents.<id>.permissions. opencode run --auto accepts whatever is not denied.

Tabs, Panes & Diffs
Ctrl+Tab / Ctrl+Shift+TabNext / previous tab
Ctrl+X W / Ctrl+Shift+TClose / reopen tab
Ctrl+ORecent sessions & projects
Ctrl+X TToggle 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

Environment
OPENCODE_CLI_CONFIG_CONTENTInline cli.json settings
OPENCODE_CONFIGPath to a config file
OPENCODE_CONFIG_DIRExtra config directory
OPENCODE_SERVER_PASSWORDServer basic auth