Moved to
srmdn/opcode-kitThis repo remains online for compatibility. New installs, docs, and future multi-tool development now live in
opcode-kit.
Switch between multiple OpenCode Go accounts instantly. No logout, no login, no env vars.
Canonical install:
curl -fsSL https://raw.githubusercontent.com/srmdn/opcode-kit/main/install.sh | bash -s -- opcode-switchCanonical docs:
- https://github.com/srmdn/opcode-kit
- https://github.com/srmdn/opcode-kit/blob/main/docs/opcode-switch.md
opcode-switch # list accounts, see which is active
opcode-switch work # switch to "work"
opcode-switch --save client # save current auth as named account
opcode-switch --add client sk-… # create account from raw key
opcode-switch --verify # check current key against APIOpenCode Go stores credentials locally (~/.local/share/opencode/account.json in recent versions, auth.json in older ones). If you have multiple accounts — personal, work, client projects, VPS — switching means copy-pasting API keys or re-authenticating every time.
opcode-switch keeps one JSON file per account in ~/.opencode/keys/. Switching copies the chosen file into place. One command, instant, works from any shell.
~/.opencode/keys/
├── personal.json
├── work.json
├── client-x.json
└── vps.json
↓ opcode-switch work
~/.local/share/opencode/account.json ← active (auth.json also written)
Recommended:
curl -fsSL https://raw.githubusercontent.com/srmdn/opcode-kit/main/install.sh | bash -s -- opcode-switchCompatibility install from this repo:
curl -fsSL https://raw.githubusercontent.com/srmdn/opcode-switch/main/install.sh | bashPrebuilt binary from canonical repo (pick your OS/arch from the latest release):
curl -fsSL -o ~/.local/bin/opcode-kit https://github.com/srmdn/opcode-kit/releases/latest/download/opcode-kit-darwin-arm64
chmod +x ~/.local/bin/opcode-kit
printf '#!/usr/bin/env bash\nexec opcode-kit switch "$@"\n' > ~/.local/bin/opcode-switch
chmod +x ~/.local/bin/opcode-switchThe canonical install builds opcode-kit from source, so it needs go. The compatibility install from this repo installs the standalone bash script, which needs bash and python3. Both need OpenCode.
opcode-switch --add work sk-abc123…opencode login # authenticate with new key
opcode-switch --save personal # snapshot itopcode-switch work # switch
opcode-switch --verify # ✓ API key is valid (14 models available)
opencode # launch — now uses "work"| Command | What it does |
|---|---|
opcode-switch |
List all accounts, show active with → |
opcode-switch <name> |
Switch to named account |
opcode-switch --save <name> |
Save current active credential as named account |
opcode-switch --add <name> <key> |
Create account from raw API key |
opcode-switch --rename <old> <new> |
Rename an account |
opcode-switch --verify |
Check current key against OpenCode API |
opcode-switch --help |
Show usage |
OpenCode >= 1.18 reads credentials from ~/.local/share/opencode/account.json (v2 account store); older versions use ~/.local/share/opencode/auth.json. This tool switches the active opencode-go credential in both files. No API calls, no rate limits, no logout.
- List: scans
~/.opencode/keys/for.jsonfiles, marks the one matching the active credential - Switch: merges the saved account into
account.json(preserving other providers), dual-writes legacyauth.json - Save: snapshots the active credential from
account.json(falls back toauth.json) into~/.opencode/keys/ - Add: builds a v2 account entry from a raw key, writes to keys dir
- Verify: runs
opencode models opencode-goto validate key against API
- Keys stored in
~/.opencode/keys/withchmod 600(owner read/write only) - Keys never pass through shell history
- No keys in
.zshrc,.bashrc, or environment variables - Do NOT commit
~/.opencode/keys/to any git repo - Do NOT sync
~/.opencode/keys/via iCloud or Dropbox
Does this work with OpenCode Go only?
Yes. OpenCode Go uses the opencode-go provider in auth.json. Third-party model keys (Copilot, ChatGPT, etc.) use different providers and aren't affected.
Can I use two accounts simultaneously?
Not via the switcher (one active at a time). For simultaneous usage, set OPCODE_API_KEY per terminal session.
What happens when I switch mid-session? Nothing. Running OpenCode instances cache the key at startup. Restart OpenCode after switching.
Is this against OpenCode ToS? No. It's a bash script that copies locally-stored credential files. No reverse engineering, no auth bypass, no ToS violation. See OpenCode Terms.
Why Go now, when this used to be bash?
The canonical tool moved to a single Go binary (opcode-kit with a switch subcommand), so it installs as one command with prebuilt binaries per OS/arch. This repo keeps the standalone bash script for compatibility. Either way: no runtime to set up, no package-manager lock-in.
MIT © srmdn