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.
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.
How slash commands fit a typical workflow
mermaid
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]
First session in a repo
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
During a task
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
Session control and undo
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.
Export and share
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
Built-in slash commands (complete reference)
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
—
Toggle reasoning block visibility
—
/undo
—
Undo last turn + revert files (Git-backed)
Ctrl+x u
/unshare
—
Unshare current session
—
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 slash commands (.md and JSON)
Custom commands are OpenCode's primary extensibility layer—repetitive prompts defined once, invoked with /command-name.
Scopes
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.
Markdown command example
Create .opencode/commands/test.md:
markdown
---
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:
bash
/test
JSON config alternative
jsonc
{"$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"}}}
Frontmatter / JSON options
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.
Template placeholders
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:
markdown
---
description: Create a new component
---
Create a new React component named $ARGUMENTS with TypeScript support.
Include proper typing and basic structure.
bash
/component Button
Coverage analysis example:
markdown
---
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:
markdown
---
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.
At commands (@): 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:
text
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).
Bash commands (!): 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 configuration (tui.json)
TUI behavior is configured separately from opencode.json via tui.json or tui.jsonc:
/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
Quick custom command starter
bash
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
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.