OpenCode: Quick Reference, Migration & Metrics
API Key Setup (dsec)
API keys are stored in the dsec encrypted secrets system under d000 dev/app alongside other application secrets.
Step 1: Generate API Keys
Visit each dashboard and generate an API key:
| Provider | Dashboard URL | Key Prefix |
|---|---|---|
Anthropic (Claude) |
|
|
OpenAI (GPT) |
|
|
DeepSeek |
|
|
Google (Gemini) |
|
Step 2: Add to dsec
dsec edit d000 dev/app
Paste this section at the bottom of the file, fill in the keys:
# ============================================================================
# === AI / LLM Provider API Keys ===
# ============================================================================
# --- Anthropic (Claude) ---
# Dashboard: https://console.anthropic.com/settings/keys
ANTHROPIC_API_KEY=
# --- OpenAI (GPT) ---
# Dashboard: https://platform.openai.com/api-keys
OPENAI_API_KEY=
# --- DeepSeek ---
# Dashboard: https://platform.deepseek.com/api_keys
DEEPSEEK_API_KEY=
# --- Google (Gemini) ---
# Dashboard: https://aistudio.google.com/apikey
GOOGLE_GENERATIVE_AI_API_KEY=
# --- OpenCode Feature Flags ---
OPENCODE_EXPERIMENTAL_LSP_TOOL=true
Save and exit. dsec auto-encrypts the file.
Step 3: Load and Launch
# Load secrets into current shell
ds d000 dev/app
# Verify keys are loaded (shows var names, not values)
env | grep -E "ANTHROPIC|OPENAI|DEEPSEEK|GOOGLE_GENERATIVE" | awk -F= '{print $1, "=", substr($2,1,8) "..."}'
# Launch OpenCode
opencode
Step 4: Authenticate GitHub Copilot
GitHub Copilot uses device login, not an API key. Inside OpenCode TUI:
/connect
# Select GitHub Copilot
# Browser opens → enter device code → authorize
# Token cached for future sessions
Step 5: Verify All Providers
Inside OpenCode TUI:
# List available models across all providers
/models
# Switch model to test each provider
Ctrl+X → M # Open model picker
# Select anthropic/claude-sonnet-4-6 → send a test message
# Select openai/gpt-4.1 → send a test message
# Select deepseek/deepseek-chat → send a test message
# Select google/gemini-2.5-flash → send a test message
Provider Status Checklist
| Provider | Auth Method | Status |
|---|---|---|
Anthropic |
|
[ ] Key generated, loaded via dsec |
OpenAI |
|
[ ] Key generated, loaded via dsec |
DeepSeek |
|
[ ] Key generated, loaded via dsec |
Google Gemini |
|
[ ] Key generated, loaded via dsec |
GitHub Copilot |
|
[ ] Authenticated via browser |
Ollama (local) |
N/A (not installed) |
[ ] Skipped — uncomment in opencode.jsonc when installed |
Daily Workflow
# Start of session: load secrets + launch
ds d000 dev/app && opencode
# Or alias in ~/.zshrc:
# alias oc='ds d000 dev/app && opencode'
Troubleshooting
| Problem | Fix |
|---|---|
"No API key" error |
Run |
Provider not showing in |
Check |
DeepSeek connection refused |
Verify baseURL in opencode.jsonc is |
Copilot models not available |
Re-run |
Wrong model on startup |
Check |
Quick Reference
Installation
# Install via curl
curl -fsSL https://opencode.ai/install | bash
# Or via package manager (Arch)
paru -S opencode-bin
# Or via npm
npm install -g opencode
# Verify
opencode --version
Daily Usage
# Start OpenCode in current directory
opencode
# Start with specific model
opencode --model ollama/qwen-coder-14b
# Start in Plan mode (read-only)
opencode --mode plan
# Resume previous session
opencode --resume
# Non-interactive query
opencode -p "explain this function"
# Generate AGENTS.md for new project
opencode /init
In-Session Commands
# Skills
/deploy # Push and rebuild docs
/deploy "docs: New runbook" # With commit message
/worklog # Create today's worklog
/session # Create session log
# Built-in commands
/undo # Undo last file change
/redo # Redo last undo
/share # Share session link
/models # List available models
/theme # Switch theme
/help # Show help
# Agent dispatch
@general "complex multi-step task"
@explore "find all AsciiDoc partials"
@adoc-linter "check this component"
Keybinding Cheatsheet
| Key | Action |
|---|---|
|
Toggle Build/Plan mode |
|
Model picker |
|
Agent picker |
|
New session |
|
Share session |
|
Session history |
|
Quit |
|
Undo |
|
Redo |
Provider Quick Switch
# In model picker (Ctrl+X → M), select:
ollama/qwen-coder-14b # Free, local, fast
deepseek/deepseek-chat # Cheap cloud coder
copilot/gpt-4.1 # Existing subscription
openai/gpt-4.1 # Second opinion
google/gemini-2.5-pro # Large context
anthropic/claude-sonnet # Best reasoning
MCP Server Management
opencode mcp list # List configured servers
opencode mcp auth <server> # Authenticate
opencode mcp debug <server> # Debug connection
opencode mcp logout <server> # Logout
Environment Variables
# Provider API keys
export ANTHROPIC_API_KEY="..."
export OPENAI_API_KEY="..."
export DEEPSEEK_API_KEY="..."
export GOOGLE_GENERATIVE_AI_API_KEY="..."
# OpenCode config
export OPENCODE_CONFIG="/path/to/custom/config.json"
export OPENCODE_CONFIG_CONTENT='{"provider":{"ollama":{...}}}'
File Locations
| File | Purpose |
|---|---|
|
Global config (providers, agents, permissions) |
|
TUI config (theme, keybindings) |
|
Project config (merges with global) |
|
Project instructions |
|
Project agents, commands, modes, plugins, skills, themes |
|
Global agents |
|
Global skills |
|
Global custom themes |
|
Global plugins |
CLI Reference
Core Commands
| Command | Purpose |
|---|---|
|
Start TUI (default — interactive terminal UI) |
|
Non-interactive mode — send a prompt, get a response, exit |
|
Start headless HTTP server (no TUI, API only) |
|
Start server + web interface |
|
Attach TUI to a running OpenCode server (remote control) |
Agent Management
| Command | Purpose |
|---|---|
|
Interactive wizard to create a new agent markdown file |
|
List all configured agents |
Authentication
| Command | Purpose |
|---|---|
|
Authenticate with a provider (stores in |
|
List stored credentials |
|
Remove stored credentials |
MCP Server Management
| Command | Purpose |
|---|---|
|
Add a new MCP server interactively |
|
List all configured MCP servers and auth status |
|
Authenticate with an MCP server (OAuth flow) |
|
Remove stored MCP credentials |
|
Debug MCP connection issues |
Session Management
| Command | Purpose |
|---|---|
|
List all sessions |
|
Export session as JSON |
|
Import session from JSON file or URL |
|
Show token usage and cost statistics |
Model Management
| Command | Purpose |
|---|---|
|
List all available models across configured providers |
|
List models for a specific provider |
GitHub Integration
| Command | Purpose |
|---|---|
|
Install GitHub agent for CI/CD |
|
Run GitHub agent |
Maintenance
| Command | Purpose |
|---|---|
|
Update OpenCode to latest (or specified) version |
|
Remove OpenCode completely |
|
Start Agent Client Protocol server (Zed, JetBrains, Neovim integration) |
Global Flags
| Flag | Purpose |
|---|---|
|
Show help |
|
Show version |
|
Print logs to stdout |
|
Set log level (debug, info, warn, error) |
|
Override model for this session |
|
Override config file path |
|
Override permission mode (allow, ask, deny) |
Non-Interactive Mode Examples
# Quick query
opencode run "explain the main function in src/index.ts"
# With specific model
opencode run -m ollama/qwen-coder-14b "fix the type error in utils.py"
# Pipe input
echo "review this code" | opencode run
# With permissive mode (auto-approve everything)
opencode run --permission allow "add error handling to all API endpoints"
Environment Variables (47)
OpenCode supports 47 environment variables for configuration, debugging, and feature flags.
Configuration Overrides
| Variable | Purpose |
|---|---|
|
Path to custom config file (overrides global) |
|
Path to custom TUI config file |
|
Override config directory (default: |
|
Inline JSON config (highest priority override) |
|
Override all permissions ( |
|
Custom URL for model registry |
|
Client identifier string |
Server & Auth
| Variable | Purpose |
|---|---|
|
Server authentication password |
|
Server authentication username |
Feature Toggles
| Variable | Purpose |
|---|---|
|
Enable web search via Exa AI (set to any truthy value) |
|
Disable automatic updates |
|
Disable session pruning |
|
Disable terminal title changes |
|
Disable built-in plugins |
|
Disable automatic LSP server downloads |
|
Disable automatic context compaction |
|
Disable fetching model registry |
|
Disable file modification time checking |
Claude Code Compatibility
| Variable | Purpose |
|---|---|
|
Disable reading from |
|
Disable reading |
|
Disable loading |
Experimental Features
| Variable | Purpose |
|---|---|
|
Enable ALL experimental features at once |
|
Enable LSP tool (goToDefinition, findReferences, etc.) |
|
Override default bash timeout (default: 120000ms) |
|
Override maximum output tokens |
|
Enable experimental file watcher |
|
Disable file watcher |
|
Disable copy-on-select behavior |
|
Enable icon discovery |
|
Enable oxfmt formatter |
|
Enable Exa web search (alternative to OPENCODE_ENABLE_EXA) |
|
Enable ty LSP server |
|
Enable experimental markdown rendering |
|
Enable experimental plan mode features |
Recommended .zshenv Configuration
# Provider API keys (use gopass or age-encrypted source in practice)
export ANTHROPIC_API_KEY="..."
export OPENAI_API_KEY="..."
export DEEPSEEK_API_KEY="..."
export GOOGLE_GENERATIVE_AI_API_KEY="..."
# OpenCode feature flags
export OPENCODE_ENABLE_EXA=1 # Enable web search
export OPENCODE_EXPERIMENTAL_LSP_TOOL=true # Enable LSP tool
export OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS=300000 # 5min bash timeout
# Disable Claude Code compat if not needed
# export OPENCODE_DISABLE_CLAUDE_CODE=1
Session Sharing & History
Session Sharing
OpenCode can share sessions as viewable links. Three sharing modes:
{
"share": {
"provider": "opencode",
"mode": "manual"
}
}
| Mode | Behavior |
|---|---|
|
Share only when explicitly requested via |
|
Automatically share all sessions |
|
Disable sharing entirely |
Share Commands
| Action | Method |
|---|---|
Share current session |
|
Unshare session |
Via keybind ( |
Export as JSON |
|
Import from file/URL |
|
Session History
Sessions persist in a local SQLite database. Navigate sessions with:
| Keybind | Action |
|---|---|
|
Session list (browse all sessions) |
|
Session timeline view |
|
New session |
|
Fork current session (branch point) |
|
Rename current session |
Session Statistics
# View token usage and cost breakdown
opencode stats
Shows per-provider token usage, cost estimates, and session counts.
Snapshot System (Undo/Redo)
{
"snapshot": true
}
When enabled (default), OpenCode tracks every file modification:
-
edit,write,apply_patch,multieditall create snapshots -
/undoreverts the last file change -
/redore-applies the last undone change -
Keybinds:
<leader>u(undo),<leader>r(redo) -
Snapshots are session-scoped
Auto-Compaction
{
"compaction": {
"enabled": true
}
}
When context approaches token limits, OpenCode automatically summarizes earlier conversation to free space. Disable with:
export OPENCODE_DISABLE_AUTOCOMPACT=1
Or trigger manually with <leader>c keybind.
The experimental.session.compacting plugin hook allows customizing what context is preserved during compaction.
Migration from Claude Code
A systematic mapping of every Claude Code feature to its OpenCode equivalent. This is not about replacing — it is about translating a battle-tested configuration into a provider-agnostic system.
Configuration File Mapping
| Claude Code | OpenCode | Notes |
|---|---|---|
|
|
AGENTS.md is per-repo. Global rules go in |
|
|
Provider config, permissions, MCP, agents. |
|
|
Keybindings + theme + scroll + diff config. |
|
|
Project instructions in AGENTS.md. Agents/commands/modes in |
|
|
Project config merges with global. |
|
|
Same concept, slightly different frontmatter schema. |
|
|
Cross-compatible! OpenCode reads |
|
|
Rules become modes or instruction files. No auto-load by file type. |
|
AGENTS.md instructions |
No dedicated output style system. Embed tone directives in AGENTS.md. |
|
|
Bash hooks become JS/TS plugins. Richer event model. |
Feature Parity Checklist
| Feature | Claude Code | OpenCode | Migration Action |
|---|---|---|---|
Global instructions |
CLAUDE.md (873 lines) |
AGENTS.md + instructions |
Split into AGENTS.md (project) + global instruction files |
Permissions (107 allow) |
settings.json |
opencode.json |
Translate |
Permissions (10 deny) |
settings.json |
opencode.json |
Direct translation |
Auto-backup on edit |
PreToolUse hook |
Plugin or snapshot system |
Use built-in snapshots; optionally add backup plugin |
AsciiDoc attribute validation |
PostToolUse hook |
Plugin |
Port |
ShellCheck on save |
PostToolUse hook |
Plugin |
Port shell validation to TS plugin |
Sensitive file warning |
UserPromptSubmit hook |
Plugin |
Port staging check to TS plugin |
Session banner |
SessionStart hook |
Plugin ( |
Display environment info on startup |
/deploy skill |
.claude/skills/deploy/ |
.opencode/skills/deploy/ (or same path) |
Zero migration — OpenCode reads .claude/skills/ |
/worklog skill |
.claude/skills/worklog/ |
.opencode/skills/worklog/ (or same path) |
Zero migration — cross-compatible |
/session skill |
.claude/skills/session/ |
.opencode/skills/session/ (or same path) |
Zero migration — cross-compatible |
doc-auditor agent |
.claude/agents/doc-auditor.md |
.opencode/agents/doc-auditor.md |
Translate frontmatter (tools → permission, model format) |
build-fixer agent |
.claude/agents/build-fixer.md |
.opencode/agents/build-fixer.md |
Translate frontmatter |
AsciiDoc rule (auto-load) |
.claude/rules/asciidoc.md |
AGENTS.md or mode |
No auto-load equivalent. Embed in AGENTS.md or create review mode. |
Output style (professional) |
output-styles/professional.md |
AGENTS.md tone section |
Embed communication rules in AGENTS.md |
Undo/redo |
Not available |
Built-in ( |
New capability — no migration needed |
Theme |
Not available |
tui.json + custom themes |
New capability — Catppuccin Mocha |
Desktop app |
Not available |
Beta (Linux AppImage/DEB/RPM) |
New capability |
Migration Priority Order
-
Install OpenCode and verify basic operation
-
Configure providers — Ollama, DeepSeek, Copilot, OpenAI, Gemini, Claude
-
Set up AGENTS.md — Port core CLAUDE.md rules
-
Verify skills — Existing
.claude/skills/should work immediately -
Translate agents — Port agent frontmatter to OpenCode format
-
Build plugins — Port bash hooks to TS plugins
-
Configure permissions — Translate allow/deny lists
-
Set up theme — Catppuccin Mocha
-
Customize keybindings — Match muscle memory from Claude Code
-
Test workflows — Run daily operations cycle end-to-end
What You Lose
Be honest about what is not yet available:
-
Path-specific rule auto-loading — Claude Code auto-loads rules for
.adoc,.sh, etc. OpenCode requires modes or AGENTS.md. -
Hook simplicity — Bash hooks are simpler to write than TS plugins for quick one-off validations.
-
Anthropic-optimized tooling — Claude Code is specifically tuned for Claude models. OpenCode is provider-agnostic, which means less optimization per provider.
-
Proven maturity — Claude Code backed by Anthropic with focused development. OpenCode is MIT/community.
What You Gain
-
Provider freedom — Six providers, local + cloud, switch mid-session
-
Cost control — Ollama for free local, cheap providers for routine work
-
Undo/redo — Built-in file change rollback
-
Richer customization — Themes, full keybinding control, JS/TS plugins
-
Open source — Inspect, modify, contribute
-
Desktop app — Native GUI option
-
Client/server — Remote control capability
Success Metrics
Configuration Targets
| Capability | Target | Current |
|---|---|---|
Providers configured |
6 |
0 (planning phase) |
Custom agents |
6+ |
0 (planned: adoc-linter, build-fixer, worklog-creator, carryover-updater, commit-reviewer, cli-drill-master) |
Skills migrated |
3 (from Claude Code) |
0 (cross-compatible, untested) |
Plugins built |
4+ (asciidoc-validator, auto-backup, security-guard, shellcheck) |
0 (planned) |
Custom commands |
5+ |
0 (planned) |
Custom modes |
2+ (Review, Secure) |
0 (planned) |
Theme |
Catppuccin Domus |
0 (built-in Catppuccin available) |
AGENTS.md |
Fully ported from CLAUDE.md |
0 (not started) |
Cost Targets
| Metric | Before (Claude Code) | Target (OpenCode) |
|---|---|---|
Monthly API spend |
~$50-100 (Anthropic only) |
~$20-40 (mixed providers + local) |
Local model usage |
0% (not supported) |
60-70% of all interactions |
Cloud API usage |
100% |
30-40% (complex tasks only) |
Free tier usage |
0% |
Ollama local + Gemini free tier |
Workflow Acceleration Targets
| Metric | Claude Code Baseline | OpenCode Target |
|---|---|---|
Worklog creation |
<10 seconds (skill) |
<10 seconds (same skill, cross-compatible) |
Deploy cycle |
1 command (/deploy) |
1 command (same skill) |
Model switch |
N/A (single provider) |
<2 seconds (Tab or Ctrl+X → M) |
Undo mistake |
Manual git revert |
/undo (instant) |
Provider failover |
Not possible |
Switch provider mid-session if one is down |
Parity Checklist
Track progress toward feature parity with the Claude Code configuration:
| Feature | Parity | Notes |
|---|---|---|
Global instructions (CLAUDE.md → AGENTS.md) |
[ ] |
Port 873 lines to AGENTS.md + instruction files |
Permission allow list (107 entries) |
[ ] |
Translate Bash(command:*) format |
Permission deny list (10 entries) |
[ ] |
Direct translation |
Skills (3 implemented) |
[~] |
Cross-compatible, needs testing |
Agents (10 total) |
[ ] |
Translate frontmatter format |
Hooks → Plugins (7 hooks) |
[ ] |
Port bash to TS |
Rules → Modes/Instructions (5 rules) |
[ ] |
Embed in AGENTS.md or create modes |
Output style (professional) |
[ ] |
Embed in AGENTS.md |
Keybindings |
[ ] |
Map muscle memory to tui.json |
Theme (Catppuccin) |
[~] |
Built-in available, custom variant planned |