Installer OpenCode CLI : setup, auth, TUI Plan/Build, git diff
Installer OpenCode CLI, auth, premier diff revu dans le TUI.
The first hour with the OpenCode CLI usually breaks on a missing opencode binary, skipping /connect or opencode auth login for your LLM provider, or letting Build mode edit a dozen files without a git diff review. Install the binary, authenticate, launch the TUI in your repo, ask one read-only question, then use Plan/Build for one reversible diff.
The query is how to install and use the OpenCode CLI terminal agent. This page follows opencode.ai/docs and opencode.ai/docs/cli for install, auth, the TUI, and opencode run (labels and shortcuts can change—trust the live TUI). OpenCode needs legitimate API keys or billing for your chosen provider or OpenCode Zen—no shared keys. Desktop and IDE builds are separate entry points; this guide is CLI-only. To walk a diff on a short call, open a room on wbmeet; see create and join a room.
What the OpenCode CLI does
OpenCode (opencode.ai) is an open source AI coding agent. Running opencode with no subcommand starts the terminal TUI, which can read your repo, edit files, and run shell commands after you approve permission prompts. Use Tab to switch between Plan (outline without editing) and Build (apply changes); /undo and /redo revert or replay session edits. For scripting, use opencode run "…". Credentials default to ~/.local/share/opencode/auth.json; project .env files can also load keys per CLI docs.
Install the opencode binary
- 1
Official install script (macOS / Linux)
Run the documented installer, e.g.
curl -fsSL https://opencode.ai/install | bash. Verify withopencode --version. - 2
Package managers
brew install anomalyco/tap/opencode, ornpm install -g opencode-ai(also pnpm/bun/yarn per docs). On Windows, see Chocolatey, Scoop, or npm in opencode.ai/docs. - 3
Avoid duplicate binaries
Docs warn some install paths can conflict with OpenCode 2. Run
which opencodeand keep one install method if commands behave oddly.
Sign in and configure models (auth)
- 1
/connect in the TUI
Launch
opencode, type/connect. Pick OpenCode Zen (sign in atopencode.ai/auth, add billing, paste your API key) or another provider from the list (see opencode.ai/docs/providers). - 2
Or opencode auth login
From the shell:
opencode auth login, choose a provider, store the key. Checkopencode auth list; runopencode modelsforprovider/modelnames. - 3
Project .env (optional)
Startup loads environment variables and a project-root
.env. Never commit secrets. Do not use shared or leaked API keys.
Start the TUI in your repo
- 1
cd to the Git root
cd /path/to/your-repoand rungit statusso you know what is already dirty. - 2
Run opencode
opencodeopens the TUI. Optionally run/initonce to analyze the project and writeAGENTS.md(official Intro flow). - 3
Read-only first message
Ask: “In three sentences, explain the main modules described in @README.md.” Or reference one file with
@path/to/file.ts(exact @ syntax follows the TUI).
First reviewable diff (Plan → Build)
- 1
Tab into Plan
Press Tab for Plan mode (indicator in the lower corner per opencode.ai/docs Intro). Prompt: “Add input validation in one helper only—list 3 steps, do not edit files yet.”
- 2
Tab back to Build, one step
When the plan looks sane, Tab to Build: “Execute step 1 only; one file; show changes and wait before step 2.” Read every permission prompt before approving; avoid
--autountil you trust the workflow (CLI flag in docs). - 3
git diff and /undo
In another terminal, run
git diff. Wrong result?/undoin the TUI orgit restoreon paths. Later tryopencode run -f src/foo.ts "Explain exports only, do not edit"for scripted read-only checks.
# First hour · OpenCode CLI · 2026-10-20
curl -fsSL https://opencode.ai/install | bash # or brew / npm per docs
opencode auth login # or /connect in TUI
cd ~/your-repo && git status
opencode
# /init (optional)
# Read-only: explain @README.md
# Tab → Plan → small task outline
# Tab → Build → step 1 only → approve edits carefully
git diff
# /undo if the session edit was wrongFeature comparison
| Entry | Good for | First-hour note |
|---|---|---|
TUI opencode | Interactive repo edits | Plan then Build |
opencode run | Scripts, quick Q&A | Read-only first, no --auto |
opencode auth login | Provider keys | Official keys only |
| Claude Code / Codex CLI | Other terminal agents | See on-site guides |
command not found
Reinstall; ensure npm global bin is on PATH.
No models / auth errors
opencode auth list; retry /connect; verify the key matches the provider.
Too many files touched
Plan with tighter scope; Build with “one step, one file”; /undo or git restore.
Suggested path: official install → auth or /connect →
opencodein repo → read-only question → Plan → Build one step →git diff. Trust opencode.ai/docs for your version.
- Vs Claude Code / Codex CLI
- OpenCode is its own open agent and TUI with providers from the models.dev directory. Compare our Claude Code and Codex CLI notes.
- Must I use OpenCode Zen?
- No. Zen is one official billing path; you can BYOK per provider docs.
- Scope
- OpenCode CLI first hour only—not a wbmeet meeting guide.
Questions worth checking
Is Plan/Build always on Tab?
Intro docs use Tab to switch Plan/Build; if your build differs, follow the mode indicator and current opencode.ai/docs.
Will opencode run edit files?
It depends on the prompt and permissions. Hour one: read-only prompts without --auto; prefer the TUI for edits you approve step by step.
Does private repo code go to the provider?
Handling follows your provider and OpenCode configuration. Read official privacy docs and obey company policy on sensitive repos.
Must the first task add tests?
No. Any small revertible change works; the gate is Plan scope, Build one step, and git diff review.