OpenCode CLI Cheatsheet - Open-Source TUI AI Coding Agent Full Reference

All OpenCode terminal AI coding agent commands in one place — from resume to model/agent selection, MCP, and session sharing — organized by scenario. Copy and go.

AI CLI·33 commands·Last updated 2026-08-21

Launch & Run 5

opencode
Start the default interactive TUI
opencode "Refactor the auth module"
Start a session with an initial prompt
opencode -c
Continue the most recent session (--continue)
opencode -s abc123
Resume a session by ID (--session)
opencode --fork
Fork the current session into a new branch

CLI Flags 5

opencode -m anthropic/claude-sonnet "task"
Set provider/model (--model)
opencode --agent build "Implement login page"
Run with a named subagent (--agent)
opencode --prompt "Explain this function"
Single non-interactive prompt then exit
opencode --port 4096
Set the service port
opencode --hostname 0.0.0.0
Bind the listening address

Subcommands · agent / auth 5

opencode agent create <name>
Create a custom subagent
opencode agent list
List configured subagents
opencode auth login
Interactive provider sign-in
opencode auth list
List authenticated providers
opencode auth logout
Sign out

Subcommands · github / mcp 5

opencode github install
Install the GitHub integration
opencode github run
Run GitHub-related tasks
opencode mcp add <name> <url>
Add an MCP server
opencode mcp list
List configured MCP servers
opencode mcp auth
Authenticate an MCP server

Serve & Runtime 5

opencode run "task"
Run once and exit (good for automation)
opencode serve
Start the background service
opencode web
Open the Web UI
opencode attach
Attach to a running session
opencode upgrade
Upgrade to the latest version

Interactive Slash Commands 8

/help
List all available commands
/sessions
Open the session picker
/share /unshare
Share / unshare the current session
/compact /summarize
Compact / summarize to free the window
/models /themes
Switch model / theme
/init
Generate project config
/undo /redo
Undo / redo the last step
/exit /quit /q
Quit the TUI

Tips

  • OpenCode is an open-source Claude Code-style TUI; set the backend with `-m provider/model` (Anthropic/OpenAI/local) to avoid vendor lock-in.
  • For automation use `opencode run "..."` to execute once and exit — lighter than a resident TUI for CI codegen/review.
  • Encode recurring workflows as subagents (`opencode agent create`) and call them with `--agent` — more stable than repeating instructions in prompts.
  • Share a session with `/share` for a read-only link to send a colleague the agent's solution without exposing your local environment.

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Aug 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us