OpenCode CLI の使い方:インストール、auth、TUI Plan/Build、git diff

OpenCode CLI インストール、auth、TUI で最初の diff をレビュー。

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.

Install opencodeAuth loginTUI task + git diff

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.

TUI
Interactive agent
Plan
Tab planning mode
git diff
Review gate

Install the opencode binary

  1. 1

    Official install script (macOS / Linux)

    Run the documented installer, e.g. curl -fsSL https://opencode.ai/install | bash. Verify with opencode --version.

  2. 2

    Package managers

    brew install anomalyco/tap/opencode, or npm install -g opencode-ai (also pnpm/bun/yarn per docs). On Windows, see Chocolatey, Scoop, or npm in opencode.ai/docs.

  3. 3

    Avoid duplicate binaries

    Docs warn some install paths can conflict with OpenCode 2. Run which opencode and keep one install method if commands behave oddly.

Sign in and configure models (auth)

  1. 1

    /connect in the TUI

    Launch opencode, type /connect. Pick OpenCode Zen (sign in at opencode.ai/auth, add billing, paste your API key) or another provider from the list (see opencode.ai/docs/providers).

  2. 2

    Or opencode auth login

    From the shell: opencode auth login, choose a provider, store the key. Check opencode auth list; run opencode models for provider/model names.

  3. 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. 1

    cd to the Git root

    cd /path/to/your-repo and run git status so you know what is already dirty.

  2. 2

    Run opencode

    opencode opens the TUI. Optionally run /init once to analyze the project and write AGENTS.md (official Intro flow).

  3. 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. 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. 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 --auto until you trust the workflow (CLI flag in docs).

  3. 3

    git diff and /undo

    In another terminal, run git diff. Wrong result? /undo in the TUI or git restore on paths. Later try opencode 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 wrong

Feature comparison

EntryGood forFirst-hour note
TUI opencodeInteractive repo editsPlan then Build
opencode runScripts, quick Q&ARead-only first, no --auto
opencode auth loginProvider keysOfficial keys only
Claude Code / Codex CLIOther terminal agentsSee on-site guides
01

command not found

Reinstall; ensure npm global bin is on PATH.

02

No models / auth errors

opencode auth list; retry /connect; verify the key matches the provider.

03

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 → opencode in 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.

無料で会議を開始