| name | opencode-cli |
| description | opencode CLI (anomalyco/opencode) comprehensive reference for the TUI, headless server, ACP server, web UI, sessions, agents, MCP servers, providers/auth, models, plugins, GitHub agent integration, stats, export/import, and debugging utilities from the command line. Includes guidance on which commands launch blocking interactive UIs and how to avoid them in scripted contexts. |
| license | CC-BY-NC-4.0 |
opencode CLI
Comprehensive reference for the opencode CLI (anomalyco/opencode) - the open source AI coding agent.
Version: 1.15.10 (current as of May 2026)
Source: https://github.com/anomalyco/opencode
Docs: https://opencode.ai/docs
Interactive vs Non-Interactive Commands
Some opencode commands launch a full-screen TUI or another long-running interactive process and will block the terminal until the user exits. That is the intended behavior for human use - it only becomes a problem when an automated agent runs them without a human at the keyboard.
Commands that block on an interactive UI / long-running process:
opencode (no subcommand) and opencode <project-path> - full-screen TUI
opencode attach <url> - remote TUI
opencode serve, opencode web, opencode acp - long-running servers
opencode mcp add, opencode mcp auth <name> - interactive prompts
opencode providers login (alias opencode auth login) - interactive picker / browser
opencode github install - interactive setup wizard
opencode db (no query) - opens an interactive sqlite3 shell
opencode debug wait - blocks indefinitely
If you are running unattended (e.g. inside another agent, in CI, or in a scripted shell), prefer the non-interactive equivalents:
- Use
opencode run "<prompt>" instead of the bare opencode TUI for one-shot prompts
- Pass
--format json to opencode run and opencode session list for machine-readable output
- Pass an explicit query to
opencode db "SELECT ..." instead of opening the bare shell
- Drive
opencode serve from a process supervisor; don't shell out to it from a single-shot script
If you are an interactive user (or a tool/skill that knows how to drive a TUI - e.g. a terminal-multiplexer wrapper, an ACP-aware editor, an expect-style harness), running the interactive commands directly is fine and supported.
When in doubt about an unfamiliar subcommand, run opencode <subcommand> --help first - the help text exits cleanly and tells you whether the command is interactive.
Prerequisites
Installation
curl -fsSL https://opencode.ai/install | bash
brew install anomalyco/tap/opencode
brew install opencode
npm i -g opencode-ai@latest
scoop install opencode
choco install opencode
sudo pacman -S opencode
paru -S opencode-bin
mise use -g opencode
nix run nixpkgs#opencode
nix run github:anomalyco/opencode
opencode --version
Authentication
opencode auth login
opencode auth login -p anthropic
opencode auth login -p openai -m "API Key"
opencode auth list
opencode auth ls
opencode auth logout
opencode providers list
opencode providers login
opencode providers logout
Credentials are stored at ~/.local/share/opencode/auth.json. Provider env vars (e.g. ANTHROPIC_API_KEY, OPENAI_API_KEY, GITHUB_TOKEN, AWS / Azure / Vertex creds) are auto-detected when set.
Showing Paths and Debug Info
opencode debug paths
opencode debug info
CLI Structure
opencode # Root - start TUI in cwd (interactive)
โโโ [project] # Start TUI in given project path (interactive)
โโโ run # One-shot prompt (non-interactive)
โโโ attach <url> # Connect TUI to a running server (interactive)
โโโ serve # Headless HTTP server (long-running)
โโโ web # Server + browser UI (long-running)
โโโ acp # Agent Client Protocol (stdio JSON-RPC)
โโโ completion # Print shell completion script
โโโ upgrade [target] # Upgrade opencode binary
โโโ uninstall # Uninstall opencode
โโโ providers (alias: auth) # AI providers / credentials
โ โโโ list (ls)
โ โโโ login [url]
โ โโโ logout
โโโ agent # Manage agents
โ โโโ create
โ โโโ list
โโโ mcp # MCP servers
โ โโโ add
โ โโโ list (ls)
โ โโโ auth [name]
โ โ โโโ list (ls)
โ โโโ logout [name]
โ โโโ debug <name>
โโโ plugin <module> # Install plugin (alias: plug)
โโโ models [provider] # List models
โโโ session # Sessions
โ โโโ list
โ โโโ delete <sessionID>
โโโ export [sessionID] # Export session as JSON
โโโ import <file> # Import session JSON / share URL
โโโ stats # Token usage and cost
โโโ github # GitHub agent integration
โ โโโ install
โ โโโ run
โโโ pr <number> # Checkout GitHub PR + run opencode
โโโ db # SQLite database tools
โ โโโ [query]
โ โโโ path
โ โโโ migrate
โโโ debug # Diagnostics
โโโ config
โโโ info
โโโ paths
โโโ startup
โโโ agent <name>
โโโ skill
โโโ scrap
โโโ v2
โโโ snapshot { track, patch, diff }
โโโ lsp { diagnostics, symbols, document-symbols }
โโโ rg { tree, files, search }
โโโ file { read, status, list, search, tree }
โโโ wait
Configuration
Config Files and Resolution Order
Config is deep-merged in this order (later wins):
- Remote config from
<authdomain>/.well-known/opencode (org defaults, fetched at auth time)
- Global:
~/.config/opencode/opencode.json
OPENCODE_CONFIG env var path
- Project:
opencode.json (or opencode.jsonc) found by walking up from cwd to the nearest git root
.opencode/ subdirs in project: agents/, commands/, modes/, plugins/, skills/, tools/, themes/
OPENCODE_CONFIG_CONTENT env var (inline JSON, runtime override)
- Managed:
/Library/Application Support/opencode/ (macOS), /etc/opencode/ (Linux), %ProgramData%\opencode (Windows)
- macOS managed prefs (
ai.opencode.managed, MDM .mobileconfig - highest, not user-overridable)
JSON Schema URL: https://opencode.ai/config.json (draft 2020-12). Config files support JSONC (comments + trailing commas).
Show Resolved Config
opencode debug config
Minimal opencode.json
{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"small_model": "anthropic/claude-haiku-4-5",
"default_agent": "build",
"logLevel": "INFO",
"share": "manual",
"instructions": ["AGENTS.md", "docs/*.md"],
"permission": { "edit": "ask", "bash": "ask" }
}
Variable Substitution in Config
{
"model": "{env:OPENCODE_MODEL}",
"mcp": {
"github": {
"type": "remote",
"url": "https://api.githubcopilot.com/mcp",
"headers": { "Authorization": "Bearer {env:GITHUB_TOKEN}" }
}
},
"instructions": ["{file:./AGENTS.md}"]
}
{env:VAR} reads an env var. {file:path} inlines file contents (relative to the config dir, or absolute when starting with / or ~).
TUI Config
The TUI keeps its own file, schema https://opencode.ai/tui.json:
- Default:
~/.config/opencode/tui.json
- Override:
OPENCODE_TUI_CONFIG env var
Keys: theme, keybinds, scroll_speed, scroll_acceleration, diff_style, mouse, leader_timeout, attention. Legacy theme / keybinds / tui keys inside opencode.json are auto-migrated.
Environment Variables
export OPENCODE_CONFIG=/path/to/custom-opencode.json
export OPENCODE_CONFIG_DIR=/path/to/config-dir
export OPENCODE_CONFIG_CONTENT='{"model":"anthropic/claude-sonnet-4-5"}'
export OPENCODE_TUI_CONFIG=/path/to/tui.json
export OPENCODE_AUTO_SHARE=1
export OPENCODE_DISABLE_AUTOUPDATE=1
export OPENCODE_DISABLE_AUTOCOMPACT=1
export OPENCODE_DISABLE_PRUNE=1
export OPENCODE_DISABLE_TERMINAL_TITLE=1
export OPENCODE_DISABLE_DEFAULT_PLUGINS=1
export OPENCODE_DISABLE_LSP_DOWNLOAD=1
export OPENCODE_DISABLE_MODELS_FETCH=1
export OPENCODE_DISABLE_MOUSE=1
export OPENCODE_ENABLE_EXPERIMENTAL_MODELS=1
export OPENCODE_DISABLE_CLAUDE_CODE=1
export OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1
export OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1
export OPENCODE_PERMISSION='{"edit":"ask","bash":{"npm install":"allow","*":"ask"}}'
export OPENCODE_SERVER_PASSWORD='supersecret'
export OPENCODE_SERVER_USERNAME='opencode'
export OPENCODE_GIT_BASH_PATH='C:\Program Files\Git\bin\bash.exe'
export OPENCODE_CLIENT='cli'
export OPENCODE_MODELS_URL=https://models.dev
export OPENCODE_DEV_DEBUG=true
export OPENCODE_EXPERIMENTAL=1
export OPENCODE_EXPERIMENTAL_FILEWATCHER=1
export OPENCODE_EXPERIMENTAL_LSP_TOOL=1
export OPENCODE_EXPERIMENTAL_LSP_TY=1
export OPENCODE_EXPERIMENTAL_PLAN_MODE=1
export OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS=120000
export OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=8192
export ANTHROPIC_API_KEY=...
export OPENAI_API_KEY=...
export GEMINI_API_KEY=...
export GROQ_API_KEY=...
export OPENROUTER_API_KEY=...
export XAI_API_KEY=...
export GITHUB_TOKEN=...
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_REGION=...
export AZURE_OPENAI_ENDPOINT=...
export AZURE_OPENAI_API_KEY=...
export VERTEXAI_PROJECT=...
export VERTEXAI_LOCATION=...
export HTTPS_PROXY=http://proxy.corp:8080
export HTTP_PROXY=http://proxy.corp:8080
export NO_PROXY=localhost,127.0.0.1,.corp
export NODE_EXTRA_CA_CERTS=/etc/ssl/corp-ca.pem
There is no OPENCODE_LOG_LEVEL, OPENCODE_THEME, OPENCODE_DISABLE_SHARE, or OPENCODE_MODEL env var. Use --log-level (CLI) or logLevel (config) for logging, the theme key in tui.json for theming, and "share": "disabled" in opencode.json to disable sharing.
Running opencode (TUI / one-shot)
The bare opencode command launches the TUI and blocks the terminal. Pass a project path positional to start in a different directory.
Start TUI
opencode
opencode /path/to/project
opencode -m anthropic/claude-sonnet-4-5 --agent build
opencode -c
opencode --continue
opencode -s ses_abc123
opencode -c --fork
opencode --prompt "Refactor authentication module"
opencode --pure
opencode --port 4096 --hostname 127.0.0.1
opencode --mdns --mdns-domain opencode.local
opencode --cors http://localhost:3000 --cors http://localhost:5173
opencode --print-logs --log-level DEBUG
Run (non-interactive prompts)
Use opencode run to send a single prompt and exit. This is the right entry point for scripts and CI.
Basic Run
opencode run "Write a Python script that lists S3 buckets"
opencode run "Add error handling" "to src/api/server.ts"
opencode run "Audit this file" -m anthropic/claude-opus-4-5
opencode run "Plan a refactor" --agent plan
opencode run "Solve this puzzle" --variant high
opencode run "Plan it" --thinking
opencode run "Triage build errors" --share
opencode run "Land issue #123" --title "Issue 123 fix"
opencode run --command /test "src/api/server.test.ts"
Continue / Resume Sessions
opencode run -c "Now write tests for that"
opencode run -s ses_abc123 "Now write tests"
opencode run -c --fork "Try a different approach"
Attach Files to a Run
opencode run "Review this code" -f src/server.ts -f src/server.test.ts
opencode run "Describe this screenshot" -f screenshot.png
Output Format
opencode run "ping"
opencode run "ping" --format json
opencode run "ping" --format json | jq -c 'select(.type=="message")'
opencode run "ping" --format json
opencode export | jq .
Run Against a Remote Server
opencode run "Help" --attach http://localhost:4096
opencode run "Help" --attach http://server:4096 -u opencode -p hunter2
opencode run "Refactor" --attach http://server:4096 --dir /srv/project
Risk-Sensitive Flags
opencode run "Apply the patch" --dangerously-skip-permissions
opencode run -i "Start a chat about this codebase"
opencode run --demo /tutorial
Attach (remote TUI)
Connect a local TUI to a running opencode serve / opencode web instance.
opencode attach http://localhost:4096
opencode attach http://server:4096 -u opencode -p hunter2
opencode attach http://server:4096 --dir /srv/project
opencode attach http://server:4096 -c
opencode attach http://server:4096 -s ses_abc123
opencode attach http://server:4096 -c --fork
Serve (headless server)
Run a headless HTTP server. Other clients (TUI, web UI, IDE plugins) can connect.
opencode serve
opencode serve --hostname 0.0.0.0 --port 4096
opencode serve --mdns --mdns-domain dev.opencode.local
opencode serve --cors http://localhost:3000 --cors http://localhost:5173
OPENCODE_SERVER_PASSWORD='hunter2' opencode serve --hostname 0.0.0.0 --port 4096
The OpenAPI 3.1 schema is exposed at http://<host>:<port>/doc. SSE event stream lives at /event (first event is server.connected).
Web (server + browser UI)
opencode web
opencode web --port 4097 --hostname 127.0.0.1
opencode web --mdns --cors http://localhost:3000
ACP (Agent Client Protocol)
opencode acp exposes opencode as an ACP subprocess speaking JSON-RPC over stdin/stdout. Used by Zed, JetBrains, Avante.nvim, CodeCompanion.nvim, etc.
opencode acp
opencode acp --port 4096 --hostname 127.0.0.1
opencode acp --cwd /path/to/project
opencode acp --mdns --mdns-domain opencode.local --cors http://localhost:3000
ACP supports tools, MCP servers, AGENTS.md, formatters, and the permission system. /undo and /redo slash commands are not supported in ACP mode.
Agents
Agents combine a system prompt, model, mode, and permissions. They live as Markdown files with YAML frontmatter under ~/.config/opencode/agents/ (global) or .opencode/agents/ (project). Filename = agent name.
Manage Agents
opencode agent list
opencode debug agent build
opencode debug agent plan
opencode debug agent <my-agent>
opencode debug agent build --tool read --params '{"file":"package.json"}'
opencode debug agent build --tool grep --params '{"pattern":"TODO","include":"*.ts"}'
opencode agent create \
--path ~/.config/opencode/agents \
--description "Code reviewer that focuses on security" \
--mode subagent \
--permissions read,grep,glob,webfetch \
-m anthropic/claude-sonnet-4-5
--permissions (alias --tools) is comma-separated; valid tool ids: bash, read, edit, glob, grep, webfetch, task, todowrite, websearch, lsp, skill. Default is all.
Agent File Format
---
description: "Security-focused code reviewer"
mode: subagent # primary | subagent | all
model: anthropic/claude-sonnet-4-5
temperature: 0.1
top_p: 0.9
steps: 10 # max iterations
color: "#ff6b6b" # hex or theme color name
hidden: true # subagent only - hide from @ autocomplete
disable: false
permission:
edit: deny
bash: ask
webfetch: allow
prompt: |
You are a senior code reviewer focused on security.
Audit changes for SQL injection, XSS, and auth bypass.
---
Optional extra prompt body in Markdown after the frontmatter.
Built-ins:
build - primary, full toolset, default agent
plan - primary, read-only; asks for edits and bash
general - subagent, full toolset
explore - subagent, read-only
scout - subagent, external research
Unknown frontmatter keys pass through as model options (e.g. reasoningEffort: high, textVerbosity: low).
MCP Servers (Model Context Protocol)
opencode reads MCP server config from the mcp key in opencode.json. Tools from a server are namespaced as <server-name>_<tool>.
Manage MCP Servers
opencode mcp list
opencode mcp ls
opencode mcp add
opencode mcp auth my-mcp
opencode mcp auth list
opencode mcp auth ls
opencode mcp logout my-mcp
opencode mcp debug my-mcp
OAuth tokens are cached at ~/.local/share/opencode/mcp-auth.json. opencode auto-detects OAuth on a 401 response (RFC 7591 Dynamic Client Registration). Set "oauth": false on the server to disable.
MCP Config (in opencode.json)
{
"mcp": {
"filesystem": {
"type": "local",
"command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/srv"],
"enabled": true,
"environment": { "LOG_LEVEL": "info" },
"timeout": 5000
},
"github": {
"type": "remote",
"url": "https://api.githubcopilot.com/mcp",
"enabled": true,
"headers": { "Authorization": "Bearer {env:GITHUB_TOKEN}" },
"timeout": 5000
},
"linear": {
"type": "remote",
"url": "https://mcp.linear.app/sse",
"enabled": true,
"oauth": {
"clientId": "{env:LINEAR_CLIENT_ID}",
"clientSecret": "{env:LINEAR_CLIENT_SECRET}",
"scope": "read write",
"callbackPort": 19876,
"redirectUri": "http://127.0.0.1:19876/mcp/oauth/callback"
}
}
},
"tools": { "github_*": true, "filesystem_delete*": false }
}
Models
opencode models
opencode models anthropic
opencode models openai
opencode models --verbose
opencode models --refresh
Custom registry: set OPENCODE_MODELS_URL to a models.dev-compatible URL.
Sessions
Sessions are persisted in opencode's SQLite database at ~/.local/share/opencode/opencode.db.
List / Delete Sessions
opencode session list
opencode session list -n 20 --format json
opencode session list --format json | jq '.[].id'
opencode session delete ses_abc123
Export / Import
opencode export
opencode export ses_abc123 > session.json
opencode export ses_abc123 --sanitize > session-redacted.json
opencode import ./session.json
opencode import https://opncd.ai/s/abcd1234
Stats
opencode stats
opencode stats --days 30
opencode stats --tools 10
opencode stats --models 5
opencode stats --project ""
opencode stats --project /path/to/project
Plugins
opencode plugins are JS/TS modules implementing hooks (tool.execute.before, session.created, permission.asked, etc.) and optionally registering custom tools. Local plugins live under .opencode/plugins/ (project) or ~/.config/opencode/plugins/ (global). npm plugins are listed in the plugin array in opencode.json and auto-installed via Bun (cached at ~/.cache/opencode/node_modules/).
opencode plugin opencode-wakatime
opencode plug opencode-wakatime
opencode plugin "@example/opencode-notifier"
opencode plugin opencode-wakatime --global
opencode plugin opencode-wakatime -g
opencode plugin opencode-wakatime --force
opencode plugin opencode-wakatime -f
Plugin Skeleton
import type { Plugin } from "@opencode-ai/plugin"
export const MyPlugin: Plugin = async ({ project, directory, worktree, client, $ }) => ({
"tool.execute.before": async ({ tool, args }) => {
if (tool === "bash") console.log("[bash]", args.command)
},
"session.created": async ({ session }) => {
await $`echo ${session.id} >> ~/sessions.log`
},
})
If a plugin tool name matches a built-in, the plugin tool wins. For local plugins with deps, drop a package.json next to them - opencode runs bun install on startup.
GitHub Agent
The opencode github subcommand wires up the opencode GitHub App (github.com/apps/opencode-agent) so PRs and issues can be driven by /oc / /opencode comments.
opencode github install
opencode github run --token github_pat_xxx
opencode github run --event ./mock-issue_comment.json --token github_pat_xxx
Workflow Skeleton (manual setup)
name: opencode
on:
issue_comment: { types: [created] }
pull_request_review_comment: { types: [created] }
jobs:
opencode:
if: contains(github.event.comment.body, '/oc') || contains(github.event.comment.body, '/opencode')
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
persist-credentials: false
- uses: anomalyco/opencode/github@latest
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
with:
model: anthropic/claude-sonnet-4-5
Comment triggers in issues / PRs:
/oc explain this issue - reads thread, replies inline
/oc fix this - opens a branch + PR
/oc add error handling here (on a PR review line) - auto-detects file, lines, and diff context
Pull Request Workflow Helper
opencode pr 123
opencode pr 4567
Database (SQLite)
opencode persists sessions and snapshots in SQLite. The bare opencode db opens an interactive sqlite3 shell - pass a query to keep it non-interactive.
opencode db path
opencode db "SELECT id, title, updated FROM session ORDER BY updated DESC LIMIT 10"
opencode db --format json "SELECT id, title FROM session LIMIT 5"
opencode db migrate
opencode db
Upgrade / Uninstall
opencode upgrade
opencode upgrade 1.15.10
opencode upgrade v1.15.10
opencode upgrade --method brew
opencode upgrade --method npm
opencode upgrade --method bun
opencode upgrade --method curl
opencode upgrade --method choco
opencode upgrade --method scoop
opencode uninstall --dry-run
opencode uninstall --keep-config
opencode uninstall --keep-data
opencode uninstall -c -d
opencode uninstall --force
Shell Completion
opencode completion
opencode completion >> ~/.zshrc
opencode completion -s bash > ~/.opencode-completion.bash
echo 'source ~/.opencode-completion.bash' >> ~/.bashrc
opencode completion -s fish > ~/.config/fish/completions/opencode.fish
Debug Subcommands
opencode debug exposes diagnostics that mirror the LSP, ripgrep, file-system, and snapshot tools the agent uses internally. Most subcommands are one-shot and safe to script; opencode debug wait blocks indefinitely (it exists to keep the runner alive while attaching a debugger).
Resolved Configuration / Environment
opencode debug config
opencode debug info
opencode debug paths
opencode debug startup
Agents and Skills
opencode debug agent build
opencode debug agent <my-agent>
opencode debug agent build --tool read --params '{"file":"package.json"}'
opencode debug skill
opencode debug scrap
opencode debug v2
LSP
opencode debug lsp diagnostics src/server.ts
opencode debug lsp symbols "createServer"
opencode debug lsp document-symbols file:///abs/path/src/server.ts
Ripgrep
opencode debug rg tree --limit 200
opencode debug rg files --query server --glob "*.ts" --limit 100
opencode debug rg search "TODO"
opencode debug rg search "createServer" --glob "src/**/*.ts" --glob "!**/*.test.ts" --limit 50
Filesystem
opencode debug file read package.json
opencode debug file status
opencode debug file list src/
opencode debug file search Server
opencode debug file tree
opencode debug file tree src/
Snapshots
opencode debug snapshot track
opencode debug snapshot patch <hash>
opencode debug snapshot diff <hash>
Wait
opencode debug wait
Sharing
Sharing publishes a session to a CDN-served URL like https://opncd.ai/s/<id>.
opencode run "Plan a refactor" --share
In the TUI, /share and /unshare slash commands toggle sharing for the current session. There is no env var to disable sharing globally - use "share": "disabled" in config (or push it via managed config in enterprise).
Global Flags
| Flag | Description |
|---|
--help / -h | Show help for command (use this FIRST) |
--version / -v | Show opencode version |
--print-logs | Print server logs to terminal |
--log-level LEVEL | DEBUG / INFO / WARN / ERROR |
--pure | Run without external plugins |
--port N | Server port (default 0 = random; serve/web use 4096) |
--hostname HOST | Server hostname (default 127.0.0.1) |
--mdns | Enable mDNS discovery |
--mdns-domain DOMAIN | mDNS domain (default opencode.local) |
--cors ORIGIN | Extra CORS origin (repeatable) |
-m / --model SPEC | provider/model model spec |
-c / --continue | Resume the most recent session |
-s / --session ID | Resume a specific session |
--fork | Fork the resumed session (requires -c or -s) |
--prompt TEXT | Initial prompt for the TUI |
--agent NAME | Agent to use |
opencode run-only flags worth highlighting: --format json, -f/--file, --share, --variant, --thinking, --attach, -p/--password, -u/--username, --dir, --title, --replay, --replay-limit, -i/--interactive, --dangerously-skip-permissions, --demo, --command.
Output Formatting
--format json (run / session list / db)
opencode run "ping" --format json
opencode run "ping" --format json | jq -c 'select(.type=="message")'
opencode run "ping" --format json | jq -r 'select(.type=="message" and .role=="assistant") | .content'
opencode session list --format json | jq -r '.[] | "\(.id)\t\(.title)"'
opencode session list --format json | jq '[.[] | select(.directory|startswith(env.PWD))]'
The full per-line event schema for run --format json is not documented in the official docs. Inspect a sample run for the exact shape on your installed version, or stream the related SSE feed at GET /event on a running opencode serve.
Database queries (TSV / JSON)
opencode db "SELECT id, title FROM session LIMIT 5"
opencode db --format json "SELECT id, title FROM session LIMIT 5" | jq .
opencode db --format json \
"SELECT s.id, s.title, p.worktree FROM session s JOIN project p ON s.project_id = p.id ORDER BY s.updated DESC LIMIT 10"
Common scripting recipes
SES=$(opencode session list -n 1 --format json | jq -r '.[0].id')
opencode run -s "$SES" --format json "Now write tests" | jq -c '.'
opencode auth list
opencode db --format json "SELECT content FROM message WHERE role='assistant' ORDER BY created DESC LIMIT 5" \
| jq -r '.[].content'