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.
Launch & Run 5
opencodeStart the default interactive TUI
opencode "Refactor the auth module"Start a session with an initial prompt
opencode -cContinue the most recent session (--continue)
opencode -s abc123Resume a session by ID (--session)
opencode --forkFork 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 4096Set the service port
opencode --hostname 0.0.0.0Bind the listening address
Subcommands · agent / auth 5
opencode agent create <name>Create a custom subagent
opencode agent listList configured subagents
opencode auth loginInteractive provider sign-in
opencode auth listList authenticated providers
opencode auth logoutSign out
Subcommands · github / mcp 5
opencode github installInstall the GitHub integration
opencode github runRun GitHub-related tasks
opencode mcp add <name> <url>Add an MCP server
opencode mcp listList configured MCP servers
opencode mcp authAuthenticate an MCP server
Serve & Runtime 5
opencode run "task"Run once and exit (good for automation)
opencode serveStart the background service
opencode webOpen the Web UI
opencode attachAttach to a running session
opencode upgradeUpgrade to the latest version
Interactive Slash Commands 8
/helpList all available commands
/sessionsOpen the session picker
/share /unshareShare / unshare the current session
/compact /summarizeCompact / summarize to free the window
/models /themesSwitch model / theme
/initGenerate project config
/undo /redoUndo / redo the last step
/exit /quit /qQuit 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