explainx / blog
OpenCode Slash Commands: Complete TUI Reference (2026)
Every OpenCode slash command—/init, /undo, /compact, custom .md commands, @ file refs, and built-ins. Workflow guide from official docs.
explainx / blog
Every OpenCode slash command—/init, /undo, /compact, custom .md commands, @ file refs, and built-ins. Workflow guide from official docs.
Jun 11, 2026
Claude Code exposes 90+ slash commands for setup, parallel agents, review, memory, and shipping. This is the complete reference: what each command does, when to use it, and how they fit a typical workflow.
Jun 11, 2026
Codex CLI exposes 40+ slash commands for models, permissions, goals, subagents, review, and session control. This is the complete reference: what each command does, when to use it, and how they fit a typical workflow.
Jun 11, 2026
Cursor CLI exposes 25+ slash commands for Plan/Ask modes, models, sandbox, MCP, rules, and session control. This is the complete reference from official docs plus how commands fit a typical workflow.
OpenCode is an open-source agentic terminal for working with LLMs on your codebase—supporting multiple providers, subagents, MCP servers, and a keyboard-first TUI. For the full product guide (desktop app, Zen, LSP, privacy, harness comparison), see OpenCode: Open Source AI Coding Agent (2026). Beyond natural-language prompts, it exposes 17 built-in slash commands, custom markdown commands in .opencode/commands/, and @ / ! input patterns for file injection and shell passthrough.
Custom commands are defined in markdown with YAML frontmatter—you can override built-ins, pin agents and models per command, and force subagent invocation with subtask: true. This article is a complete reference from the official Commands and TUI documentation.
It is not a replacement for upstream docs. Use this as a map of the surface area and a workflow guide; verify behavior against opencode.ai/docs before you ship team runbooks.
Sister guides: Claude Code · Codex · Gemini CLI · Cursor CLI
TL;DR
| Question | Answer |
|---|---|
| How do I see all commands? | Type / in the TUI; run /help or open command palette with Ctrl+p |
| Custom commands? | .md files in .opencode/commands/ or ~/.config/opencode/commands/ |
| First session in a repo? | /connect → /init → define custom commands |
| Long conversation? | /compact (alias /summarize) to free context |
| Attach files? | @path/to/file in prompts (fuzzy search, git-aware) |
| Run shell? | !ls -la at start of message |
| Undo edits? | /undo and /redo (requires Git repo) |
| Project memory file? | AGENTS.md via /init |
| Sister guides? | Claude Code · Codex · Gemini CLI · Cursor CLI |
/, @, and !OpenCode uses three prefixes with different roles—similar to Gemini CLI:
| Prefix | Role | Examples |
|---|---|---|
/ | Built-in or custom slash commands | /init, /compact, /test |
@ | Fuzzy file search; inject content into prompt | @packages/functions/src/api/index.ts |
! | Run shell command; output added as tool result | !git status |
Configured reference aliases also appear in @ autocomplete—type @alias for a reference root or @alias/ to browse files inside it.
flowchart LR
A[Setup /connect /init] --> B[Work /models custom cmds]
B --> C[Context @files !shell]
C --> D[Undo /undo /redo]
D --> E[Share /share /export]
E --> F[Sessions /new /sessions]
| Step | Command | What it does |
|---|---|---|
| 1 | /connect | Add a provider and API key |
| 2 | /init | Guided setup for AGENTS.md |
| 3 | Create .opencode/commands/ | Add project-scoped custom workflows |
| 4 | /models | Confirm available models |
| Command | Purpose |
|---|---|
/models | List available models (keybind: Ctrl+x m) |
/compact | Summarize session to save tokens (alias: /summarize) |
/thinking | Toggle visibility of reasoning blocks |
/details | Toggle tool execution details |
@<path> | Inject file content via fuzzy search |
!<cmd> | Run shell command; output enters conversation |
Custom /review, /test, etc. | Reusable prompts from .md command files |
| Command | Purpose |
|---|---|
/undo | Remove last message + responses + revert file changes |
/redo | Restore previously undone message and file changes |
/new | Start new session (alias: /clear, keybind: Ctrl+x n) |
/sessions | List and switch sessions (aliases: /resume, /continue) |
Git requirement: /undo and /redo use Git internally to manage file changes—your project must be a Git repository.
| Command | Purpose |
|---|---|
/export | Export conversation to Markdown; open in $EDITOR |
/share | Share current session |
/unshare | Unshare current session |
/editor | Open external editor for composing messages |
Every built-in command from the TUI documentation as of June 11, 2026.
| Command | Aliases | Purpose | Keybind |
|---|---|---|---|
/connect | — | Add provider and API key | — |
/compact | /summarize | Compact/summarize current session | Ctrl+x c |
/details | — | Toggle tool execution details | — |
/editor | — | Open $EDITOR for message composition | Ctrl+x e |
/exit | /quit, /q | Exit OpenCode | Ctrl+x q |
/export | — | Export conversation to Markdown | Ctrl+x x |
/help | — | Show help dialog | — |
/init | — | Guided AGENTS.md setup | — |
/models | — | List available models | Ctrl+x m |
/new | /clear | Start new session | Ctrl+x n |
/redo | — | Redo after /undo (Git-backed) | Ctrl+x r |
/sessions | /resume, /continue | List and switch sessions | Ctrl+x l |
/share | — | Share current session | — |
/themes | — | List available themes | Ctrl+x t |
/thinking |
Leader key: Default leader is Ctrl+x—many shortcuts require leader first (e.g. Ctrl+x then n for new session). Customize via tui.json keybinds.
Command palette: Ctrl+p opens the full command list beyond slash autocomplete.
Note: Custom commands with the same name override built-ins. If you define .opencode/commands/init.md, it replaces /init.
Custom commands are OpenCode's primary extensibility layer—repetitive prompts defined once, invoked with /command-name.
| Scope | Directory | Config alternative |
|---|---|---|
| Global | ~/.config/opencode/commands/ | command key in opencode.jsonc |
| Project | .opencode/commands/ | Same JSON config, project-scoped |
Check project commands into Git for team workflows.
Create .opencode/commands/test.md:
---
description: Run tests with coverage
agent: build
model: anthropic/claude-3-5-sonnet-20241022
---
Run the full test suite with coverage report and show any failures.
Focus on the failing tests and suggest fixes.
Invoke:
/test
{
"$schema": "https://opencode.ai/config.json",
"command": {
"test": {
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
"description": "Run tests with coverage",
"agent": "build",
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
}
| Option | Required | Purpose |
|---|---|---|
template / body | Yes | Prompt sent to the LLM |
description | No | Shown in TUI command picker |
agent | No | Agent to execute (defaults to current) |
model | No | Override model (provider/model format) |
subtask | No | Force subagent invocation; isolates from primary context |
Agent behavior: If the specified agent is a subagent, the command triggers subagent invocation by default. Set subtask: false to disable. Set subtask: true to force subagent mode even when the agent is configured as primary.
| Syntax | Purpose | Example |
|---|---|---|
$ARGUMENTS | All args after command name | /component Button |
$1, $2, $3 | Positional arguments | /create-file config.json src "{...}" |
!`command` | Inline shell output in prompt | !`npm test` |
@path/to/file | Inject file content in command template | @src/components/Button.tsx |
Component example:
---
description: Create a new component
---
Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.
/component Button
Coverage analysis example:
---
description: Analyze test coverage
---
Here are the current test results:
!`npm test`
Based on these results, suggest improvements to increase coverage.
Review with file reference:
---
description: Review component
---
Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.
Shell commands in templates run from the project root; output becomes part of the prompt.
@): file references| Pattern | Purpose |
|---|---|
@packages/functions/src/api/index.ts | Fuzzy file search; content auto-injected |
@alias | Configured reference root from autocomplete |
@alias/docs/README.md | Browse files inside a reference alias |
Example prompt:
How is auth handled in @packages/functions/src/api/index.ts?
OpenCode respects .gitignore for file filtering (similar to Gemini CLI's git-aware @ behavior).
!): shell passthrough| Pattern | Purpose |
|---|---|
!ls -la | Run command; output added as tool result |
Start message with ! | Shell output enters the conversation |
Unlike slash commands, ! patterns are message prefixes, not CLI meta-commands.
tui.json)TUI behavior is configured separately from opencode.json via tui.json or tui.jsonc:
{
"$schema": "https://opencode.ai/tui.json",
"theme": "opencode",
"leader_timeout": 2000,
"keybinds": {
"leader": "ctrl+x",
"command_list": "ctrl+p"
},
"scroll_speed": 3,
"diff_style": "auto",
"mouse": true,
"attention": {
"enabled": true,
"notifications": true,
"sound": true
}
}
Use OPENCODE_TUI_CONFIG for a custom config path. Disable keybinds by setting value to "none".
Notable keybinds beyond slash commands:
| Action | Default keybind |
|---|---|
| Agent list | Ctrl+x a |
| Agent cycle | Tab / Shift+Tab |
| Model variant cycle | Ctrl+t |
| Session fork | configurable |
| Status view | Ctrl+x s |
| Copy message | Ctrl+x y |
Full list: Keybinds documentation.
| Task | OpenCode | Claude Code | Codex | Gemini CLI |
|---|---|---|---|---|
| Project memory | /init → AGENTS.md | /init → CLAUDE.md | /init → AGENTS.md | /init → GEMINI.md |
| Custom commands | .md in .opencode/commands/ | Skills | Skills/plugins | .toml in .gemini/commands/ |
| Free context | /compact | /compact | /compact | /compress |
| Switch model | /models | /model + /effort | /model | /model set |
| File attachment | @path | /ide | /mention, /ide | @path |
| Shell passthrough | !command | — | — | !command |
| Undo file changes | /undo, /redo | /rewind | — | /restore, /rewind |
| Autonomous target | custom cmd + agent | /goal | /goal | — |
| Plan mode | custom cmd + agent: plan | /plan | /plan | /plan |
| Share session | /share, /unshare | /export, cloud | /export | /chat share |
| MCP | via config + keybinds | /mcp | /mcp | /mcp |
| Subagents | subtask: true in commands | /agents, /fork | /agent, /fork | /agents |
Full references: OpenCode · Claude Code · Codex · Gemini CLI
/connect # add provider + API key
/init # AGENTS.md guided setup
/models # pick model
/compact # free context mid-session
@src/main.ts Explain this file # attach code
!git diff # shell output in chat
/undo # revert last turn + files
/sessions # switch saved sessions
/share # share session link
/export # markdown export
mkdir -p .opencode/commands
cat > .opencode/commands/plan.md << 'EOF'
---
description: Strategic plan only—no implementation
agent: plan
subtask: true
---
Create a step-by-step plan for: $ARGUMENTS
Do NOT write or modify code.
EOF
/plan Refactor the auth module
/goal on Codex and Claude CodePrimary sources: Commands — OpenCode Docs · TUI — OpenCode Docs · Keybinds
OpenCode's slash-command surface is lean on built-ins (17 commands) and deep on custom .md commands—with agent, model, and subtask overrides that none of the other three CLIs match one-to-one. The /undo / /redo pair with Git-backed file reversion is distinctive; so is subtask: true for context-isolated custom workflows.
Type /help or Ctrl+p to discover commands in your build. Treat opencode.ai/docs as source of truth; bookmark this guide alongside the Claude Code, Codex, Gemini CLI, and Cursor CLI references for cross-platform work.
Command names, keybinds, and custom command syntax reflect OpenCode documentation as of June 11, 2026. Re-check opencode.ai/changelog before documenting internal runbooks.
| — |
| Toggle reasoning block visibility |
| — |
/undo | — | Undo last turn + revert files (Git-backed) | Ctrl+x u |
/unshare | — | Unshare current session | — |