OpenCode with more than one account per provider
OpenCode keeps one login per provider in ~/.local/share/opencode/auth.json, so signing in again with another account replaces the first. To keep two accounts for one provider, run each with its own XDG data folder; OpenCode 2, a separate install, stores several and switches between them with opencode auth switch.
Contents
OpenCode 1, the version opencode.ai/install and the opencode-ai npm package give you, doesn't support multiple accounts for one provider. Its ~/.local/share/opencode/auth.json has room for one login per provider, and a second opencode auth login with another OpenAI or GitHub account overwrites the first. Both stay signed in if each account runs with its own XDG_DATA_HOME, since that gives each one an auth.json of its own.
We read OpenCode's docs on 24 October 2026, and its source at the 1.19.4 tag (22 October 2026) where the docs stop. OpenCode 2 handles this differently, and it gets its own section further down.
Where OpenCode keeps your logins: auth.json#
Whatever you connect, with /connect inside OpenCode or opencode auth login in a shell, lands in one file. The providers page says keys added with /connect "are stored in ~/.local/share/opencode/auth.json", and the troubleshooting page describes the same file as "Authentication data like API keys, OAuth tokens". Windows puts it under %USERPROFILE%\.local\share\opencode.
The source shows why a second account can't fit. The file is a JSON object keyed by provider ID (openai, anthropic, github-copilot, opencode-go), written with file mode 0600, and under each key sits a single value: an API key, an OAuth token set, or a token from a well-known login. A second openai account has nowhere to go except over the first.
To see what the file holds, run opencode auth list (opencode auth ls for short). Its first line names the file it read, for example Credentials ~/.local/share/opencode/auth.json, and each provider follows with its type, api or oauth. Keys that come from your shell, such as OPENAI_API_KEY, are listed apart in a second block called Environment.
What opencode auth login does to the account already there#
A login to a provider you already have overwrites its entry. Sign in to ChatGPT Plus as one account and then as a second, and auth.json keeps only the second; getting back to the first takes another login.
opencode auth logout undoes a login. With no argument it asks which provider to drop, and opencode auth logout openai names it directly. The CLI docs say it "Logs you out of a provider by clearing it from the credentials file", and the code does only that: it deletes the entry and writes the file back. OpenCode sends nothing to the provider, so an API key you remove from OpenCode keeps working until you revoke it in that provider's console.
That data folder holds more than logins, which matters for the next step. The troubleshooting page also lists opencode.db ("projects, sessions, and messages"), log/ and snapshot/ there, so moving the data folder moves your history with it.
How to run multiple OpenCode accounts side by side#
global.ts builds OpenCode's folders from the XDG base directory variables. Set XDG_DATA_HOME=~/.local/share-work and OpenCode reads and writes ~/.local/share-work/opencode/auth.json instead, so a second account needs that one variable and nothing else.
-
Give each extra account an alias in
~/.zshrcor~/.bashrc:bashalias opencode-work='XDG_DATA_HOME="$HOME/.local/share-work" opencode' -
In a new terminal,
opencode-work auth loginasks for the provider; sign in with the second account. OpenCode creates the folder itself. -
opencode-work auth listshould now name~/.local/share-work/opencode/auth.jsonon its first line, while plainopencode auth liststill lists the first account's providers. -
From here on,
opencodeis the first account andopencode-workthe second. When you lose track of which folders are in use,opencode debug pathsprints every one.
PowerShell has no alias that sets a variable. $env:XDG_DATA_HOME = "$HOME\.local\share-work" followed by opencode works for the window you type it in and no other; to keep it, put a function in your PowerShell profile that sets the variable, runs opencode @args and puts the old value back.
Config isn't part of the split. opencode.json, MCP servers and agents stay in ~/.config/opencode, which follows XDG_CONFIG_HOME, so both accounts share them. History is split, because each data folder has its own opencode.db; moving one session across takes opencode export in one profile and opencode import <file> in the other.
The same trick covers a different case: one OpenAI account through a ChatGPT sign-in and another through an API key. Both would go in the openai slot, so they need two data folders as well.
OpenCode 2 keeps several accounts per provider#
OpenCode 2 is a separate install, and the standard script won't give it to you: opencode.ai/install installs OpenCode 1 only, and its comments say OpenCode 2 "ships as @opencode/cli" on npm. The latest version there on 24 October 2026 was 2.1.4.
Its CLI providers page says "Each successful API-key, OAuth, or command login creates a saved account" and "The newest account becomes active". So a second opencode auth login to the same provider adds an account instead of replacing the first. opencode auth list shows them, opencode auth switch makes another one active (named by its label or ID, or picked from a list), and opencode auth logout asks which one to remove. In the TUI, running /connect again on a connected provider opens the same account list. The command came in on 9 September 2026 (switch.ts).
The accounts live in OpenCode 2's SQLite database, not in auth.json. During its database migration it imports the credentials it supports from the old auth.json in its data folder, and new or changed logins are saved in the database, not written back to that file. One account per provider is active at a time, so it's a switch, not two accounts at once.
Is it allowed to use two accounts in OpenCode?#
Use only accounts you own and are entitled to use. Whether a second one is allowed is up to each provider's terms, not OpenCode.
Claude is the clear case. OpenCode's providers page says there are plugins for using Claude Pro or Max in OpenCode, that "Anthropic explicitly prohibits this", and that OpenCode stopped bundling them in 1.3.0. Claude still works in OpenCode with a Claude Console API key, or through Amazon Bedrock or Google Vertex AI. Anthropic's wording, and what it allows instead, are quoted in can you use your Claude plan in OpenCode.
OpenAI is different. OpenCode offers a "ChatGPT Plus/Pro" sign-in under /connect, and OpenAI's own cookbook page on Sign in with ChatGPT, dated 28 September 2026, says its plan-usage integration "is available for open-source tools and personal projects that run locally". That page doesn't name OpenCode, and we didn't check which sign-in route OpenCode uses. OpenAI's Terms of Use still forbid sharing your account credentials, making your account available to anyone else, and circumventing rate limits or restrictions. What they say about holding a second ChatGPT account is in two ChatGPT accounts with Codex: the rules.
How Shuriken runs several OpenCode sources#
In Shuriken, each OpenCode sign-in you add under Settings › Sources is a source (what a source is). Shuriken gives every source a folder of its own under ~/.shuriken/accounts and points XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_STATE_HOME at its config, data and state subfolders: the same isolation as the alias above, with config and state moved too. Adding the source opens a sign-in terminal in the app that runs opencode auth login with those variables, so OpenCode writes that account's auth.json into the source's folder and your own ~/.local/share/opencode/auth.json stays as it was. One source can hold logins for several providers, as one OpenCode install does.
Every OpenCode chat that runs on a source starts with that source's folders. Shuriken reads plan usage for an OpenCode chat in two cases: on an openai/ model with a ChatGPT sign-in it reads that plan's usage the way it does for Codex, and on an opencode-go/ model it reads OpenCode Go's rolling, weekly and monthly windows. For other providers, Shuriken has no usage reading for an OpenCode chat.
OpenCode runs as a chat next to Claude Code, Codex and the other agents, and every chat but a project's Main chat works on its own branch; the OpenCode comparison covers what that adds and what OpenCode's own app already does well. The same folder-per-account approach for the other CLIs is in multiple accounts in every coding agent CLI. Free holds two sources, Pro has no cap, and the download is here.
Sources
- OpenCode docs: CLI (auth login, list, logout, export, import, debug paths) (accessed 24 October 2026)
- OpenCode docs: Providers (credentials, Anthropic, OpenAI, OpenCode Go) (accessed 24 October 2026)
- OpenCode docs: Troubleshooting (storage) (accessed 24 October 2026)
- OpenCode 1.19.4 source: auth/index.ts (auth.json, one entry per provider) (accessed 24 October 2026)
- OpenCode 1.19.4 source: cli/cmd/providers.ts (auth list and logout) (accessed 24 October 2026)
- OpenCode 1.19.4 source: core/src/global.ts (XDG base directories) (accessed 24 October 2026)
- OpenCode install script (installs OpenCode 1 only) (accessed 24 October 2026)
- OpenCode 2 docs: CLI providers (accounts, auth switch, storage) (accessed 24 October 2026)
- OpenCode source: feat(cli): add auth account switching and targeted logout (#48050) (accessed 24 October 2026)
- OpenCode source: core/src/credential.ts (several credentials, one active) (accessed 24 October 2026)
- OpenAI Cookbook: Integrating Sign in with ChatGPT in your Opensource App (accessed 24 October 2026)
- OpenAI Terms of Use (accessed 24 October 2026)
Frequently asked questions
Where does OpenCode store my API keys and logins?
OpenCode 1 keeps them in ~/.local/share/opencode/auth.json, one entry per provider, written with file mode 0600 (on Windows, %USERPROFILE%\.local\share\opencode\auth.json). Set XDG_DATA_HOME and the file is in $XDG_DATA_HOME/opencode instead.
How do I log out of one provider in OpenCode?
opencode auth logout asks which provider to drop, and opencode auth logout openai names it. Only that provider's entry leaves auth.json, and OpenCode makes no call to the provider, so a key you want dead has to be revoked in the provider's console.
Can OpenCode switch accounts without logging out?
Not OpenCode 1, the version the standard installer gives you, because it holds one credential per provider; give each account its own XDG_DATA_HOME instead. OpenCode 2, installed separately as @opencode/cli, keeps several and changes the active one with opencode auth switch.
Does a separate XDG_DATA_HOME split my chat history?
Yes. Sessions live in opencode.db, in the same data folder as auth.json, so each account sees only its own. opencode export in one and opencode import with the JSON file in the other carries a session across.
Can I add a second Claude Pro or Max account to OpenCode?
Not with the plan's sign-in. OpenCode's providers page says Anthropic explicitly prohibits using Claude Pro or Max there, and OpenCode stopped bundling those plugins in 1.3.0. Claude works in OpenCode with a Claude Console API key.