Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opcode-switch

Moved to srmdn/opcode-kit

This 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-switch

Canonical docs:

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 API

Problem

OpenCode 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.

Solution

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)

Install

Recommended:

curl -fsSL https://raw.githubusercontent.com/srmdn/opcode-kit/main/install.sh | bash -s -- opcode-switch

Compatibility install from this repo:

curl -fsSL https://raw.githubusercontent.com/srmdn/opcode-switch/main/install.sh | bash

Prebuilt 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-switch

The 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.

Quickstart

Add an account from a raw key

opcode-switch --add work sk-abc123…

Save after logging in

opencode login                        # authenticate with new key
opcode-switch --save personal         # snapshot it

Switch and verify

opcode-switch work                    # switch
opcode-switch --verify                # ✓ API key is valid (14 models available)
opencode                              # launch — now uses "work"

Commands

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

How it works

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 .json files, marks the one matching the active credential
  • Switch: merges the saved account into account.json (preserving other providers), dual-writes legacy auth.json
  • Save: snapshots the active credential from account.json (falls back to auth.json) into ~/.opencode/keys/
  • Add: builds a v2 account entry from a raw key, writes to keys dir
  • Verify: runs opencode models opencode-go to validate key against API

Security

  • Keys stored in ~/.opencode/keys/ with chmod 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

FAQ

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.

License

MIT © srmdn

About

Switch between multiple OpenCode Go accounts instantly. No logout, no login, no env vars — one command.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages