Accounts
An account is one config folder of a CLI plus the environment variables a person set for it. The person signs in with the CLI itself, and the host only asks the CLI who is signed in. Each offered CLI has a default account that uses the CLI's own folder, with the CLI's kind as id. The offered kinds come from the registry's kinds(). The host keeps accounts of other kinds but never checks them.
ProviderAccountsService keeps a host's accounts. AgentHost exposes one as host.accounts. It answers the accounts.* requests, checks sign-ins periodically, and polls the CLI for a while after accounts.watchLogin. Accounts live in providers.json without secrets.
Under a non-default account, the host removes the variables that would sign the CLI in another way, points the CLI's folder variable at the account's folder, and adds the account's own variables. A chat can move only between accounts of the same CLI that share a conversation folder (canContinue). Otherwise the host fails with account-incompatible. An account it cannot start fails with account-unavailable.
A person orders the accounts of each CLI with accounts.reorder, which writes order. A start that names no account takes the top one that is on (defaultFor, topAccountOf). A host that gives a place its own default and turned-off accounts, such as a project, decides with chooseAccount in the core's openingAccount hook. A named account the place turned off fails with account-off-in-project. A preferred account that cannot take the start gives way to the next usable one, with the reason in passedOver.
A CLI keeps accounts when its provider has a home: the folder variable, the default folder, the variables that sign it in by themselves, and the loginCommand a person types in a terminal. A CLI that signs in from its first chat, such as an ACP agent, leaves loginCommand out. Its kind appears in chatLogins instead of loginCommands, and its accounts count as ready without a check.
A provider reads who is signed in with its own askAccount(command, env): Claude Code through claude auth status --json, Codex through account/read, every ACP provider over ACP (see ACP agents). A kind in loginCommands whose provider has no askAccount is also listed in silentLogins, so a login window should not promise to close by itself. A provider whose home.shadow is true makes an account a shadow home over the CLI's own folder, as Codex does. A provider's prepareHome(folder) puts what the host needs in an account's folder, such as Codex's rules.
accounts.create makes a folder for the new account under the data folder. For Codex it is a shadow home with its own auth.json and links to the shared home's sessions, skills and rules, so accounts continue each other's threads. A file already in the way is reported as not shared. This needs Codex to keep its login in a file, not the keychain.
Sharing the default account's setup
A provider whose home has a share lets an extra account read the setup of the default account. Claude Code does: CLAUDE.md, rules, skills, agents, commands and output-styles become links to the default folder's entries, and settings.json is written once with only the keys permissions, hooks, model, statusLine and outputStyle. The list is closed. A login, env, apiKeyHelper, history, projects and plugins are never named, so they are never shared.
A person turns it on per account with accounts.shareConfig, which sets shareConfig on the account. sharedConfigKinds in the snapshot names the kinds that offer it. The service applies it in prepare, before the host's install, when it creates the account and on every check, so an entry the default account gained later is linked. An entry the account already holds stays and is named in the status message. Turning it off removes only links that point at the default folder's entry of that name; real files and the copied settings.json stay.
A settings file is replaced by the copy only when it is missing or when the host's ownsSettings(config) option says it holds nothing but what the host wrote there, such as its hooks. config is the parsed file, or undefined when it is not JSON. Without ownsSettings the host owns nothing, so an existing file always stays and only a missing one is written.
Accounts kept apart
Some CLIs keep one sign-in for all of their folders. agy 1.5 keeps a Google sign-in in one keyring entry for every GEMINI_HOME, so signing one account out signs every account out. It keeps the sign-in in the folder only when it believes it runs over SSH. A provider whose home has an apart (ProviderApart) runs each account apart from the CLI's own folder:
variables(env)are laid over the environment of every account in a folder other than the CLI's own, after the account's own variables. No account may set them by hand. Antigravity setsSSH_CONNECTIONto the host's own value, or to a stand-in.defaultFolderis the folder the default account runs in instead of the CLI's own. The service makes it on the first start, and a check gives it the host'sinstalland the links below. Without it the default account stays in the CLI's own folder.linksare entries of the CLI's own folder that every account's folder links to, such as the person's global skills and rules. A link whose entry is gone is removed, and an empty folder the CLI made in a link's place gives way to the link. Real content in the way stays and is named in the status message. On Windows only folders are linked, as junctions.
createAntigravityProvider({ defaultHome }) turns this on for the default account too; antigravityDefaultHome(dataDir) puts it beside the folders of the other accounts. A person then signs every account in with agy acp --login in a terminal under that account, since no browser opens. The sign-in of the person's own agy in ~/.gemini is no longer shared with the host.
A host that starts a CLI for its default account without its accounts at hand, such as a single prompt, takes the environment from defaultAccountEnv(provider, env). For a CLI kept apart that holds the default account's folder and variables; for any other it is env.
The types behind it
ProviderAccountsOptionsare the options of the service: the data folder, theAccountsHost, the providers, the environment and thesecrets.chooseAccounttakes the kind, the accounts, the named and preferred account, and those turned off, and returns aChosenAccount. A passed-over account carries anAccountUnusablereason, such assigned outorat its usage limit.AccountLaunchesis how a terminal or a chat starts a CLI under an account: its environment, its transcript folder and its config folder.launchEnv(accounts, kind, account, baseEnv)returns the environment of a launch; without accounts wired only the default account starts.storedAccount(kind, account)is the id a record keeps: none for the default account, so nothing changes on disk for a host without accounts.askAccountasks a CLI who is signed in and answers withsignedIn,email,planandorganization.- Making a Codex account reports what it linked, what was in the way and stayed unshared, and whether the login itself would be shared.
Secrets
A variable marked sensitive goes to the macOS login keychain, never to providers.json. On other platforms it fails with secrets-unavailable. Clients get it as '' with valueRedacted: true, and saving that back keeps the stored value. A sensitive value holds printable ASCII only.
import type { AccountsHost } from '@adecore/agents/providers';
const accountsHost: AccountsHost = { name: 'My app', variablePrefixes: ['MYAPP_'], keychainPrefix: 'my-app' };Pass it as the host's accountsHost. name is how refusals name the host. No account may set a variable starting with one of the variablePrefixes. keychainPrefix plus a hash of the data folder names the keychain items. HOME, PATH, the CLIs' folder variables and duplicates are always refused. Keep the prefix and the data folder when you move a host, or it loses its secrets.
keychainService(host, home) is that name. A SecretStore reads, writes and removes the secrets. Pass one as secrets in the service's options to keep them elsewhere, such as in memory in a test; absent is the platform's own. variablesProblem(variables, reserved) says what is wrong with an account's variables, such as a name set twice or a reserved one, or returns null. reserved holds the host and the CLIs' folder variables it checks against.
The environment
Without an env the host gives its CLIs its own environment, filtered by cliEnvironment. Filter more with environmentPolicy:
import { cliEnvironment } from '@adecore/agents/host';
const env = cliEnvironment(process.env, {
sessionPrefixes: ['MYAPP'],
variables: ['OTHER_SESSION_TOKEN'],
prefixes: ['UNTRUSTED_']
});variables removes names, and prefixes removes names starting with one. sessionPrefixes removes <prefix>_HOOK_*, <prefix>_CONTEXT_* and <prefix>_SESSION_ID and keeps the rest, such as MYAPP_HOME. Without this, a host started inside an agent session hands that session's callbacks to its own agents. Filtering never changes its input. A legacy set of hook, context and session variables is always removed, whatever the policy. The names are in host/environment, behind @adecore/agents/host.
An env you pass is used as is, unless you also pass environmentPolicy. Add a chat's own credentials in envFor on the core.