| name | opencode-coding-agent |
|---|---|
| description | SSH-based access to opencode TUI coding agent in a remote container. Supports TUI mode, non-interactive run mode, server/attach patterns, and full CLI command set. Use when the user wants to delegate coding tasks to an opencode instance running remotely. Workflow: SSH into host, cd to projects/<repo>, create feature branch from updated default branch, launch opencode (TUI or run mode), execute coding instructions, commit with conventional prefix + signature, and push to GitHub. NEVER commit to default/main branch. |
SSH-based access to an opencode TUI (terminal user interface) coding agent running in an LXC container.
Required environment variables (set by the user):
OPENCODE_HOST- SSH hostname/IP of the LXC containerOPENCODE_USERNAME- SSH username for the LXCOPENCODE_PASSWORD- SSH password for the LXC
ssh $OPENCODE_USERNAME@$OPENCODE_HOSTcd ~/projectsIf the repo already exists:
cd <repo-name>If the repo needs to be cloned:
git clone <github-url> <repo-name>
cd <repo-name>CRITICAL: Always create feature branches from the updated default branch.
# 1. If there are uncommitted changes, stash them first (before anything else)
git stash # This saves your work temporarily - prevents checkout conflicts
# 2. Checkout the default branch (main/master)
git checkout main # or master, depending on the repo
# 3. Pull latest changes
git pull origin main
# 4. Create and checkout the new feature branch
git checkout -b feature/<descriptive-name>
# Note: Stashed changes remain in the stash list (not discarded). They are left untouched - do NOT restore them to the feature branch as they are from incomplete work or failed experiments.Interactive TUI Mode (recommended for large/multi-step work):
opencodeThis mode maintains session context across multiple prompts, allowing you to:
- Work through complex tasks iteratively
- Maintain conversation history
- Refine and modify work in the same session
- Resume later with
--continue
Track Session ID: When opencode starts, it will display a session ID. Save this ID for later resumption:
session: abc123xyz
You can also list sessions to find it later:
opencode session listTUI Mode with Prompt (one-shot):
opencode --prompt "Your prompt here"Non-Interactive Mode (for scripting/single tasks):
opencode run "Your prompt here"With specific model:
opencode --prompt "Your prompt here" --model provider/model
# or
opencode run --model provider/model "Your prompt here"Attach files to prompt:
opencode --prompt "Explain this code" --file ./src/lru.jsResume Session (after disconnect or to continue work):
opencode --continue # Resume last session
# or
opencode --session abc123xyz # Resume specific session by IDAttach to running server:
opencode attach http://localhost:4096Start headless server (for API access):
opencode serve --port 4096 --hostname 0.0.0.0
# Set password for auth: OPENCODE_SERVER_PASSWORD=secretSecurity Note: Always set OPENCODE_SERVER_PASSWORD when exposing the server on a network. Default username is opencode. Default hostname is 127.0.0.1 (localhost only).
mDNS Discovery: Enable mDNS for network discovery:
opencode serve --mdns --mdns-domain myproject.localCORS for browser clients:
opencode serve --cors http://localhost:5173 --cors https://app.example.comStart with web interface:
opencode web --port 4096CRITICAL: Never commit to the default/main branch.
# Stage changes
git add .
# Commit with conventional prefix and signature
git commit -m "<type>: <description> -- Signed-off-by: Mads <openclaw>"
Examples:
- `feat: add user authentication`
- `doc: update README with installation steps`
- `fix: resolve null pointer in parser`
- `chore: update dependencies`
# Push to GitHub
git push -u origin <current-branch>Every commit must follow this format:
<type>: <description> -- Signed-off-by: Mads <openclaw>
Common types:
feat:- New featurefix:- Bug fixdoc:- Documentationrefactor:- Code refactoringchore:- Maintenance/taskstest:- Adding/fixing testsstyle:- Formatting, missing semicolons, etc.
Example:
git commit -m "feat: add user authentication -- Signed-off-by: Mads <openclaw>"
| Command | Description |
|---|---|
opencode [project] |
Start TUI (default) |
opencode run "prompt" |
Non-interactive mode, run once and exit |
opencode serve |
Start headless HTTP server (API access) |
opencode web |
Start server with web interface |
opencode attach [url] |
Attach TUI to running backend |
| Flag | Description | Default |
|---|---|---|
--port |
Port to listen on | 4096 |
--hostname |
Hostname to listen on | 127.0.0.1 |
--mdns |
Enable mDNS discovery | false |
--mdns-domain |
Custom mDNS domain | opencode.local |
--cors |
Browser origins (can be passed multiple times) | [] |
Example:
opencode serve --port 4096 --hostname 0.0.0.0 --mdns --cors http://localhost:5173When in the TUI, type / followed by a command name:
| Command | Keybind | Description |
|---|---|---|
/connect |
ctrl+x c | Add a provider (API keys) |
/compact |
ctrl+x c | Compact session (alias: /summarize) |
/details |
ctrl+x d | Toggle tool execution details |
/editor |
ctrl+x e | Open external editor for composing messages |
/exit |
ctrl+x q | Exit OpenCode (aliases: /quit, /q) |
/export |
ctrl+x x | Export conversation to Markdown |
/help |
ctrl+x h | Show help dialog |
/init |
ctrl+x i | Guided setup for AGENTS.md |
/models |
ctrl+x m | List available models |
/new |
ctrl+x n | Start new session (alias: /clear) |
/redo |
ctrl+x r | Redo previously undone message |
/sessions |
ctrl+x l | List and switch sessions (aliases: /resume, /continue) |
/share |
ctrl+x s | Share current session |
/themes |
ctrl+x t | List available themes |
/thinking |
Toggle thinking/reasoning visibility | |
/undo |
ctrl+x u | Undo last message (uses Git) |
/unshare |
Unshare current session |
Session Management Commands:
/sessions- List and switch between sessions/share- Share current session/unshare- Unshare current session/new- Start fresh session/exit- Quit TUI
File References: Use @ to reference files (fuzzy search)
How is auth handled in @packages/functions/src/api/index.ts?
Bash Commands: Start message with ! to run shell commands
!ls -la
Editor Setup:
export EDITOR="code --wait" # VS Code
export EDITOR=vim
export EDITOR=nano| Command | Description |
|---|---|
opencode session list |
List all sessions |
opencode export [sessionID] |
Export session as JSON |
opencode import <file> |
Import session from file or URL |
| Command | Description |
|---|---|
opencode agent list |
List available agents |
opencode agent create |
Create new agent with custom config |
opencode models [provider] |
List available models |
opencode models --refresh |
Refresh model cache |
| Command | Description |
|---|---|
opencode auth login |
Configure provider API keys |
opencode auth list |
Show authenticated providers |
opencode auth logout |
Clear provider credentials |
| Command | Description |
|---|---|
opencode mcp add |
Add MCP server (local or remote) |
opencode mcp list |
List configured MCP servers |
opencode mcp auth [name] |
Authenticate with OAuth server |
Use Case: MCP servers extend opencode with external tools (databases, APIs, file systems). Add servers as needed for specific tasks.
| Command | Description |
|---|---|
opencode github install |
Install GitHub agent in repo (sets up Actions workflow) |
opencode github run |
Run GitHub agent (typically in Actions) |
Use Case: The GitHub agent can automate PR creation, reviews, and repo management. Install once per repo for automated workflows.
| Command | Description |
|---|---|
opencode stats |
Show token usage and cost stats |
opencode upgrade |
Update to latest version |
opencode uninstall |
Remove opencode and files |
Customize TUI behavior through tui.json (or tui.jsonc):
{
"$schema": "https://opencode.ai/tui.json",
"theme": "opencode",
"keybinds": {
"leader": "ctrl+x"
},
"scroll_speed": 3,
"scroll_acceleration": {
"enabled": true
},
"diff_style": "auto"
}Options:
theme- UI theme (see/themesin TUI)keybinds.leader- Leader key for shortcuts (default: ctrl+x)scroll_speed- Scroll speed (default: 3)scroll_acceleration.enabled- macOS-style scroll accelerationdiff_style- "auto" (adaptive) or "stacked" (single-column)
Use OPENCODE_TUI_CONFIG to load a custom config path.
| Flag | Short | Description |
|---|---|---|
--continue |
-c |
Continue last session |
--session |
-s |
Session ID to continue |
--fork |
Fork session when continuing | |
--prompt |
Prompt to use | |
--model |
-m |
Model (provider/model format) |
--agent |
Agent to use | |
--port |
Port to listen on | |
--hostname |
Hostname to listen on | |
--file |
-f |
File(s) to attach |
--format |
Output format: default or json (raw JSON events for scripting) |
|
--title |
Title for the session (uses truncated prompt if no value provided) | |
--share |
Share the session (requires OPENCODE_AUTO_SHARE or manual sharing) | |
--help |
-h |
Display help |
--version |
-v |
Print version |
| Variable | Description |
|---|---|
OPENCODE_CONFIG |
Path to config file |
OPENCODE_CONFIG_DIR |
Path to config directory (for agents, commands, plugins) |
OPENCODE_MODELS_URL |
Custom URL for models config |
OPENCODE_SERVER_PASSWORD |
HTTP basic auth password for serve/web (username: opencode) |
OPENCODE_SERVER_USERNAME |
Override basic auth username (default: opencode) |
OPENCODE_DISABLE_AUTOUPDATE |
Disable automatic update checks |
OPENCODE_TUI_CONFIG |
Path to custom TUI config file |
OPENCODE_CONFIG_CONTENT |
Inline config (JSON) for runtime overrides |
Sharing is configured in opencode.json (not via env var):
{
"share": "manual" // "manual" (default), "auto", or "disabled"
}manual- Allow manual sharing via/sharecommand (default)auto- Automatically share new conversationsdisabled- Disable sharing entirely
| Variable | Description |
|---|---|
OPENCODE_EXPERIMENTAL |
Enable all experimental features |
OPENCODE_EXPERIMENTAL_PLAN_MODE |
Enable plan mode |
OPENCODE_EXPERIMENTAL_FILEWATCHER |
Enable file watcher for entire dir |
Runtime config: opencode.ai/config.json
TUI config: opencode.ai/tui.json
Use these schema URLs in your config files for editor validation:
{
"$schema": "https://opencode.ai/config.json",
// ... config options
}- Always start from default branch - Checkout main/master and pull latest before creating feature branch
- Stash uncommitted changes - If working directory has changes, stash them before branching
- Work inside the
projectsdirectory - All opencode sessions must run from~/projects - Use descriptive branch names - Include what the feature/fix does
- Use conventional commit prefixes - Match the type of change
- Add signature to every commit - Required for attribution
- Push after each logical unit of work - Don't leave unpushed commits
- Save session IDs - For long tasks, note the session ID to resume if disconnected
- Track token usage - Use
opencode statsto monitor costs for expensive tasks
After completing a task:
- Exit opencode:
/exit(or/quit,/q, orCtrl+C) - Exit SSH session
- Report completion to the user with:
- Branch name created
- Commit summary
- GitHub URL to the branch (if available)
- For single-file changes: Use
opencode --prompt "..."for quick one-shot tasks - For multi-file refactors: Use interactive TUI mode (
opencode) to maintain context - For long tasks: Note the session ID to resume if SSH disconnects
- For expensive tasks: Run
opencode statsto track token usage and costs - For automation: Use
opencode runwith--format jsonfor scriptable output - For security: Always set
OPENCODE_SERVER_PASSWORDwhen exposing servers on a network - In TUI: Use
@filenameto reference files,!commandto run shell commands - For context management: Use
/compactto reduce session size during long tasks - For file changes: Use
/undoand/redoto revert/restore changes (Git-based)
TUI + Server Model: When you run opencode, it starts both a TUI client and an HTTP server. The TUI talks to the server via the OpenAPI endpoint. This architecture allows:
- Multiple clients (TUI, web, IDE plugins) to connect to one server
- Programmatic control via HTTP API
- Session persistence and remote access
Server Endpoints: View the full OpenAPI 3.1 spec at http://<host>:<port>/doc
Key APIs:
/session- Create, list, fork, share, summarize sessions/session/:id/message- Send messages, get responses/file/content- Read files programmatically/find- Search files and symbols/mcp- Manage MCP servers/provider- OAuth authentication for providers