opencode — Quick reference

Open-source AI coding agent that lives in your terminal · bring your own model (75+ providers) · MIT-licensed · runs as a TUI, desktop app, or IDE extension

At a glance

opencode is a free, open-source (MIT) agent you run from the command line in your own project folder. The tool costs nothing — you only pay your model provider for the tokens a session uses. Two modes switch with one key: plan reads and proposes, build edits files. It's privacy-first: no code or context is stored server-side, so your project stays on your machine and only your provider's API sees data. Docs: opencode.ai/docs.

Setup & first edit

1 · Install
Pick whatever you have
curl -fsSL https://opencode.ai/install | bash
npm install -g opencode-ai
brew install anomalyco/tap/opencode
scoop install opencode (Windows)
sudo pacman -S opencode (Arch)
2 · Connect a model
Your key or a subscription
Run opencode auth login (or /connect inside the TUI) to add a provider key — or log in with an existing GitHub Copilot / ChatGPT Plus/Pro subscription and reuse it. No separate bill, no markup.
3 · First AI edit
One sentence, real fix
From inside your project folder:
opencode "Read anova_analysis.R, find the bug on line 34, and fix it."
It reads the file, explains the error in plain language, and proposes or applies the fix.

Run opencode alone to open the full-screen terminal UI (TUI), not a one-shot reply. Type your request in any language you like. Run /init once per project to set opencode up for that repo.

Key commands & shortcuts

In the TUI

Key / commandWhat it does
TabToggle plan ↔ build mode
@Fuzzy-search files to add to context
/connectConfigure an LLM provider key
/initInitialize opencode for this project
/undoRevert the changes the agent made
/redoRestore previously undone changes
/shareCreate a shareable link to this session

From the shell

CommandWhat it does
opencodeStart the interactive TUI
opencode run "…"Non-interactive: pass a prompt directly
opencode auth loginAdd provider credentials
opencode modelsList models from your providers
opencode session listList your sessions
opencode statsToken usage & cost stats
opencode upgradeUpdate to the latest version

Useful flags: -m provider/model pick the model · -c / --continue resume the last session · -s <id> continue a specific session · -f <file> attach a file · --share share the session.

Prompting patterns

Find & fix a bug
"My R script anova_analysis.R throws an error on line 34. Read the file, find the bug, and fix it." — opencode greps and reads files to locate the right code, then proposes the edit.
Multi-step data job
"Read all CSV files in ./data/, merge them, remove duplicates by sample_id, fill missing numeric values with column medians, and save as cleaned_data.csv" — hand it the whole job and let it write and run the script.
Plan first (read-only)
"Explain how authentication flows through this codebase and outline the safest way to add password reset — don't change any files yet." Stay in plan mode, then press Tab to build.
Split across parallel agents
Session A: "write unit tests for the parsing module." Session B: "update the README and fix the broken links." Give each a narrow, independent job so they don't collide.

Context & modes

The two agent modes (toggle with Tab)

ModeWhat it does
planRead-only analysis — explores and explains without modifying files; bash execution is permission-gated.
buildMakes the actual code changes. The status bar (bottom of the TUI) always shows which mode you're in.

Adding context & scaling out

• Press @ to fuzzy-search and attach project files; or opencode -f <file> from the shell.

LSP loads automatically — every session gets language-server-grade code understanding and navigation.

Multi-session parallelism: run several agents on the same project at once, each on a different subtask.

• Three surfaces, same agent: terminal TUI, desktop app (macOS / Windows / Linux), and IDE extension.

Pricing & limits

The opencode tool is free and MIT-licensed — there's no markup on top of your model. With BYOK (bring your own key) token costs land directly on your provider bill (e.g. Anthropic API rates), so a long refactor can run a few dollars — monitor usage or cap spending. Reusing a Copilot or ChatGPT subscription means no new bill at all.

PathWhat you pay
Core toolFree / open source — TUI, desktop app, and IDE extension all included.
BYOKPay your provider directly for tokens. 75+ providers (Anthropic, OpenAI, Google, Mistral) or a local Ollama model — switch without re-installing.
OpenCode ZenHosted models, pay-as-you-go per 1M tokens (no flat monthly plan). Free five-model tier: Big Pickle, DeepSeek V4 Flash Free, MiMo-V2.5 Free, North Mini Code Free, Nemotron 3 Ultra Free.

Zen paid models & guardrails: range from DeepSeek V4 Flash $0.14 in / $0.28 out per 1M tokens up to Claude Fable 5 $10.00 in / $50.00 out (Claude Opus models ~$5.00 in / $25.00 out). Auto-reload tops up a default $20 when your balance drops below $5; set per-workspace / per-member monthly limits. Card processing adds 4.4% + $0.30 per transaction; team plans are free during beta.

Gotchas & tips

Always run from inside the project folder — opencode loads that directory as its context.
Plan before you build. On unfamiliar code, start in plan mode, refine the approach in plain language, then Tab to build — planning first usually saves money by avoiding wrong edits you'd have to undo.
BYOK has no spend cap. A long session bills straight to your provider — watch opencode stats, or use Zen's auto-reload + per-member limits for predictable spend.
Parallel agents cost in parallel — two running sessions ≈ twice the tokens, so only fan out genuinely independent subtasks.
Stuck? /share generates a link that reproduces the exact session for a teammate to inspect.
You stay in control — opencode proposes edits; you decide whether they're applied. Use /undo to revert.