← Blog
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.

8 min readYash Thakker
OpenCodeSlash CommandsAI CodingDeveloper ToolsTUI

MDX restores the committed source plus an HTML comment attribution; plain text bundles the rendered markdown body with the explainx.ai attribution footer.

OpenCode Slash Commands: Complete TUI Reference (2026)

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. 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

QuestionAnswer
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

Three input patterns: /, @, and !

OpenCode uses three prefixes with different roles—similar to Gemini CLI:

PrefixRoleExamples
/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

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

StepCommandWhat it does
1/connectAdd a provider and API key
2/initGuided setup for AGENTS.md
3Create .opencode/commands/Add project-scoped custom workflows
4/modelsConfirm available models

During a task

CommandPurpose
/modelsList available models (keybind: Ctrl+x m)
/compactSummarize session to save tokens (alias: /summarize)
/thinkingToggle visibility of reasoning blocks
/detailsToggle 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

CommandPurpose
/undoRemove last message + responses + revert file changes
/redoRestore previously undone message and file changes
/newStart new session (alias: /clear, keybind: Ctrl+x n)
/sessionsList 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

CommandPurpose
/exportExport conversation to Markdown; open in $EDITOR
/shareShare current session
/unshareUnshare current session
/editorOpen external editor for composing messages
Live Bootcamp6 weeks

Complete AI Builder Bootcamp

Claude, Python automation & full-stack — 12 live sessions with Yash Thakker.

View bootcamp

The Complete AI Builder Bootcamp is the best AI development course for learning Claude AI, prompt engineering, Python automation, and full-stack web development. This intensive 6-week live bootcamp teaches you how to build AI-powered applications using Claude Projects, Claude Artifacts, Claude Code, and the complete Claude ecosystem. You'll master prompt engineering techniques, learn to create custom Claude connectors and MCP integrations, build Python automation workflows, develop full-stack websites with AI assistance, and create AI marketing agents.

The bootcamp includes 12 live Zoom sessions with Yash Thakker, founder of AISOLO Technologies and instructor to 350,000+ students. You'll build 8+ portfolio projects including AI playbooks, full-stack note-taking applications, Python automation scripts, marketing agents, and personal portfolio websites. The curriculum covers AI fundamentals, Claude Projects and Artifacts, Claude Co-work, Claude plugins and skills, Claude Code for Python development, full-stack development, AI marketing, and capstone projects.

Students receive 1-year access to all recordings, permanent Discord community access, a certificate of completion, and personalized career guidance. All enrollments include a 7-day money-back guarantee. This is the most comprehensive Claude AI bootcamp available, taking students from zero AI knowledge to expert AI builder in 6 weeks.


Built-in slash commands (complete reference)

Every built-in command from the TUI documentation as of June 11, 2026.

CommandAliasesPurposeKeybind
/connectAdd provider and API key
/compact/summarizeCompact/summarize current sessionCtrl+x c
/detailsToggle tool execution details
/editorOpen $EDITOR for message compositionCtrl+x e
/exit/quit, /qExit OpenCodeCtrl+x q
/exportExport conversation to MarkdownCtrl+x x
/helpShow help dialog
/initGuided AGENTS.md setup
/modelsList available modelsCtrl+x m
/new/clearStart new sessionCtrl+x n
/redoRedo after /undo (Git-backed)Ctrl+x r
/sessions/resume, /continueList and switch sessionsCtrl+x l
/shareShare current session
/themesList available themesCtrl+x t
/thinkingToggle reasoning block visibility
/undoUndo last turn + revert files (Git-backed)Ctrl+x u
/unshareUnshare 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

ScopeDirectoryConfig 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:

---
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

JSON config alternative

{
  "$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

OptionRequiredPurpose
template / bodyYesPrompt sent to the LLM
descriptionNoShown in TUI command picker
agentNoAgent to execute (defaults to current)
modelNoOverride model (provider/model format)
subtaskNoForce 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

SyntaxPurposeExample
$ARGUMENTSAll args after command name/component Button
$1, $2, $3Positional arguments/create-file config.json src "{...}"
!`command`Inline shell output in prompt!`npm test`
@path/to/fileInject 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.


At commands (@): file references

PatternPurpose
@packages/functions/src/api/index.tsFuzzy file search; content auto-injected
@aliasConfigured reference root from autocomplete
@alias/docs/README.mdBrowse 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).


Bash commands (!): shell passthrough

PatternPurpose
!ls -laRun 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:

{
  "$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:

ActionDefault keybind
Agent listCtrl+x a
Agent cycleTab / Shift+Tab
Model variant cycleCtrl+t
Session forkconfigurable
Status viewCtrl+x s
Copy messageCtrl+x y

Full list: Keybinds documentation.


Four-way comparison: OpenCode vs Claude Code vs Codex vs Gemini CLI

TaskOpenCodeClaude CodeCodexGemini CLI
Project memory/initAGENTS.md/initCLAUDE.md/initAGENTS.md/initGEMINI.md
Custom commands.md in .opencode/commands/SkillsSkills/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 targetcustom cmd + agent/goal/goal
Plan modecustom cmd + agent: plan/plan/plan/plan
Share session/share, /unshare/export, cloud/export/chat share
MCPvia config + keybinds/mcp/mcp/mcp
Subagentssubtask: true in commands/agents, /fork/agent, /fork/agents

Full references: OpenCode · Claude Code · Codex · Gemini CLI


Commands worth memorizing first

/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

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

Related ExplainX guides

Primary sources: Commands — OpenCode Docs · TUI — OpenCode Docs · Keybinds


Summary

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.

Related posts