Skip to content

Auth flows

AgentMux supports nine providers: claude, codex, gemini, pi, copilot, opencode, grok, dsh and muse. Each provider’s CLI does its own sign-in and keeps its own credentials. AgentMux doesn’t implement those logins: it runs the CLI’s own login command and points the CLI at a config directory AgentMux manages, through the environment variable that CLI already supports (for example CLAUDE_CONFIG_DIR or CODEX_HOME).

The per-provider values come from frontend/app/view/agent/providers/catalog.ts (PROVIDERS: authType, authCheckCommand, authLoginCommand, authConfigDirEnvVar, authExtraEnv) and crates/srv-core/src/backend/providers.rs.

ProviderauthTypeLogin command AgentMux runsConfig dir env var
Claude Codeoauthclaude auth loginCLAUDE_CONFIG_DIR
Codex CLIoauthcodex loginCODEX_HOME
Gemini CLIoauthgemini auth loginGEMINI_CLI_HOME (plus GEMINI_FORCE_FILE_STORAGE=true)
GitHub Copilot CLIoauthcopilot auth loginCOPILOT_HOME
Picli-managedpi-acp --terminal-loginPI_CODING_AGENT_DIR
OpenCodecli-managedopencode auth loginXDG_DATA_HOME
Grok Buildcli-managedgrok loginGROK_HOME
DeepSeek Harnesscli-manageddsh web (set the key on its Models page)DSH_HOME
Muse Codecli-managedmuse loginXDG_CONFIG_HOME

OpenCode keeps its sign-in under XDG_DATA_HOME, and Muse Code under XDG_CONFIG_HOME. AgentMux sets that variable to the provider’s folder, and the CLI makes its own opencode or muse folder inside it. Each of these variables was checked against the installed CLI: setting it moves where the CLI keeps its sign-in.

AgentMux checks whether a CLI is signed in by running its own status command (for example claude auth status --json or codex login status). The newest harnesses (OpenCode, Grok Build, DeepSeek Harness and Muse Code) have no status command AgentMux can rely on, so for them there is no check: the launch goes ahead, and a CLI that isn’t signed in says so in the pane when its session starts.

Six providers use a login of their own: Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, Grok Build (grok login, with a SuperGrok or X Premium+ account) and Muse Code (muse login, with a Meta account).

All six are account-backed: an agent using one of them must have an account bound for that provider (see Connectors → Accounts), or AgentMux refuses to start the CLI (provider_class in crates/srv-core/src/identity/resolver/provider.rs, enforced in inject_identity_env in crates/srv-core/src/identity/resolver/inject.rs).

AgentMux does not pass an API-key environment variable to these CLIs as a fallback.

For Pi and the four newest harnesses (OpenCode, Grok Build, DeepSeek Harness and Muse Code), the CLI keeps its own sign-in and AgentMux binds no account. AgentMux points the CLI at its shared folder for the provider, so every agent of that provider uses the same sign-in, kept apart from any copy of the CLI you use outside AgentMux.

  • OpenCode runs signed out on its own free models. Sign in to use your own account or keys.
  • Grok Build refuses to start a session until you sign in. It also takes XAI_API_KEY.
  • DeepSeek Harness starts signed out but needs a DeepSeek API key for its first prompt. Set it on the Models page of dsh web, or as DEEPSEEK_API_KEY.
  • Muse Code takes META_API_KEY.

When an agent pane launches, AgentMux runs the CLI’s auth check. If it fails, the pane shows Not signed in with Log in, Login via terminal, and Connectors → Accounts. When an existing account for the provider can be used instead, the last action becomes Use <account> (one candidate) or Use account… (several). After a turn has been rejected for auth, Log in reads Login Again. See First Agent Setup.

A new agent that isn't signed in: Not signed in, with Log in, Login via terminal, Use dev@acme.example, Copy error and Details

Log in goes through frontend/app/view/agent/flows/run-provider-login.ts (runProviderLogin):

  1. For the six account-backed providers (Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, Grok Build and Muse Code), AgentMux first allocates an account directory and points the login there. If the agent already has an account bound for the provider, that account’s directory is reused.
  2. It runs the login command and waits about 15 seconds for a login link in the CLI’s output. If it finds one, it opens it in your browser and shows the link in the pane with a box for pasting an authorization code, which is passed to the running login command. Claude Code runs the login in a pseudo-terminal. AgentMux then waits up to 5 minutes for the login to finish.
  3. If the CLI prints no link, AgentMux opens a terminal window for the login. For the account-backed providers it waits up to 5 minutes for the CLI’s auth check to succeed in the account directory. For the other providers it can’t detect completion: finish the login in the terminal, then log in again from the pane.
  4. On success, the account is saved and linked to the agent.

Login via terminal skips step 2 and goes straight to the terminal window.

For every other provider, no account is created: the login writes to the ambient directory described next. The newer CLI-managed harnesses log in interactively, so their login always runs in a terminal window.

There are two places.

Ambient directory. AgentMux points every agent’s CLI at the provider’s shared directory unless a bound account overrides it (crates/srv/src/server/app_api/agent_open.rs):

~/.agentmux/shared/providers/claude/
~/.agentmux/shared/providers/codex/
~/.agentmux/shared/providers/gemini/
…

This is DataPaths::provider_auth_dir in crates/common/src/data_paths.rs. The subdirectory name is the provider’s authDirName (frontend/app/view/agent/providers/types.ts), which is the provider id (claude, codex, gemini, copilot, pi, opencode, grok, dsh, muse). It is account-wide: every channel, version and instance on the machine shares it.

On Linux and macOS, AgentMux keeps its data root ~/.agentmux, which holds both kinds of credential directory, readable only by your user account. It creates the folder with mode 0700, and on startup it removes group and other access from an existing one (ensure_owner_only_dir in crates/common/src/data_paths.rs). On Windows your user profile’s permissions already restrict it to you.

Every provider except the six account-backed ones runs on the ambient directory. The six account-backed providers need a bound account: without one the agent can’t start until you sign in or bind an account.

Account directories. An OAuth login made through AgentMux for Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, Grok Build or Muse Code is saved as an account with its own directory, <identities>/<account_id>/<provider>/, where <provider> is the authDirName. When an agent is bound to such an account, AgentMux points the CLI’s config-dir variable there instead of at the ambient directory. Where <identities> lives depends on the channel, as described next.

Accounts are shared by every channel by default (crates/common/src/data_paths.rs, isolated_auth_enabled and identities_dir):

  • Every channel, stable, a dev-<branch> build from task dev and a local task package build’s local-<branch>-<hash>-<build-id> channel alike, shares one account list (in ~/.agentmux/shared/store.db) and one account-directory tree, ~/.agentmux/shared/identities/. A new build needs no login.
  • AGENTMUX_ISOLATED_AUTH=1 isolates one channel: it gets its own account list (<channel dir>/identity-store.db) and account directories (<channel dir>/identities/), and starts with no accounts. Use it to test the login and re-login paths from an empty store. Any other value, or no value, means shared.
  • The ambient directory is never isolated. It stays account-wide on every channel.

See Identity & Accounts for how an agent’s link to an account survives a channel switch, and Multi-instance & dev mode for channels in general.

The Accounts section of Connectors (Connectors → Accounts) manages accounts. It shows a tile per service: AgentMux, GitHub, Google, AWS, OpenAI, Anthropic, xAI, Slack and Custom (frontend/app/view/accounts/accounts-catalog.ts, SERVICE_CATALOG). Clicking AgentMux opens its own sign-in panel for AgentMux Cloud. If that sign-in stops working (its refresh was refused, or the cloud moved to a new sign-in service), the panel and the host popover in the status bar show your email with a Sign in again button, and AgentMux stops reconnecting with the old sign-in until you do (frontend/app/view/accounts/AgentMuxConnectPanel.tsx, frontend/app/statusbar/HostPopover.tsx). xAI is text only: Grok Build signs in inside the agent, so there is nothing to connect from here. Clicking any other tile offers Connect with OAuth, Add API key / token, or both:

  • Anthropic → Connect with OAuth runs the Claude Code login inside AgentMux, and OpenAI → Connect with OAuth runs Codex’s own login with a ChatGPT account.
  • GitHub → Connect uses AgentMux’s own GitHub App through AgentMux Cloud, so it needs an AgentMux Cloud sign-in: without one the tile says Sign in to AgentMux Cloud to connect GitHub and offers the sign-in. If you save an OAuth app of your own for GitHub (its client ID), Connect uses GitHub’s device flow with it, and needs no sign-in. Google and Slack use a PKCE browser login with an OAuth app of your own: paste its client ID and client secret (frontend/app/view/accounts/oauth-catalog.ts). A connected GitHub account reads “Connected as @login” in its details and asks to reconnect if you revoke it on GitHub. A Google account can give agents Gmail, Calendar and Drive, service by service: see Connectors → Google.
  • AWS and Custom offer only Add API key / token.
  • Add API key / token opens the Add Account form. A key you paste is kept as an api-key entry in the Vault, and the account holds only the entry’s id. Validate & Save checks the key against the service first; this is available for GitHub, OpenAI and Anthropic keys. Save without validating skips the check.

The Add Account form:

Connect Custom, a provider with no validator: Name, Provider, Kind, Display name, Secret backend, Key / token and Notes, with Save without validating and Cancel

Each account shows a status dot: green (valid), red (expired or invalid), amber (checking) or grey (unknown). For Claude Code and Codex CLI accounts, the status is refreshed from the account’s credential file each time AgentMux starts a bound agent’s CLI.

An agent’s account is chosen from the agent: click the login email in its composer strip (see Identity & Accounts). When an agent bound to one of these accounts starts, AgentMux sets that account’s key in the agent’s environment:

AccountEnvironment variables
GitHubGITHUB_TOKEN, GH_TOKEN
AnthropicANTHROPIC_API_KEY
OpenAIOPENAI_API_KEY
AWSAWS_ACCESS_KEY_ID

These mappings are in crates/srv-core/src/identity/resolver/provider.rs (provider_class). Keys for other services are not put in the environment.

These are independent layers:

  • The ambient directories are account-wide, provider-scoped and always global. Every instance on the machine shares them.
  • Accounts are bound per agent: a new agent takes the provider’s first account, and you change it later from the account chip in the agent’s composer strip. They override the ambient directory for that agent, and the six account-backed providers require one. Like the ambient directories, they are shared by every channel unless AGENTMUX_ISOLATED_AUTH=1 isolates one.

Two agents in the same instance can use different accounts for the same provider.

For a provider that runs on the ambient directory, you can sign its CLI in yourself, outside AgentMux, by setting its config-dir variable first:

Terminal window
export XDG_DATA_HOME=~/.agentmux/shared/providers/opencode
opencode auth login

Agents using that provider without a bound account then pick up the login. This doesn’t work for the six account-backed providers: a login in the ambient directory doesn’t satisfy their account requirement, so use Log in in the agent pane or Connectors → Accounts. This is rarely needed; Log in in the agent pane covers the usual case.