Skip to content

Reference: amplihack profile

Manage Claude Code login profiles. See the how-to for a walkthrough.

Automatic selection also follows organisation affinity: same-organisation capacity takes precedence over headroom ranking; upgrades never make a confirmed crossing, the rotator crosses for capacity only when the live login has no room, and an unknown organisation is not a crossing. The reference describes the crossing and unresolved-affinity warnings and how a resumed session receives them.

The rotator moves ~/.claude only to a login that has room now: see Rotate target choice.

See also the capacity governor, which reads the usage readings described here to decide when new work may start.

Synopsis

amplihack profile add <name>
amplihack profile list
amplihack profile root [<dir>]
amplihack profile show
amplihack profile switch <name> | --none
amplihack profile remove <name> --yes
amplihack profile login <name>
amplihack profile run <name> -- <claude-args>...
amplihack profile usage [--json | --summary-json | --table] [--utc] [--raw] [--spend] [--usable-session-pct <1-100>] [<name>...]
amplihack profile auto-switch on [--threshold <1-100>] [--exclude <name,...>]
amplihack profile auto-switch off [--exclude <name,...>]
amplihack profile auto-switch status
amplihack profile auto-switch threshold <1-100>
amplihack profile auto-switch exclude [<name>...]
amplihack profile auto-switch install
amplihack profile auto-switch repair
amplihack profile overflow add|remove|clear <name>
amplihack profile overflow list
amplihack profile rotate [--dry-run] [--session-at N] [--week-at N] [--margin N] [--upgrade-margin N] [--hold SECS] [--target-week-max N] [--overflow-wait SECS] [--overflow-unknown-reset 0|1]
amplihack profile rotate start|watch [<tuning flags>] [--interval SECS]
amplihack profile rotate watch [<tuning flags>] [--interval SECS] --supervised[=UNIT]
amplihack profile rotate stop|status
amplihack profile rotate autostart [on|off]
amplihack profile rotate owner [clear]
amplihack profile kind list
amplihack profile kind set <name> <subscription|api-key|auto>
amplihack profile verify [--fix]
amplihack profile seed-record <name> [--write]
amplihack profile prune-probe-logs [--dir <dir>] [--dry-run]
amplihack profile overflow clear --platform
amplihack launch|claude --profile <name> [...]

Subcommands

Command Behavior
add <name> Copy allowlisted shared assets from ~/.claude into a private staging directory, then atomically publish <root>/<name>/ (mode 0700 on Unix; Windows uses its inherited ACL). Errors if a profile exists whose name matches case-insensitively, on every platform. Does not run Claude. Then links projects/, file-history/ and session-env/ to ~/.claude when it exists; see Shared session directories. The first add also saves the root it used; see Saved on the first add.
root [<dir>] Print the profile root in use and where it came from, or save <dir> as the root. See Profile root.
list First line root: <path> (source: env\|config\|default); see Profile root. Then one profile per line, sorted; the default is marked *. Skips dot-entries, symlinks and non-directories. Reports a corrupt or dangling default pointer instead of silently omitting the marker.
show Prints name: <name> and dir: <path>, or none. Paths only; never directory contents.
switch <name> Moves the profile's login into ~/.claude with the rotator's swap, under the rotator's lock, then pins rotation to it, writes the default pointer and records the switch in the rotate ledger, so sessions stopped on a usage limit before it are resumed. The profile must exist. Then checks the shared session links of both profiles in the swap; messages go to stderr. It moves that profile's login file away from sessions started with --profile <name>. When the live login cannot be moved (any system but Linux, a profile open in a session, no login in ~/.claude, ...), it still writes the default pointer, holds nothing and exits 1. See Rotate switch.
switch --none Removes the default pointer and the rotation pin. Prints Default profile cleared., or No default profile was set. when there was none, plus Rotation released; the rotator picks the best login on its next cycle. when a pin was removed; exits 0 either way. Moves no login. Conflicts with a name; switch with neither is a usage error. See Clearing the default.
remove <name> Requires --yes. Resolves and verifies the path is inside the root, reads the default pointer, deletes the directory, then clears a matching pointer. A missing pointer means no default; a corrupt, unreadable or dangling pointer fails closed before any deletion (repair with switch). Never deletes the root; never follows symlinks, so the shared session links are removed and the sessions in ~/.claude are kept. *.pre-share-* backups inside the profile are deleted with it.
login <name> Checks the profile's shared session links, then always runs the claude binary (ignores binary selection), interactively, with CLAUDE_CONFIG_DIR=<profile dir>. Then refuses a login whose account another profile or ~/.claude already holds, and restores the previous login. See Login check.
run <name> -- <args> One-shot launch through the normal launch path. Args are forwarded as a literal argv vector; no shell is involved.
usage [<name>...] Reads each profile's usage from Anthropic's OAuth usage endpoint with the profile's own token, several profiles at a time, and starts claude only for a profile whose direct read fails for a reason other than a missing login, or, with --spend, to read the spend limit of an account with usage credits on; then shows its weekly and session usage as bars and its spend status as a mark, sorted by the rotator's headroom, followed by a capacity summary and, with no names, a live reading of each Codex account. --table for the text table, --utc for UTC reset times, --json or --summary-json for scripts, --raw to include Claude's output. Refreshes auto-switch readings and adds to the usage history. See Usage command.
auto-switch … Turn auto-switch on or off, set its threshold and exclusions, show its state, or install and repair the status-line wrapper. See Auto-switch commands.
overflow … Mark or unmark a credit-backed profile that the rotator may use when every plan login is exhausted, list the marks, or lift a spend-limit block. See Overflow commands.
rotate … Keep the login in ~/.claude on the account with the most capacity: once, as a dry run, or in a background process with start, stop and status; autostart controls whether launches start that process. See Rotate.
kind list, kind set <name> <kind> Show whether each profile is a subscription or an API-key profile, and set or remove an override. See Kind override.
verify [--fix] Unix only. For ~/.claude and each profile folder, print the account Anthropic's OAuth profile endpoint reports for the folder's own token, against the account recorded for it. --fix moves a profile's login that is another profile's recorded account into that profile's empty folder; do not use it until #1960 is closed. See profile verify.
seed-record <name> [--write] Unix only. Shows the account a profile with no record would be recorded with, from one fresh reading. --write saves it. Moves no login and writes no credentials file. See profile seed-record.
prune-probe-logs [--dir <dir>] [--dry-run] Deletes the session logs that usage probes from older amplihack versions left in ~/.claude/projects/<encoded home>, and nothing else. --dry-run lists them without deleting. Never run automatically. See Prune probe logs.

remove and login are also refused while auto-switch has an account's login away from home; see Leases. run, switch and --profile launches refuse a subscription profile with no OAuth login of its own on Unix; see No silent billing.

Usage command

amplihack profile usage [--json | --summary-json | --table] [--utc] [--raw] [--spend] [--usable-session-pct <1-100>] [<name>...]

Shows how much of each profile's current session and weekly quota is used and when each resets, so you can see which accounts have capacity. Below the bar view or table, a capacity summary adds the rows up: weekly headroom across all logins, how many can take work now, the next session reset, how long the weekly capacity lasts at the recent rate, and which weekly limits reset in the next 24 hours. With no names it covers every profile under the root, as list does, and then reads each Codex account live and lists it after the Claude output, the warnings and the usage history update, marking the one codex-pick's rule picks from these live readings. Each name must pass the name rules and must exist. A name given twice is probed once. Names select Claude profiles only; with names, Codex is not read.

Flag Effect
--json Print the profile rows as one JSON array instead of the bar view. Claude rows only: Codex is not read, and the Codex rows are in --summary-json. No summary. See JSON output. Conflicts with --table and --utc.
--summary-json Print one JSON object holding the same Claude rows, the summary and the Codex rows. Cannot be combined with --json, --raw, --table or --utc (exit status 2). See Summary JSON.
--table Print the eight-column text table instead of the bar view. The capacity summary follows it as it follows the bar view. See Table output. Conflicts with --json, --summary-json and --utc.
--utc Show reset times in the bar view in UTC, as MM-DD HH:MMZ, instead of local time. See Reset times. Conflicts with --json, --summary-json and --table.
--usable-session-pct <n> Session percentage below which a login counts as usable now in the summary, 1 to 100; default 95. Overrides AMPLIHACK_PROFILE_USAGE_USABLE_SESSION_PCT. A value out of range is a usage error (exit status 2). See Usable now.
--spend Also run one /usage probe for each row whose account has usage credits on, to fill its spend status: the spend: mark in the bar view, the SPEND cell with --table. Without it no claude is started for those rows and their spend is not_probed. See Spend probe.
--raw Also print what claude wrote to stdout and stderr, for each profile, from the attempt that gave the row. Without it, that output is dropped once parsed. Rows read without claude print a fixed line instead. Also prints the note: lines for rows that fell back or whose account has usage credits on. It can include account details; see Raw output. With --raw there is no summary and nothing is added to the usage history.
<name>... Probe only these profiles, in the usual order.

How a profile is probed

Each OAuth profile is read in this order, and the first step that gives a result decides the row:

  1. Passive reading. A reading already stored in usage.json for the account in the profile's directory, if it is no older than AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS (300 seconds by default).
  2. Direct read. amplihack asks Anthropic's OAuth usage endpoint itself, with the login stored in the profile's .credentials.json. No claude process is started. See Direct read.
  3. Fallback. Only when the direct read fails for a reason other than a missing login: the claude probe described below, which sends the get_usage request and then, if needed, runs claude -p /usage. A profile with no login to use ends at step 2 as not_logged_in, and no claude is started for it.

An HTTP 429 skips /usage. With a future Retry-After, both Claude fallback attempts are skipped. Without a usable retry time, the ordered mode can still send the get_usage control request once. If it supplies no reading, the row reports the direct failure.

Every row records which step gave it as its source: passive, direct or fallback. Some profiles skip steps:

Profile Steps
In the auto-switch exclude list None. It is not probed, read or refreshed. See Excluded profiles. This wins over every row below.
API-key profile None. It is not probed, as before.
Marked as overflow Fallback only, as /usage text. The spend limit is visible only in /usage, so the spend-limit block keeps working. Source fallback. Under AMPLIHACK_PROFILE_USAGE_PROBE=direct the row is not probed and reads error; see Probe method.
A direct answer shows usage credits turned on (extra_usage is not absent, null or {"is_enabled": false}) The windows and state come from the direct answer. Source direct. Spend not_probed, unless --spend asks for one /usage text probe, under the normal per-probe timeout (--timeout-secs, 120 s by default), that reads only the spend status; see Usage credits on. If neither window in the answer is usable, the direct read fails with usage credits on and the profile goes to the fallback.
A direct read finds no login: no oauth token or no refresh token (Unix), or, on Linux only, no credentials file in a directory that exists Passive, then direct. The row is not_logged_in with source direct, and no claude is started. See Logins with no token.
Any profile, with AMPLIHACK_PROFILE_USAGE_PROBE set to auto or text Fallback only, with the method named. See Probe method.
Any profile, with AMPLIHACK_PROFILE_USAGE_PROBE=direct Passive, then direct. A failed direct read gives state error, or not_logged_in for a missing login, and the reading starts no claude. An account with usage credits on gives its direct windows, with spend not_probed, because no spend probe runs, even under --spend. Overflow profiles read error without a direct read. The one exception is the rotator's held-cycle spend-limit check.

When every row is passive or direct, no claude process is started, and amplihack does not look for the claude binary at all, unless --spend asks for a spend probe of a row with usage credits on. It looks for it the first time a row needs the fallback or a spend probe, and keeps the result for the rest of the command (or the rest of the rotator cycle). If claude cannot be found then, only the rows that needed it for a reading read error, with the reason claude not found; a row that needed it only for a --spend probe keeps its windows and shows spend unknown. The other rows are unaffected.

Passive readings

A passive reading is the entry in <root>/.auto-switch.d/usage.json for the account whose login is in the profile's directory, as the auto-switch ledger names it. For a profile live in ~/.claude, that is the profile's own account. The entry is used only when all of these hold:

  • auto-switch state exists and the ledger names an account for the directory;
  • the entry's observed_at is no later than now and no more than AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS seconds ago;
  • at least one of its windows passes the same plausibility check as a status-line reading: a finite percentage, and a reset from one day before to eight days after now.

Otherwise the profile is read directly. The live profile is no exception: a stale reading for it is read directly like any other.

Setting Values Default
AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS 0 to 3600 300

0 turns passive readings off. An empty variable counts as unset. Any other value prints one warning to stderr, showing the value escaped and cut to 32 characters, then uses 300:

warning: ignored AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS "ten" (use 0 to 3600); using 300

A passive row is built from the stored windows: five_hour becomes session and seven_day becomes week_all. resets_text is the reset time written as YYYY-MM-DDTHH:MM:SSZ. week_models contains retained model observations whose recorded reset is strictly after now. At equality an observation has expired. Each model retains its own observed_at, so a new passive reading does not make that model appear newly measured. An entry with a plausible seven_day and no five_hour reads as no session limit: session is null and session_limit is false, as a direct read of the same answer gives, and as auto-switch counts a login with no session window. So a login with weekly figures only reads the same whether it was read directly or passively. An entry whose five_hour was stored but fails the plausibility check keeps session_limit true, with the session unknown. The state follows the usual rule.

The status-line wrapper writes these readings during live sessions. Rows that profile usage and the rotator record are stored in the same way, so they also count as passive while they are fresh: a second profile usage within 300 seconds reads most rows passively. A row read from the usage endpoint is stored with source direct and the time it was read; a row read through claude is stored with source statusline. Every reader treats the two sources the same way. So a login the rotator read directly in the last 300 seconds is read passively by profile usage, which sends no request for it. A passive row is never recorded again, so a reading does not stay fresh by being read. With AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS=0 no stored reading is used, and every caller sends its own request, as before.

amplihack profile usage --help states the window: a stored reading younger than 300 seconds (AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS, at most 3600) is used without starting claude. The same help says that the ~/.claude row and AMPLIHACK_PROFILE_USAGE_PROBE=auto or text always probe.

This applies to the rotator too. A rotator cycle records the rows it measured, so with --interval 120 the next two cycles mostly use those readings rather than asking again. A candidate can be ranked on a reading up to AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS seconds old (300 by default), but the rotator never swaps to it on that reading alone: a target whose reading is more than 300 seconds old, or older than the live login's, is read again first, by the probe method with passive readings off; see Rotate reading freshness. Lower the value in the rotator's environment for it to react sooner; see Readings that take longer than a cycle. To force a new reading of every profile, run with AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS=0.

Direct read

amplihack reads the profile's OAuth login and sends one request:

GET https://api.anthropic.com/api/oauth/usage
Authorization: Bearer <access token>
anthropic-beta: oauth-2025-04-20
Accept: application/json
User-Agent: amplihack-profile-usage

This is the endpoint Claude Code's /usage reads. The endpoint, the beta header, the default token URL and the OAuth client id used for refreshes are the values Claude Code 2.1.316 uses, and are constants in usage_direct.rs; a change on Anthropic's side makes direct reads fail, and every profile then falls back to claude, more slowly but with the same figures.

Which login is read. The credentials file follows the directory claude would use for that row:

Row File
A profile in its own directory <root>/<name>/.credentials.json
A profile live in ~/.claude $HOME/.claude/.credentials.json

The file is opened without following symlinks and read up to 64 KiB. It must be a regular file owned by you and not writable by group or others. The access token is claudeAiOauth.accessToken; claudeAiOauth.expiresAt is its expiry in Unix epoch milliseconds. A token is used only if it is 1 to 4096 bytes long and every byte is a printable ASCII character other than a space (0x21 to 0x7E). A token is used only for the row of the directory it was read from.

The answer. The body is read up to 64 KiB and parsed as JSON. It has the same five_hour, seven_day and extra_usage objects as the rate_limits object of a get_usage answer, and is read by the same code, so the rules for utilization, resets_at, what counts as credits on, and no session limit are the same. The one difference is what happens when credits are on: the usage request's answer is rejected, but a direct answer still gives its windows; see Usage credits on. For example:

{
  "five_hour": { "utilization": 100.0, "resets_at": "2026-11-01T14:00:00Z" },
  "seven_day": { "utilization": 55.0, "resets_at": "2026-11-05T09:00:00Z" },
  "extra_usage": { "is_enabled": false }
}

gives a session_exhausted row with session at 100% and week_all at 55%. The weekly figure is always the one reported, whatever the session reads. Unknown fields are ignored. A body that is not a JSON object, or in which neither five_hour nor seven_day has a valid utilization, is unparseable. A direct read that gets an answer never gives spend_limit, not_logged_in or unparsed. A direct read that finds no login to use gives not_logged_in without any request; see Logins with no token.

Timing. The connect and read timeouts of each GET are min(10 seconds, deadline - 1 second), at least 500 milliseconds, and the whole read, refresh included, must finish within the deadline. The deadline is fixed when the read starts, and each request is given only the time left of it, so a GET that answers 401, the refresh POST and the second GET together take no longer than one deadline. No request starts once the deadline has passed.

The DNS lookup is inside that deadline too. The HTTP client puts no time limit on a lookup of its own, so each lookup is bounded by amplihack: for a GET, by the read's deadline; for the refresh POST, by its connect timeout less 500 milliseconds. A lookup that misses its bound ends the request as a DNS failure, before any of the request is sent.

A refresh POST is sent only when at least 3 seconds of the deadline are left; otherwise none is sent and the read is timeout. A refresh can retire the old refresh token, so one given up on before its answer arrives could leave the profile logged out, while a skipped refresh costs only this read. The POST's connect and read timeouts are min(10 seconds, time left), so never below 3 seconds, and it too ends by the deadline. With a deadline under 3 seconds, a direct read never refreshes. Redirects are not followed. HTTPS_PROXY and similar variables are ignored. One read makes at most two GETs and one refresh POST. An HTTP 429 ends the direct read. A future Retry-After expressed as delay-seconds or an HTTP date gives the earliest time a later caller can make a direct read for that login. The usage row shows that time. The usage command and every rotate mode, including --dry-run, share the deadline. An absent, invalid, or elapsed value leaves the next ordinary caller eligible. The deadline is shared by callers using the same OAuth login or the same named profile. A profile moved into ~/.claude keeps its profile scope, and a Claude or Amplihack token rewrite in that scope keeps the deadline. A replacement login under the same profile name also waits if the previous login left an active deadline there. A caller that finds a usage request in progress reports the probe as unread and returns without sending a request.

An interrupted request or failed deadline write leaves no known server deadline. Once the lock is available, the next ordinary caller may make one request. A later 429 replaces the incomplete record with the new server deadline. This can result in one additional early request after a failed publication.

For a failed profile usage row, the table and JSON can show a direct reading up to 300 seconds old when the current OAuth credential matches the one used for that reading. The cached figures keep their original observation time and are for display only. Profile-name history and passive readings lack that credential match and cannot supply these figures.

Endpoint overrides. Two variables point the direct read at another server, for tests or a local relay:

Setting Default
AMPLIHACK_PROFILE_USAGE_API_BASE https://api.anthropic.com
AMPLIHACK_PROFILE_USAGE_TOKEN_URL https://platform.claude.com/v1/oauth/token

A value is accepted only if it starts with https://, or starts with http:// and its host is exactly 127.0.0.1, [::1] or localhost. The scheme is matched exactly, in lower case. A value with whitespace, a control character, @, ? or # in it is refused, and the host is checked again after the URL is parsed, so http://localhost.example.com and http://127.0.0.1@example.com are refused. HTTPS is required for both requests unless both values are loopback addresses. A refused value prints one fixed warning, which never repeats the value, and the default is used:

warning: ignored AMPLIHACK_PROFILE_USAGE_API_BASE (use https:// or a loopback http:// address); using the default

An empty variable counts as unset.

Direct read failures

A direct read that fails gives one of these fixed reasons. None of them holds a token, a URL, a response body or an underlying error message; only the numeric HTTP status class is kept.

The read checks the credentials file first: it is opened and checked, then an expired token with no refresh token is caught, and only then are the endpoint settings used. A profile with no login therefore gives no credentials file, no oauth token or no refresh token even when the endpoint settings are unusable, and never transport.

Reason When
no credentials file The credentials file is missing.
credentials refused The file is a symlink, not a regular file, owned by someone else, writable by group or others, over 64 KiB, or could not be read.
no oauth token The file says there is no login: it is the empty object {}, or its claudeAiOauth object has no accessToken, or one that is null or empty.
unreadable credentials The file is there but is not a login this read recognises: it is not JSON (a format change, or a file caught mid-write), is not a JSON object, is a non-empty object with no claudeAiOauth (an API-key login, or a renamed key), has a claudeAiOauth that is not an object, or has an accessToken that is not a string or is over 4096 bytes or holds whitespace or a non-printable byte. Also given for an expired token whose refreshToken is there but rejected the same way.
no refresh token The token has expired (expiresAt is at or before now), and the file has no claudeAiOauth.refreshToken (missing, null or empty). A refresh token that is there but rejected (not a string, over 4096 bytes or holding whitespace) gives unreadable credentials instead. Checked before any request, whether or not amplihack may refresh in this directory. No request is sent. A missing or non-numeric expiresAt does not count as expired.
token expired The token has expired, the file has a refresh token, and amplihack may not refresh it in this directory, so claude is left to refresh it.
http 401, http 403, http 429 The endpoint answered with that status (a 401 after any allowed refresh).
http 3xx, http 4xx, http 5xx Any other status of that class.
timeout A timeout or the deadline was reached.
transport The connection or TLS failed, or the server closed it.
unparseable The body is over 64 KiB, not a JSON object, or has no usable window.
usage credits on The answer shows usage credits on (extra_usage.is_enabled as true, or an extra_usage amplihack does not recognise), and neither five_hour nor seven_day has a valid utilization. When either window is usable, the read succeeds instead; see Usage credits on.
refresh busy The token needs a refresh, but the refresh lock is held or a swap is in progress.
refresh refused The checks before a refresh failed (see Token refresh).
refresh failed A token that is still valid needed a refresh (it is due within the refresh margin, or the endpoint answered 401) and the file has no usable refresh token; or the refresh request did not reach the token server (a DNS lookup that failed or ran out of time, or a failed connection or TLS handshake), or the server turned it away with a 3xx or 4xx status. When a refresh request was sent, the old refresh token is still on file.
refresh not saved The refresh request may have reached the token server, but its new login was not written: the answer was a 5xx or a 2xx other than 200, the answer did not arrive before the deadline, the connection failed after the request was sent, a 200 answer was not usable, or the write failed.

Except under AMPLIHACK_PROFILE_USAGE_PROBE=direct, a failed direct read moves on to the fallback, unless its reason means the profile has no login to use; see Logins with no token. The table marks the row (fallback) and the JSON gives source fallback; the reason is printed only with --raw, as one line to stderr for that row:

note: profile "spare": direct read gave http 5xx; using claude

Without --raw, nothing is printed for it, so an endpoint that fails for every profile does not add a line per profile to each run. The rotator never prints this line, to its log or to rotate.err. To see why a login fell back, run amplihack profile usage --raw <name>.

usage credits on leads to a /usage text probe instead of get_usage. Under direct, the row's state is error and its reason is direct read: <reason>, for example direct read: http 5xx. An overflow profile under direct is not read at all and reads error with direct read: overflow needs /usage, because it can only be read with /usage.

Logins with no token

Some direct-read reasons mean the profile has no login that claude could use either. For these, the direct read's result is final: amplihack does not look for claude or start it, and the row is ready as soon as the credentials file has been checked. This holds in the default order and under AMPLIHACK_PROFILE_USAGE_PROBE=direct; auto and text do no direct read and are unchanged.

Reason Final when
no oauth token Always, on Unix. The file is {}, or its claudeAiOauth has no accessToken or an empty one.
no refresh token Always, on Unix. The token has expired and there is nothing to refresh it with; claude would fail the same way.
no credentials file On Linux only, and only when the directory read is a real directory (checked with lstat, so not a symlink). A symlinked directory, and the live login when $HOME is not set, still go to the fallback.

Every other reason still goes to the fallback, including credentials refused (the file exists but is a symlink, has loose permissions or could not be read: a login may be there), token expired (the token has expired but has a refresh token, and claude can refresh it), refresh refused, refresh failed, refresh busy, refresh not saved, unreadable credentials (the file did not parse or held a token the read rejects: a statement about this read, not about the login), timeout, transport, unparseable, usage credits on and every http status: these can be passing conditions, or ones claude can still get past. Only the reason is used to decide; the token is never read again or shown. Checking for a missing file reads only the directory's own metadata; nothing inside it is opened or listed.

On macOS, Claude Code keeps its login in the Keychain, so a profile with no .credentials.json may still be signed in. There, no credentials file goes to the fallback as before, except under AMPLIHACK_PROFILE_USAGE_PROBE=direct, where the row reads error. On platforms other than Unix every failed direct read goes to the fallback, again except under AMPLIHACK_PROFILE_USAGE_PROBE=direct, where the row reads error.

A credentials file that is corrupt, in a format this read does not recognise, or that claude is rewriting at the moment it is read, gives unreadable credentials, not no oauth token. It goes to the fallback, and the rotator logs warning: rotate: probe of <name> failed for it when the probe fails, and holds the move onto overflow, as for any failed probe.

The decision uses only the profile's own credentials file. A login that works only through ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN or CLAUDE_CODE_OAUTH_TOKEN in the environment, with no token in the profile's file, reads not signed in as well; claude is not started to try that credential. With any of these set, profile usage already warns on stderr that the readings may be that credential's; see Refreshing auto-switch readings. The row is read again on every run, so it changes as soon as the profile has a login.

The row is:

  • state not_logged_in, source direct, spend unknown, and no raw output;
  • in the bar view, not signed in (<reason>) in place of the bars, for example not signed in (no oauth token); the marks column after STATE does not repeat it and shows only the row's other marks, such as * and spend:unknown, with no (fallback) mark;
  • with --table, not signed in (<reason>) in the MARKS cell, after any other marks (* not signed in (no oauth token)), - in every percentage and reset column, and no (fallback) mark;
  • sorted with the other not_logged_in rows, after every row with a reading and before every timeout, unparsed and error row;
  • "state": "not_logged_in", "source": "direct" and "error": null in the JSON and in the rows of Summary JSON, as for a not_logged_in row that claude reported. The row is not an error row, so the reason is not in the JSON. No key is added, and the set of states is unchanged.

No warning: line goes to stderr for such a row: the reason is already in the row, and a root with many unused profiles would otherwise print one identical line for each. With --raw the row prints no note: line and no (direct: no claude output) line. The fix is the same as for any not_logged_in row: amplihack profile login <name>.

A not_logged_in row that claude itself reported, in the fallback or under auto or text, is shown as before, with the (fallback) mark.

The rotator uses the same reads, so it also starts no claude for a login with no token. It treats the row as it treats any not_logged_in result: never a target, and <name>:failed in the cycle line. Like any not_logged_in result, and unlike a probe that timed out, it is not unknown, so it does not hold the move onto overflow profiles. It writes no warning: rotate: probe of <name> failed line for it, to stderr or to rotate.err, so an unused profile does not add a line to every cycle. The verdict is read-only: no login is written, refreshed, moved or removed because of it.

Usage credits on

A direct answer shows usage credits on when its extra_usage is anything other than absent, null or an object with "is_enabled": false. An is_enabled of true, an object with no is_enabled, an is_enabled of "false" or 0, and an extra_usage that is not an object all count as on. A profile does not need to be marked as overflow for this.

When credits are on and either window in the answer is usable, the direct answer gives the row as for any other account:

  • session, week_all, session_limit and state come from five_hour and seven_day;
  • source is direct, and the row has no (fallback) mark;
  • the ordering uses that state and those windows.

Only /usage shows a used-up spend limit. Without --spend, no claude is started for such a row and its spend status is not_probed. With --spend, in the default reading order, profile usage runs a spend probe for each such row. Its result goes only to the row's spend status. It never changes the row's state, windows, source or error, so a row can be ok with spend limit_reached.

Mode Credits-on account with a usable window
unset (default) Direct windows; spend not_probed. With --spend, then a spend probe.
direct Direct windows. No spend probe and no claude, even with --spend; spend not_probed.
auto, text No direct read. The fallback reads the row, and its spend status follows from how it was read; see Spend status.
Marked as overflow, any mode Unchanged: /usage only, or under direct the error direct read: overflow needs /usage.

When neither window is usable, the direct read fails with usage credits on and the row goes to the fallback, as described under Direct read failures.

Spend probe

Why it is opt-in. The point of reading credits-on accounts directly (issue #1856) is that the session and weekly figures no longer wait on claude /usage, which was reported to take 10 to 20 seconds per profile on a loaded host; one probe has taken 71.5 seconds at load 194 (see Probe deadline). A spend probe is that same /usage run. Started on every run, it would either hold the table up for that long or, under a short deadline, be killed before it answered on the hosts that need it most, starting and killing claude processes for a column that read unknown. So the default run starts none, and --spend asks for them when the spend limit is what you want to know.

What --spend runs. One claude -p /usage in the profile's directory for each direct row whose account has usage credits on, with the same command line and environment as the fallback's text attempt, so no token is passed to it. Spend probes start only after every passive and direct read has finished, at most the claude bound run at once, and each runs under the same probe deadline as a fallback: 120 seconds by default, set by AMPLIHACK_PROFILE_USAGE_TIMEOUT_SECS. A probe still running at its deadline has its process group killed, and its row shows spend unknown. No claude started for a spend probe outlives the command.

The spend probe's output is parsed for the spend status and then dropped. It is not shown by --raw: the row's raw block stays (direct: no claude output).

Notes with --raw. With --raw, each such row prints two note: lines to stderr:

note: profile "example-org": direct read gave usage credits on; windows direct, spend from claude
note: profile "example-org": extra_usage: object; keys: currency, is_enabled, monthly_limit, org_id, used_credits; is_enabled: bool true

The first line ends in one of three ways:

Ending When Spend
windows direct, spend from claude The spend probe finished and its output gave a usage reading. ok or limit_reached
windows direct, spend probe failed --spend asked for a spend probe, and it was killed at the probe deadline, could not run (including claude not found), or gave output that parsed as not_logged_in or unparsed. unknown
windows direct, spend not probed No spend probe was asked for: the run had no --spend, or AMPLIHACK_PROFILE_USAGE_PROBE is direct. not_probed

The second line shows the shape of extra_usage, so you can see why amplihack counts the account as having credits on. It never shows a token, an account or organisation identifier, an e-mail address, a currency or an amount. It is built as follows.

  • Type. extra_usage: object for an object. Any other value shows only its type, extra_usage: string, extra_usage: number or extra_usage: array, except a bool, which also shows its value: extra_usage: bool false. Only an object is followed by keys.
  • Keys. keys: and the object's top-level key names, separated by ,, in byte order. For an object with no keys, keys: none.
  • At most 32 keys are listed. More are counted as (+N more) after the 32nd.
  • Every character other than A to Z, a to z, 0 to 9, _, . and - is shown as ?. This covers spaces, punctuation, control and formatting characters, and letters outside ASCII, so a key name cannot add a field to the line or reorder it on the terminal.
  • A key longer than 64 characters is cut to 63 and followed by ….
  • An empty key is shown as "".
  • is_enabled. is_enabled: and one of the forms below. The value is printed only when it is one of a fixed set, and then the fixed text is printed, not the bytes received.
Value of is_enabled Shown as
Absent missing
null null
true or false bool true, bool false
A string equal, ignoring ASCII case, to true, false, on, off, yes, no, enabled, disabled, 0 or 1 string "<word>", in lower case, for example string "false"
Any other string string (<n> chars), its length in characters
The number 0 or 1, as an integer or as a float exactly equal to it (0.0, 1.0) number 0, number 1
Any other number number
An object or array object, array
  • Other flags. Each other member among the 32 listed keys whose value is a bool or null is added, in key order, as ; <key>: bool <value> or ; <key>: null, with the key shown as in the key list. Members holding a string, a number, an object or an array are shown by key name only. Nested objects and arrays are not looked into.

Two more examples:

note: profile "spare2": extra_usage: object; keys: is_enabled; is_enabled: string "false"
note: profile "team2": extra_usage: object; keys: limit_reached, overage; is_enabled: missing; limit_reached: bool false; overage: null

The key names are sent by Anthropic's server and printed after the replacement and cut above; a key name could itself look like an identifier. Without --raw, nothing about the shape is printed. The shape is never in --json, usage.json, the rotate log or rotate.err, and the rotator neither runs spend probes nor prints these lines.

Token refresh

A refresh is tried when expiresAt is no more than 60 seconds away, or when the first GET returns 401. There is at most one refresh per profile per read. It is tried only for a profile read in its own directory, and never for:

  • ~/.claude, for the live profile;
  • a profile whose login is lent to another directory, or whose directory hosts another profile's login;
  • a profile in the auto-switch exclude list. Such a profile is never probed, so it never reaches this step; see Excluded profiles. The same holds for the login in ~/.claude when local files show that it belongs to an excluded profile; see Local proof of an excluded live login.

In the first two cases a session may be using the login, and claude refreshes it itself, so the row falls back with token expired or http 401. An expired token with no refresh token is the exception: it gives no refresh token in every directory, and the row is not signed in. The one exception is outside the usage read: a rotate cycle refreshes the login in ~/.claude once, by these steps, when its token has already expired, so that its identity can be read (see An expired live login).

The refresh runs as follows:

  1. Take Claude's own refresh lock, <dir>/.oauth_refresh.lock (a directory made with mkdir), in the directory that holds the credentials file. If it is held, an auto-switch or rotate journal.json exists, or the rotator is stopping, nothing is refreshed and the reason is refresh busy. A lock held by someone else is never broken.
  2. Under the lock, read the file again. If accessToken differs from the token the GET was sent with, claude has refreshed it already: the new token is used and no refresh request is sent. Only accessToken is compared; a refresh always replaces it, and a changed refreshToken alone does not give a token to send.
  3. Check that the directory passes the login directory rule, that the file can be replaced safely, and that a private temporary file can be created beside it. If any check fails, the reason is refresh refused and no request is sent.
  4. If less than 3 seconds of the deadline are left, stop: no request is sent, nothing is changed and the reason is timeout (see Timing above). Otherwise send POST to the token URL with a JSON body holding grant_type (refresh_token), refresh_token and client_id (Claude Code's public client id).
  5. On a 200 with a usable answer, set accessToken, expiresAt (now plus expires_in seconds, in milliseconds) and, only when one is returned, refreshToken. Every other field of the file is kept as it was. The new token must pass the same check as a stored one, and expires_in must be a whole number from 1 to 31536000.
  6. Write the file through the temporary file (mode 0600, synced, renamed over the old file, and the directory synced), release the lock, and send the GET once more with the new token.

The file is never touched unless the write in step 6 succeeds. The POST ends at the read's deadline like every other request, so the 3-second floor in step 4 makes an unanswered refresh less likely but cannot rule it out. The token server may retire the old refresh token as soon as it handles the request, so when the request failed before it could reach the server, or the server turned it away with a 3xx or 4xx status, the reason is refresh failed; in every other case the reason is refresh not saved. Those cases are a 5xx answer (a 502, 504, 520 or 524 from a proxy in front of the token server can follow a request the server received and handled), a 2xx other than 200, no answer before the deadline, a connection lost after the request was sent, a 200 that cannot be used, and a failed write. The old refresh token may no longer work, so one line goes to stderr in every mode, with or without --raw (rotate.err for a background rotator):

warning: profile "spare": token refresh may not have been saved; run claude /login for this profile

The row then falls back as usual, or reads error with direct read: refresh not saved under AMPLIHACK_PROFILE_USAGE_PROBE=direct.

The lock is held only for steps 2 to 6. If amplihack is killed with SIGKILL while it holds the lock, the lock stays behind and claude waits on it. Remove it with rmdir <dir>/.oauth_refresh.lock when no amplihack or claude process is running for that profile.

Reading source
Source Meaning
passive A fresh stored reading. Nothing was asked.
direct The OAuth usage endpoint answered, or the direct read found no login to use and the row ended there.
fallback claude gave the row: the direct read failed (including usage credits on with no usable window), the profile is marked as overflow, or AMPLIHACK_PROFILE_USAGE_PROBE is auto or text. A spend probe never makes a row fallback.

The table shows (fallback) among a fallback row's marks. The JSON has the source key. A row that failed on every step keeps the source of its last attempt; a row that was never probed has source null.

Fallback probe

For a fallback, amplihack runs the claude binary directly, as login does (the binary selection is ignored, and AMPLIHACK_CLAUDE_BINARY_PATH is honoured). A fallback makes at most two attempts, one after the other, within one deadline of its own:

  1. Usage request. claude is started as
claude -p --input-format stream-json --output-format stream-json --verbose --no-session-persistence

and amplihack writes exactly one line to its stdin, then closes it:

{"type":"control_request","request_id":"amplihack-usage","request":{"subtype":"get_usage","skip_behaviors":true}}

claude answers with its session and weekly figures as JSON. It does not appear to scan the session transcripts to answer, or to make a model call. 2. /usage text. Only when the usage request gave no accepted answer, and the deadline has not passed, claude is started again as

claude -p /usage --no-session-persistence

with stdin from /dev/null, and its text is read.

Both command lines end with --no-session-persistence, so claude writes no session log for the probe. On Linux, each one is also run inside the probe sandbox, which hides the shared projects folder from the probe.

Profiles marked as overflow skip the first attempt: they are always probed with /usage only, whatever the method, because only /usage reports a used-up spend limit. Under text, every profile skips it.

Both children get CLAUDE_CONFIG_DIR=<profile dir> on their own Command; the environment of amplihack itself is never changed. The one exception is a profile whose login is live in ~/.claude: its children have CLAUDE_CONFIG_DIR removed instead, so claude reads ~/.claude and ~/.claude.json. It is never set to ~/.claude: when CLAUDE_CONFIG_DIR is set, claude reads .claude.json from inside that directory (~/.claude/.claude.json), not the ~/.claude.json the default login uses, so it would report the wrong account or none. Removing the variable is exactly what "use the default directory" means. Those children still get AMPLIHACK_CLAUDE_PROFILE=<name>, like every other probe. There is no shell, and no arguments other than the ones above are passed; the probe sandbox only puts bwrap and its own arguments in front of them. The profile directory is checked again just before each spawn, as for every launch. A refused directory gives error (profile directory refused), and no further attempt is made.

For neither fallback attempt does amplihack create, copy, link, move or write anything in the profile directory, and the fallback never opens or reads a login file. claude reaches the login in place, as it does for any claude run with that CLAUDE_CONFIG_DIR, and may update its own files there, such as .claude.json, as any claude run does.

  • At most the direct-read bound of profiles are read at a time. A row that falls back waits for a free claude slot, and at most the claude bound of claude processes run at a time, however many reads are running. With auto or text, every row starts claude, so the claude bound is the only one.
  • The fallback's deadline, 120 seconds by default, runs from its first spawn and covers both attempts. The /usage attempt gets only the time left; when none is left, the state is timeout. When the deadline passes, the running child is killed. Output from a /usage attempt that timed out is never parsed.
  • A usage request still running at the deadline without an accepted answer gives timeout, and /usage is not tried.
  • After an accepted answer, amplihack waits for claude to exit rather than kill it, so that claude can finish writing its own files. A claude that answers but does not exit keeps its place in the parallelism bound until the deadline. It is then killed and its answer is used: the state comes from the answer, not timeout.
  • On Unix each child runs in its own process group. When an attempt ends, whether by the deadline or a normal exit, the whole group is killed with SIGKILL, so processes claude started (MCP servers, for example) do not outlive it. A process that left the group itself is not tracked. On other platforms only the child is killed. A kill at the deadline can interrupt a write claude is making to its own files, such as .claude.json.
  • stdout and stderr are each read up to 64 KiB per attempt. Anything after that is dropped and the rest is still parsed; a usage request answer cut off by the limit is not accepted.
  • Neither attempt appears to use quota: the usage request does not appear to make a model call, and an exhausted session still answers /usage without its session percentage changing. This is claude's behaviour, not something amplihack controls. claude contacts Anthropic to answer; in the fallback, amplihack itself makes no network calls.

Without the probe sandbox, the /usage attempt makes claude read every session transcript reachable from the profile's projects directory. With large transcripts that is over half a minute of CPU time for one probe: one probe was measured at 71.5 seconds on a 72-CPU host at a load average of 194, and another opened 10,371 session logs in 47.5 seconds. On 10 November 2026, on the same host at a load average of about 60, with Claude Code 2.1.322 and 9,084 transcripts in the shared folder, claude -p /usage --no-session-persistence run directly opened 8,918 .jsonl files and took 68 seconds. Through amplihack profile usage with the sandbox, the same probe opened 3 .jsonl files, none of them under projects, and took 4.5 seconds. In the default mode, where that login's answer to the usage request was not used and the probe went on to /usage, both attempts together took 7.5 seconds. Neither run created a file in the shared folder, while the same probe from a build without this change wrote one session log there. The usage request opened 5 paths under projects with or without the sandbox, so it does not make that scan, though it still pays for claude starting up. This cost is why the direct read comes first. The deadline and the claude bound are still sized for the /usage attempt on a loaded host, because it remains the fallback and the only method that can read overflow profiles. profile usage and the rotator use the same settings: method, deadline, parallelism, the passive age and the endpoint overrides.

Probe sandbox

Every claude that profile usage and the rotator start to read usage gets three protections: both fallback attempts, the spend probe and the rotator's held-cycle spend-limit check.

  1. No session log. The probe's arguments end with --no-session-persistence, so claude writes no transcript for it. Older versions wrote one log of about 5 KB per probe into the shared projects folder; see Prune probe logs to remove them.
  2. No shared history. On Linux, when bwrap (bubblewrap) is usable, the probe runs in its own mount namespace with an empty tmpfs over the resolved projects folder:
bwrap --dev-bind / / --tmpfs <canonical projects> -- claude -p /usage --no-session-persistence

Inside, projects is empty, whether claude reaches it directly or through the profile's projects link, so /usage has no transcripts to read. The login files are seen in place. Nothing outside the probe changes: the profile's projects link is not repointed, the sandbox creates no folder on the host, and a session started on the same profile during the probe writes its transcript to the shared folder as before.

  1. No session folder. Even with --no-session-persistence, claude makes an empty session folder under its per-user temporary root and does not remove it. Each attempt therefore runs with CLAUDE_CODE_TMPDIR set to a new owner-only folder in the system temporary directory, named amplihack-probe- and a random suffix. amplihack removes that folder, and everything in it, once the attempt's process group has ended, whether it exited, failed or was stopped at the deadline. This applies with and without bwrap, on every system. Nothing else in the temporary root is read or removed. If the folder cannot be made, the probe runs without it; if it cannot be removed, the probe's result stands. Each case prints one warning: usage probe: line to stderr, without a path.

Which projects folder is hidden. The folder is <config dir>/projects, with every link resolved. The config dir is read from the probe's own command, not from amplihack's environment:

CLAUDE_CONFIG_DIR on the probe's command Config dir
Set to a value (a profile directory) That value
Removed (a login live in ~/.claude) $HOME/.claude
Not mentioned amplihack's CLAUDE_CONFIG_DIR if set, else $HOME/.claude

A profile's projects is a link to ~/.claude/projects, so the folder hidden is normally ~/.claude/projects itself. The probe runs without bwrap, with --no-session-persistence alone, when the folder does not exist, a link in its path is broken, or the resolved path is /, $HOME or the config dir itself.

When bwrap is used. The first probe that needs the sandbox looks for bwrap once for the life of the process:

  1. Each absolute directory on PATH is checked, in order, for a regular, executable file named bwrap. Empty and relative entries are skipped.
  2. That file is run once as bwrap --dev-bind / / -- true, with no shell and its output discarded.
  3. Exit status 0 means bwrap is usable, and its absolute path is kept for every later probe. A missing file, a failed start or any other exit status means it is not. AppArmor on Ubuntu 24.04, for example, can refuse unprivileged namespaces to an installed bwrap.

The answer is not checked again until the process ends, so the rotator checks once when it starts. There is no timeout and no retry on the check. On any system but Linux, bwrap is never looked for.

The note. When a probe runs without the sandbox, amplihack prints one line to stderr, at most once per process, naming the reason:

note: usage probes run claude with --no-session-persistence only: bwrap not found
note: usage probes run claude with --no-session-persistence only: bwrap refused
note: usage probes run claude with --no-session-persistence only: projects folder not resolved

bwrap refused means the check in step 2 failed. The note contains no path and no environment value. It goes to stderr, so stdout stays clean for --json and --summary-json; the rotator's copy goes to rotate.err.

What the sandbox is not. --dev-bind / / gives the probe the whole filesystem, read and write, as before. The sandbox hides one folder; it does not confine claude and is not a security boundary. bwrap runs with no extra privilege: the user id is unchanged.

Process handling. The command keeps the probe's environment changes (values set and values removed) and its working directory. bwrap is started in place of claude, so it leads the probe's process group, and the group kill at the end of each attempt ends bwrap, claude and what claude started. --die-with-parent and --new-session are not passed: the group kill already ends the probe, and the probe's stdio is pipes or /dev/null, never a terminal. If amplihack itself is killed with SIGKILL, the probe can outlive it, as a plain claude probe can.

Probe method

This section covers the get_usage request of the fallback probe. claude prints its answer to the usage request as one JSON line. Shown over several lines, with fields amplihack does not read left out, an answer looks like this:

{
  "type": "control_response",
  "response": {
    "subtype": "success",
    "request_id": "amplihack-usage",
    "response": {
      "rate_limits_available": true,
      "rate_limits": {
        "five_hour": { "utilization": 20.0, "resets_at": "2026-10-17T02:00:00Z" },
        "seven_day": { "utilization": 30.0, "resets_at": "2026-10-22T09:00:00Z" },
        "model_scoped": [
          { "display_name": "Fable", "utilization": 0.0, "resets_at": "2026-10-22T09:00:00Z" }
        ],
        "extra_usage": { "is_enabled": false }
      }
    }
  }
}

The answer is the first line of stdout that is a JSON object with "type": "control_response" and a response.request_id of "amplihack-usage". Lines before it, such as the system line claude prints when it starts, are skipped. Lines after it are ignored, even another line with the same request_id. The figures are in response.response, called the payload below; every field named in the rest of this section is inside it. An answer that failed has response.subtype "error" and a message in response.error; amplihack never parses that message or puts it in a message of its own.

The answer is accepted only when all of these hold:

  • response.subtype is "success";
  • the payload, response.response, is an object;
  • rate_limits_available is the JSON value true (not 1 or "true"), and rate_limits is an object;
  • extra_usage is absent, null, or an object whose is_enabled is the JSON value false, both at the top of the payload and at rate_limits.extra_usage;
  • rate_limits.five_hour.utilization or rate_limits.seven_day.utilization is a finite number from 0 to 1000000.

Claude Code reports whether the account has usage credits turned on at rate_limits.extra_usage.is_enabled. The top-level extra_usage is checked as well, in case a later version moves it. The rule is strict: an answer with no extra_usage, or a null one, is accepted, but an extra_usage of true, an object with no is_enabled, or an is_enabled of "false" or 0 is not.

An accepted answer becomes the row like this:

Payload field Row field
rate_limits.five_hour session, label session
rate_limits.seven_day week_all, label all models
each rate_limits.model_scoped entry with a valid display_name and a valid utilization one week_models entry, labelled with its display_name, in the order given; any other entry is skipped
utilization used_percentage, as read; -0 reads as 0
resets_at, a valid string resets_text, the string as received; resets_at, that time in Unix epoch seconds

A display_name or resets_at string is valid only when it is 1 to 64 characters long and has no control characters (C0, DEL or C1, so no escape sequences) and no bidirectional override or isolate characters (U+202A to U+202E, U+2066 to U+2069). This stops an answer from putting terminal escapes or reordered text into the table or the JSON. Letters of any script are kept, as are the directional marks U+200E, U+200F and U+061C.

A window whose utilization is missing, null, not a number, negative or above 1000000 is left out (null), never read as 0. For a window that is kept:

  • When the window's resets_at is missing, null, not a string (a number of epoch seconds, for example) or not a valid string, the row's resets_text and resets_at are both null.
  • When it is a valid string, resets_text is that string. resets_at is null when the string is not an RFC 3339 time, or when the time is more than 8 days from now: no session or weekly window resets that far ahead, so such a time is treated as unknown rather than trusted.

A five_hour window at 0 whose resets_at key is absent or null, or no five_hour at all, means the reading has no session limit when seven_day was read: session is then null and session_limit is false. A five_hour above 0 with no reset keeps its window and the session limit.

This page shows such resets as 2026-10-16T23:50:00Z. That is an example of the form: whether claude sends fractional seconds, Z or an offset such as +00:00 is up to claude, and resets_text keeps what it sent. The other windows in the payload (seven_day_opus, seven_day_sonnet, seven_day_oauth_apps) are not used.

The state of an accepted answer is session_exhausted when the session is at 100% or more and a session limit applies, else weekly_exhausted when the all-models week is, else ok. The usage request never gives spend_limit, not_logged_in or unparsed: those states come only from the /usage text.

claude can answer from figures it stored earlier, without saying how old they are. /usage shows the same stored figures, so amplihack treats both alike and adds no age check.

Any other outcome of the usage request, apart from reaching the deadline, falls back to /usage in the time left:

Usage request outcome Why it falls back
response.subtype is not success, such as an error with Unsupported control request subtype from a claude that does not know get_usage The installed claude cannot answer it.
No line of stdout is a control_response for amplihack-usage: none was printed, the output is not JSON, or the answer was cut off at 64 KiB The answer is missing.
response.response is missing or not an object The answer has no payload.
rate_limits_available is not true, or rate_limits is not an object (null, for example) claude has no figures, for example because the profile is not logged in. /usage can then report not_logged_in.
Neither the session nor the all-models week has a valid utilization Nothing usable was read.
extra_usage, at the top of the payload or at rate_limits.extra_usage, is not absent, null or an object with "is_enabled": false; for example {"is_enabled": true} The account has usage credits turned on, or the answer reports extra_usage in a form amplihack does not recognise. amplihack does not read the payload's spend fields (Claude Code 2.1.314 sends rate_limits.extra_usage.spend_limit_reached and rate_limits.spend), because they can disagree with /usage; /usage shows a used-up spend limit as spend_limit.
claude could not be started, written to, read or waited for The attempt failed.

Profiles marked as overflow are probed with /usage only. They never get a direct read or the usage request, whatever the mode, because the spend-limit block depends on /usage reporting spend_limit. Under direct, which starts no claude for a reading, an overflow profile is therefore not probed and reads error with direct read: overflow needs /usage, so the rotator does not move onto it. The rotator's held-cycle spend-limit check of a pinned live overflow profile is separate from these readings and still runs claude -p /usage under direct. The marks are read from <root>/.auto-switch before probing; a missing or corrupt .auto-switch marks no profile. A profile that is not marked but whose account has usage credits turned on is read directly, and its spend status is not_probed unless --spend asks for a spend probe, which runs under the normal per-probe timeout (--timeout-secs, 120 s by default); when the direct read failed instead, its usage request answer is not accepted, and it falls back to /usage.

get_usage is part of an interface that Claude Code marks as experimental, and it may change or be removed. A change that makes its answer unrecognisable only makes every fallback go on to /usage.

Setting Values Default
AMPLIHACK_PROFILE_USAGE_PROBE direct, auto, text unset: passive, direct, then claude
Value Behaviour
unset The reading order: passive, direct, then the fallback. With --spend, also a spend probe for each direct row whose account has usage credits on.
direct Passive, then direct only. A failed direct read gives state error, and no claude is started for a reading or a spend probe; an account with usage credits on gives its direct windows with spend not_probed, even under --spend. Overflow profiles read error with direct read: overflow needs /usage. The rotator's held-cycle spend-limit check still starts claude.
auto The fallback probe only, as before the direct read existed: the usage request, then /usage. No passive or direct reads.
text claude -p /usage only, so every probe pays the transcript scan. No passive or direct reads.

The rotator's freshness re-reads follow the same setting, with passive readings off: under auto or text a re-read is a claude probe in that mode, never a direct read.

To go back to the behaviour before direct reads, set AMPLIHACK_PROFILE_USAGE_PROBE=auto. Values are matched exactly: case, leading and trailing spaces count. An empty variable counts as unset. Any other value prints one warning to stderr, showing the value escaped and cut to 32 characters, then uses the default order:

warning: ignored AMPLIHACK_PROFILE_USAGE_PROBE "Text" (use direct, auto or text); using the default order

There is no command-line flag for it. Whether a claude supports the usage request is not remembered: every fallback tries it again.

To check that both methods give the same figures for your logins, see Compare the two probe methods.

Probe deadline

Setting Values Default
--timeout-secs <n> (hidden flag, profile usage only) 1 to 600 none
AMPLIHACK_PROFILE_USAGE_TIMEOUT_SECS 1 to 600 120

The deadline bounds each read of one profile. A direct read, any refresh included, must finish within it, and its connect and read timeouts are each min(10, deadline - 1) seconds. A fallback that follows gets a deadline of its own, which covers the usage request and, when it falls back, the /usage attempt in the time left. The default of 120 seconds allows about 1.7 times the 71.5 seconds one /usage probe was measured to take on a 72-CPU host at a load average of 194.

The flag wins over the variable. A flag value out of range is a usage error (exit status 2). An empty variable counts as unset. A variable that is not a number from 1 to 600 prints one warning to stderr, showing the value escaped and cut to 32 characters, then uses 120:

warning: ignored AMPLIHACK_PROFILE_USAGE_TIMEOUT_SECS "soon" (use 1 to 600); using 120

The rotator has no flag; see Probe settings in the rotator.

Probe parallelism

Direct reads and claude fallbacks have separate bounds, because a direct read is one small HTTP request while a fallback is a claude process.

Setting Values Default Bounds
AMPLIHACK_PROFILE_USAGE_DIRECT_PARALLEL 1 to 16 8 Passive and direct reads run at once.
AMPLIHACK_PROFILE_USAGE_PARALLEL 1 to 16 the derived bound claude fallbacks run at once.

For the direct-read bound, an empty variable counts as unset, and any other value prints one warning to stderr, showing the value escaped and cut to 32 characters, then uses 8:

warning: ignored AMPLIHACK_PROFILE_USAGE_DIRECT_PARALLEL "lots" (use 1 to 16); using 8

Unless AMPLIHACK_PROFILE_USAGE_PARALLEL is set, the number of claude fallbacks run at once is derived from the host:

cpus  = number of CPUs available to amplihack
load1 = first field of /proc/loadavg (the one-minute load average)
free  = max(cpus - load1, 0)
bound = clamp(floor(free / 8), 2, 4)

Where /proc/loadavg is missing or cannot be read (any platform other than Linux, for example), free is cpus. A load value that is empty, negative or not a finite number counts as missing.

Host free Bound
72 CPUs, idle 72 4
72 CPUs, load 38 34 4
72 CPUs, load 194 0 2
8 CPUs, idle 8 2

The floor is 2, not 1. Under load 194 a bound of 1 would make a cycle over 14 profiles take about 16 minutes. Two probes add little to a host already that busy, and they halve that time. The ceiling of 4 keeps an idle host from starting a burst of transcript scans at once.

For AMPLIHACK_PROFILE_USAGE_PARALLEL, a valid value replaces the derived bound. An empty variable counts as unset, as it does for the deadline. Any other value, including 0 and one that is not valid UTF-8, prints one warning to stderr, showing the value escaped and cut to 32 characters, then uses the derived bound:

warning: ignored AMPLIHACK_PROFILE_USAGE_PARALLEL "lots" (use 1 to 16); using 2

The number after using is the derived bound from the formula above, before the cap described next, so it can be larger than the number of profiles.

Whichever value applies is then capped at the number of profiles that need a fallback, and is never below 1. The direct-read bound is likewise capped at the number of profiles. There is no command-line flag for either. The claude bound counts probes, not attempts: a profile's /usage attempt starts only after its usage request has ended, so each probe runs at most one claude at a time.

Probe settings in the rotator

The rotator uses the same reading order, method, deadline, parallelism, passive age and endpoint overrides as profile usage, from the same variables. It has no flags for them.

  • When they are read. At the start of every cycle, from the rotator's own environment. That environment is fixed when the rotator starts: a background rotator inherits it from the shell that ran amplihack profile rotate start, or from the launch that autostarted it. To change a setting, set the variable in a shell, then run amplihack profile rotate stop and amplihack profile rotate start from that shell. The variables the background rotator removes are listed under Rotate daemon; the AMPLIHACK_PROFILE_USAGE_* variables are not among them.
  • Warnings. An invalid value prints its warning once per cycle (to rotate.err for a background rotator), and the default is used.
  • The live probe counts against the bound. This applies to both bounds: each is capped for the candidates plus one. When the live login needs a claude fallback, the claude bound is derived for the candidates plus one. The live probe and the candidate probes share one pool of that size: the live probe starts first, and whenever a probe ends, the live one included, the next candidate takes its place. With a bound of 1, the live probe runs first and the candidates follow one at a time. Either way a cycle never runs more probes at once than the bound. An API-key live login is not probed, so then the bound is derived for the candidates alone.
  • No spend probe. The rotator does not run spend probes. A profile that is not marked as overflow and whose account has usage credits on is read directly and judged by its windows, with spend not_probed. Before, such a profile was read with /usage, so a used-up spend limit made it spend_limit; the rotator no longer sees that. Profiles marked as overflow are still read with /usage, so the spend-limit block works as before, and the held-cycle spend-limit check of a pinned live overflow profile is unchanged.
  • Load. The bound is derived again on every cycle, so it follows the load as it changes.

  • The claude binary. It is looked up only when a cycle first needs a fallback. A claude that cannot be found makes only those rows fail.

  • Freshness re-reads. A re-read of a stale swap target uses the same method, with passive readings off. Under auto or text it is a claude probe, never a direct read.
Reads that outlast a cycle

A cycle does not wait for every read to finish. The reads run on their own threads, and the cycle waits only until --interval minus 2 seconds after the cycle started, and at least 1 second. Then:

  • A login whose read has not finished reads as unknown. The cycle line shows it as <name>:unknown, still running. For the decision it is unknown: it is a target only on a last good reading that qualifies, it blocks a move onto overflow as timeout does, and for the live login it counts towards failed live probes.
  • The read keeps running. The next cycle collects its result and uses it, and starts no second read for that login while one is outstanding. Only logins with no result and no read in flight get a new read. A result collected this way has no reading time, so if the decision chooses that login as a swap target it is read again directly before the swap.
  • A read that has been working for 2 × deadline + 5 seconds (245 seconds by default) is dropped, and the next cycle starts a new one. Its thread ends on its own HTTP or claude timeout. A read is working from when it leaves the queue of the parallelism bound, and its clock starts again when a claude fallback takes its slot; time spent queued or waiting for a slot does not count, and a read in either is never dropped. The direct read, any refresh included, takes at most one deadline, and the fallback one more, so a read still working past this limit has hung.

--dry-run waits for every read in full. When the rotator stops, it waits up to the deadline plus 1 second for any token refresh in progress, so that it does not leave Claude's refresh lock behind. Once the rotator is stopping, no new refresh starts: a read that needs one gives refresh busy and takes no lock. Reads still running after that are abandoned, and reads not yet started are not run.

Cycles never overlap: the rotator starts the next cycle only after the previous one ends, when a wake arrives or --interval seconds have passed, whichever is first.

Rotate wake

rotate watch does not poll. After a cycle it blocks until the first of these, then runs a cycle:

Wake When Log line
Limit event The blocks recorded in ledger.json in the state directory differ from those the last cycle began with. A step or hook that meets a limit records a block there, so the rotator acts within one cycle of the record. profile overflow clear removing a block counts too wake: ledger changed
Reset The earliest until among the overflow_blocked and platform block records falls due, so the login comes back when its reset passes wake: reset due
Interval --interval seconds have passed with neither of the above wake: interval
Signal SIGTERM or SIGINT ends the wait at once, so rotate stop returns inside its 10 seconds however long the wait was; both signals are handled as in Rotate signals none; the rotator stops

These log lines are fixed text, defined once in the rotator's source. wake: interval is written only when the previous wake had a different reason, as the idle latch does, so a quiet rotator does not write one line per tick.

The wait ends at the earlier of now + --interval and the earliest future reset. A reset beyond the interval never lengthens a wait, and one already past does not count: the next cycle removes it. The exception is a reset that fell due while the previous cycle ran: that cycle still held the login out, so the next one runs at once, logged as wake: reset due. The cycle's own save removes such a block from the ledger, so the rotator judges this from the blocks as they stood when that cycle began, not from the ledger it saved. A clock jump cannot lengthen a wait either. With --interval 1 the rotator still ticks every second.

A ledger write wakes the rotator only when it changes the blocks in force: the overflow_blocked records and the platform block that have not reached their until. On each change to the file the rotator loads the ledger and compares those blocks with the ones the last cycle began with. Who wrote the file does not matter, and nor do its bytes. The rotator's own saves of its cycle records keep the blocks as they were, so they do not wake it, and it keeps no record of what it wrote. A block removed by a prune has reached its until, so it is in force in neither and is not a change. A ledger that cannot be loaded runs a cycle, which reports why; no writer saves over a ledger it cannot load, so this costs one cycle.

A writer records a block under the rotate lock, and a cycle holds that lock only from its check before a swap to its last save, not while it measures. A block recorded while a cycle measures is therefore kept by that cycle's own save, although the cycle decided without it. Because the rotator compares with the blocks the cycle began with, not with the blocks it saved, the next cycle runs at once, logged as wake: ledger changed. A block the cycle recorded itself differs too, and costs one extra cycle. A writer that does not take the lock can still lose its record to a cycle's save; the step and hook writers take it.

No timer coalesces a burst of records. The number of cycles events can cause is bounded by the blocks instead. Every writer keeps a block that is in force as it is: a step's record, the API-key block and the rotator's own spend block are each written once and never extended. A login therefore adds at most one block per reset window, and so starts at most one cycle when its block is recorded and one when the block falls due. Every block written while a cycle runs is taken by the one cycle after it. Twenty-five runs that meet one login's limit together cost one cycle: the first record adds the block, and the other twenty-four find it in force and write nothing.

If the ledger watch is lost or its queue overflows, the rotator rebuilds it, logs wake: watch rebuilt, and then loads the ledger and compares its blocks as for any other change, so a record that arrived while events were lost still runs a cycle. Where no watch can be made it logs wake: unavailable (<cause>), using --interval once, and where one stops working it logs wake: lost (<cause>), using --interval once. Either way it waits by interval as before, and neither ends the rotator. <cause> is fixed text:

<cause> Meaning
not supported here Not Linux: there is no inotify or pidfd
inotify watch limit reached fs.inotify.max_user_watches is used up
descriptor or inotify instance limit reached The process's descriptor limit or fs.inotify.max_user_instances is used up
permission denied, not found, already exists, disk full, I/O error Any other failure, by its kind

A paused rotator still wakes, takes the paused branch and logs through the same idle latch as before, so repeated wakes do not fill the log.

A cycle that follows a limit event or a reset reads less than an interval cycle. It reads the live login, and takes each other login's figures from the last reading this rotator took of it, while that reading can still stand for the login:

  • it was taken no more than --interval seconds ago, so the cycle never decides on figures older than an interval cycle would have used; and
  • every window it reports has a known reset that is still to come, so a login whose window has reset since, which is how a login comes back, is read again.

A login with no such reading is read, as in every cycle. A login skipped as no account is read in a cycle only for the token refresh the read can make, since its reading never enters a decision, so it is left to the next interval cycle. When the cycle took any figures from a kept reading, it writes wake: read <r> of <t> logins, the others from their last reading after its cycle line. <t> counts the live login, when it is probed, and every candidate; <r> counts the ones it read.

This is safe because a login's use within one window only rises until that window resets. While every window a kept reading reports is still open, the reading never shows less use than the login has now. A login it shows full is still full, and the cycle decides on it as it stands. A login it shows with room may have less room now, so the cycle does not swap to it on that figure alone: a kept reading has no reading time in the cycle that takes it, and the confirmation reads the chosen target again before the swap, logged as reread: <name> reading stale ...; fresh ..., and decides again on what that read finds. A target that has filled up is rejected and the decision is made again. An alternative waits for confirmation in a later cycle. The one target confirmation uses the existing probe deadline. When it says nothing about the login (an HTTP 429 or a timeout, for example), the confirmation fails closed: the kept target is rejected with a reject: line whatever room the live login has, and the cycle makes no swap. A kept reading is also never replaced by an older one, so a figure that a newer reading has overtaken cannot come back as the live reading. The check under the lock before a swap takes no reading, so a kept target that the confirmation has not read is made unknown there and is not swapped to.

Each login is therefore read for its figures at most once per --interval, however many events arrive, as well as once when a window it reported resets and once before it becomes the target. The live login is read in every cycle. A cycle after an interval wake reads every login, so a quiet rotator still reads each login once per --interval. The kept readings are held in the rotator's memory only: a rotator that starts reads every login in its first cycle, and the one-shot rotate and --dry-run read every login.

Kept readings and last good readings are separate. The rotator keeps only readings its own probes took, never a last good reading that stood in for a failed probe. A kept reading is not a probe of the cycle that takes it, so it has no label and the cycle never replaces it with a last good reading. Like a passive reading, a kept reading at most 300 seconds old is written to the usage history under the time of the cycle that took it. A later last good reading drawn from that point has the figures the login last showed, and its age may be understated by up to 300 seconds.

The rotator wakes on a block whoever records it, whatever reason the block carries. Today the writers of a block are the rotator itself, the API-key block and a step that meets a spend limit (#2893). The one function that records any usage, spend or credit limit for the login a step ran under belongs to #2911, and the limit-resume hook calls it under #2912.

What is read

This section covers the /usage attempt; an accepted usage request is read as in Probe method. These lines of the /usage stdout are read. Each one has a percentage and usually a reset time:

Current session: 100% used · resets Oct 16, 4:50pm (America/Los_Angeles)
Current week (all models): 68% used · resets Oct 22, 2am (America/Los_Angeles)
Current week (Fable): 0% used · resets Oct 22, 2am (America/Los_Angeles)

Claude leaves out the reset when no session window applies, for example Current session: 0% used. Such a line at 0% means the reading has no session limit when the all-models week was read. A session line above 0% with no reset is read as a session window with no known reset.

Line Field
Current session session
Current week (all models) week_all
Current week (<anything else>) one entry in week_models, in the order printed

The separator before resets may be ·, •, - or missing. Anything after used other than a reset clause makes the line unreadable. Extra spaces and decimal percentages (12.5%) are accepted. A line whose percentage is not a finite number, or is above 1,000,000, is ignored. Every other line is ignored. The parser never guesses a number: a value it cannot read is left out.

The reset text is kept exactly as Claude printed it (resets_text). amplihack also turns it into a time (resets_at, Unix epoch seconds) when it can:

Form Example Meaning
Month, day, time, zone Oct 22, 2am (America/Los_Angeles) The year that puts the time between one day before now and 366 days after now: this year, then next year, then last year.
Month, day, year, time, zone Jan 2, 2027, 9:30pm (UTC) That date.
Time, zone 4:50pm (America/Los_Angeles) The first time of day at or after 10 minutes ago in that zone: usually today, or tomorrow if that time has passed. Claude prints whole minutes, so a reset due within the current minute can print as a time a few seconds ago, just before midnight included.

Minutes are optional, am/pm may be in any case, and spacing is tolerant. The zone must be an IANA name; the host's own time zone is never used. If the zone is unknown, the time does not exist in that zone (a daylight-saving gap) or the text has another form, resets_at is null and only the text is shown. A time that occurs twice (the hour repeated when daylight saving ends) resolves to the earlier one.

No session limit

Claude sometimes reports the all-models week without a running five-hour session window. A reading then has no session limit: no active session window was reported, and the profile is judged on its all-models week alone. The report has session_limit set to false and session set to null.

The label describes the reading, not the plan. Claude also leaves out the session reset when a session-limited login has not started a session, so an idle Pro or Max login reads as having no session limit until a session starts. This does not change which login is chosen: the session is at 0%, which is not exhausted, and the next reading that has a reset restores the session window.

A /usage reading has no session limit when the all-models week line was read and either of these holds:

  • there is no Current session line;
  • the Current session line is at 0% and has no reset clause, for example Current session: 0% used.
Current week (all models): 47% used · resets Oct 22, 2am (America/Los_Angeles)
Current session: 0% used
Current week (all models): 47% used · resets Oct 22, 2am (America/Los_Angeles)

Both give state ok, session_limit false and session null. With the week at 100% or more the state is weekly_exhausted.

A plan with no session limit has nothing to count in the session percentage, so a value above 0% shows that a session window exists. The same line at 47% used keeps the session limit with state ok, and at 100% used gives session_exhausted, as before issue #1818. In both cases resets_text and resets_at are null.

The rule fails closed. A session limit still applies, and the session line is read as before, in each of these cases:

Case Example Why
The session line is above 0%, with or without a reset clause Current session: 100% used A non-zero percentage shows a session window. With no reset clause resets_text and resets_at are null.
The session line has a reset clause, even one whose time cannot be resolved Current session: 3% used · resets 3am (Etc/Unknown) A printed reset shows that a session window exists. resets_at is null and resets_text keeps the text.
A line contains Current session but does not have the form above, for example because of a prefix Current session: unavailable A change in Claude's wording must not make an exhausted login look usable.
No all-models week line was read Current session: 0% used alone Nothing else can rank the profile. The state follows the usual rules. A session line with no reset clause is still read: resets_text and resets_at are null, and the bar view shows - in S-RESET (SESSION RESETS in --table).
The row is spend_limit or any failed state session_limit is true on every row that is not ok or weekly_exhausted.

An accepted usage request has no session limit when rate_limits.seven_day was read and either rate_limits.five_hour is absent, or its utilization is 0 and its resets_at key is absent or null. A five_hour above 0 with no reset keeps the session window and the limit, and is session_exhausted at 100 or more. The check is on the raw key: a resets_at that is present but not a valid string, not an RFC 3339 time or more than 8 days ahead still means a session limit applies, even though the row's resets_at is then null. A five_hour whose utilization is unusable is left out as before and also keeps the limit.

rate_limits session_limit session
{"seven_day": {"utilization": 47.0, "resets_at": "2026-10-22T09:00:00Z"}} false null
{"five_hour": {"utilization": 0.0, "resets_at": null}, "seven_day": {…}} false null
{"five_hour": {"utilization": 0.0}, "seven_day": {…}} false null
{"five_hour": {"utilization": 100.0, "resets_at": null}, "seven_day": {…}} true the window, with both reset fields null
{"five_hour": {"utilization": 20.0, "resets_at": "2026-10-17T02:00:00Z"}, "seven_day": {…}} true the window
{"five_hour": {"utilization": 20.0, "resets_at": 1792202400}, "seven_day": {…}} true the window, with both reset fields null

A profile with no session limit is not exempt from limits: it is weekly_exhausted, and never chosen, once its all-models week reaches 100%, and the rotator and auto-switch apply their usual week thresholds to it. See Rotate decision rule and Candidate selection.

Known limitations:

  • An idle session-limited login at 0% is labelled no session limit, as described above, in profile usage and profile usage --json.
  • rotate status and auto-switch status read the stored auto-switch readings, which have no field for "a session limit applies but its window is unknown". They therefore print no session window, not no session limit: a stored reading with seven_day and no five_hour. That happens for a reading with no session limit, and also when:
  • a status-line input had no five_hour, or one that was rejected (no resets_at, an unusable percentage, or a reset outside the bounds in Readings);
  • a profile usage row that has a session limit had its session window rejected by the same bounds (for example no reset time), and the stored five_hour had already reset.

Ranking is the same in every case: a missing five_hour counts as 0%. These views can also be as old as the last recorded reading. - When profile usage records a reading with no session limit for a login whose stored auto-switch reading has a session window that has not reset, that window is kept until its reset passes. The new reading may come from figures claude stored earlier, and a live window contradicts it. The rotator and auto-switch therefore go on treating the login as it was (for example session-exhausted) for at most five hours. See Refreshing auto-switch readings.

Excluded profiles

A profile in the auto-switch exclude list is never probed or refreshed by profile usage. Such a login is often shared with another host. A token refresh from this host rotates the login's refresh token and signs the other host out, so the only safe action is none. Issue #2218 made this rule apply to every reader.

The list is read once per command from <root>/.auto-switch, the file the rotator reads, whether auto-switch is on or off. There is no second list and no other setting. A name in the list that is not a profile under the root is ignored, as before.

For an excluded profile, profile usage makes no usage request, no token request and no identity request, does not open its .credentials.json or API-key file, starts no claude, and runs no spend probe, even under --spend.

usage.json is updated by loading it, changing the entries for the profiles read and saving it again, so an entry for the excluded profile written before it was excluded stays in the file. profile usage neither shows, updates nor deletes that entry. No reader counts it as room: the capacity file writers, auto-switch candidate selection and the rotator apply the same exclude list, and the usage-limit wait never counts an excluded profile as a login that could take over.

The same holds for the usage history. Lines written before the profile was excluded, or before #2218, can still hold a reading for it. Those lines are neither removed nor filtered: the history is read as written. The figures leave the profile out instead. The capacity summary of profile usage is built from this run's rows, which never hold a reading for it, and the capacity line of rotate status leaves the profiles in the current exclude list out of usable now, login-weeks of N and unknown when it builds its figures.

With no names, the excluded profile is still listed, so that the table shows every profile under the root:

Output Excluded row
Bar view excluded (not probed) from WEEK to the end of S-RESET; STATE is excluded; no marks other than (live) after the name.
--table STATE is excluded, SESSION is excluded (not probed), every other usage cell is -, SPEND is n/a.
--json and --summary-json "state": "excluded". The keys source, account, session, week_all and error are present with the value null, week_models is [] and spend is "n/a". No e-mail, account name or cached figure appears anywhere in the row.
Capacity summary Not counted at all: neither in N nor on the unknown line.
Usage history and usage.json No new reading is written for it. An older usage.json entry is left as it is, and is ignored as above.

Excluded rows come after every other row; see Ordering. The command exits 0 when the only difference from a full run is the excluded rows.

The login in ~/.claude is not read either when local files show that it belongs to an excluded profile, by the rules under Local proof of an excluded live login. That profile's row is the excluded (not probed) row, marked (live) in the bar view and live in ~/.claude in --table, and its live_in is "~/.claude". No other row is marked live. A profile that is both live and excluded is always treated as excluded.

With names, each excluded name is refused on stderr, and the other names are probed, recorded and reported as usual:

amplihack profile usage work shared
shared: excluded (in auto-switch exclude list); not probed (amplihack profile auto-switch exclude)
PROFILE  WEEK             W-RESET      SESSION           S-RESET     STATE
work     ███░░░░░░░  30%  11-05 09:00  ██░░░░░░░░  20%   11-01 12:00 ok
shared   excluded (not probed)                                       excluded
...

The refused name is also shown as an excluded (not probed) row, as with no names. The command exits 1 once every other name has been probed, recorded and printed, so profile usage work shared reads work, refuses shared and exits 1. A script that wants only the readable profiles can name them, or run with no names. A name that is not a profile under the root is still refused as an unknown profile before anything is read, and that error takes precedence over the exclusion.

A profile that is both excluded and an API-key or overflow profile is shown as excluded. Neither kind is probed.

When <root>/.auto-switch is a private file of yours that parses but is invalid for its other settings (an unknown kind, say), its exclude list still applies, and the command prints once on stderr:

warning: auto-switch config invalid; exclude list applied, other settings ignored

When the file exists but cannot be read, does not parse, or is unsafe (owned by another user, or writable by group or others), the command cannot tell which profiles are excluded, so it treats every profile as excluded: none is probed or refreshed. It prints once on stderr:

warning: auto-switch config unreadable or unsafe; every profile treated as excluded, none probed or refreshed

The rotator and profile verify do the same; see Unreadable exclude list, which also says how to fix the file without losing the exclusions.

States

Every profile gets exactly one state:

State Meaning
excluded The profile is in the auto-switch exclude list and was not probed. See Excluded profiles.
ok The session or the all-models week was read, from a passive reading, a direct read, an accepted usage request or a /usage line, and neither is at 100%.
session_exhausted The session is at 100% or more and a session limit applies. A reading with no session limit never has this state.
weekly_exhausted The all-models week is at 100% or more and the session is not.
spend_limit The /usage output reported that the organisation's spend limit was reached. Any percentages read are kept.
not_logged_in A direct read found no login to use, or the /usage output had no usage line of any kind (model week lines included) and reported that the profile is not signed in. Run amplihack profile login <name>. A profile live in ~/.claude is probed against ~/.claude, so its missing .credentials.json does not give this state.
timeout The fallback passed its deadline, in either attempt. The account's usage is unknown. A direct read that times out falls back instead, except under direct, where it gives error.
unparsed The /usage output had nothing recognisable. Run again with --raw to see what Claude said.
error The probe could not run. The reason goes to stderr in both modes, and the JSON also has it in error.

When several apply, the first in this order wins: excluded, error, timeout, spend_limit, session_exhausted, weekly_exhausted, ok, not_logged_in, unparsed. A model-specific week line at 100% (for example Current week (Opus)) does not make a profile exhausted; the profile can still be used with other models. The exit status of claude does not decide the state: output that parses counts even after a non-zero exit.

The spend-limit and not-logged-in states are recognised by phrases, matched without regard to case in stdout and stderr:

State Phrases
spend_limit spend limit, spending limit, usage limit for your organization, organization has reached
not_logged_in not logged in, run /login, invalid api key, login required, authentication_error, oauth token has expired

A spend-limit phrase wins even when usage lines were read, and such a row is not recorded: the session and weekly resets do not lift a spend limit, so recording its percentages would make auto-switch treat the profile as usable. A normal /usage reading contains none of these phrases.

The not-logged-in phrases count only when no usage line of any kind was read; a model week line alone is enough to rule them out. New wording from Claude that matches none of these gives unparsed, never a guessed state. Scripts should treat a state they do not know as unparsed.

Spend status

Every row has a spend status, shown in the SPEND column of the table, as the spend key of the JSON, and, when it is not n/a, as a spend:<value> mark in the bar view. It says whether /usage reported a used-up spend limit for the row. It is for reading only: ordering, the states and the rotator's decisions do not use it.

Value Rows
n/a No /usage text was read for spend, and none was needed: a direct row whose account has usage credits off, a passive row, an API-key row, and a fallback row given by an accepted get_usage answer, which is accepted only when credits are off.
ok /usage text was read, gave a usage reading, and did not report a used-up spend limit: a spend probe whose output parsed as ok, session_exhausted or weekly_exhausted, or a fallback row from /usage in one of those states.
limit_reached /usage text reported a used-up spend limit: a spend probe whose output parsed as spend_limit, or a fallback row in state spend_limit.
unknown A probe ran, or was asked for, and the spend status could not be read: a direct row with usage credits on whose --spend probe was killed at the probe deadline, could not run (including claude not found), or gave output that parsed as not_logged_in or unparsed; every fallback row in state not_logged_in, unparsed, timeout or error; and a direct row with no login to use.
not_probed Usage credits are on and no spend probe was asked for: a direct row with usage credits on in a run without --spend, or under AMPLIHACK_PROFILE_USAGE_PROBE=direct. The rotator's rows are always not_probed.

n/a does not mean that usage credits are off. A passive row says nothing about credits. ok is never guessed: output that claude printed but that gave no usage reading, such as a login prompt, gives unknown, not ok. A row whose state is ok and whose spend is limit_reached has room in its plan windows, but the account's spend limit is used up, so it cannot work past them on credits.

Failed and exhausted results

A probe that timed out or could not run says nothing about the account. Its usage is unknown, and it is never reported or treated as 100%. An exhausted result is a reading: the account answered, and a window is at 100% or more.

Result profile usage table --json Rotator cycle line Rotator decision Next probe
timeout state timeout, - in every percentage and reset "state": "timeout", session, week_all and error null, week_models empty <name>:unknown, timeout Unknown: never a target unless its last good reading qualifies, never counted as exhausted; a plan candidate in this state always blocks a move onto overflow Next run or cycle; no failed result is kept
error state error, - in every percentage and reset; reason on stderr "state": "error", session and week_all null, week_models empty, reason in error <name>:unknown, <label> for a labelled cause, else <name>:failed As for timeout, profile directory refused included (see Overflow decision) As for timeout
session_exhausted, weekly_exhausted the percentages read the windows read <name>:s=<n>%,w=<n>%, the windows read; see Exhausted figures Headroom 0: never a target Next run or cycle
Still running (rotator only) - - <name>:unknown, still running As for timeout Its result is used by the next cycle; see Reads that outlast a cycle

spend_limit, not_logged_in and unparsed are also shown as <name>:failed in the cycle line and are never a target; see Decision rule. Unlike timeout and error, they do not block a move onto overflow, so a profile that is never logged in cannot keep the rotator off credits for good. A failed live probe is handled as in Failed live probes. Neither profile usage nor the rotator records a timeout or error result as an auto-switch reading, or as exhausted anywhere.

Exhausted figures

An exhausted reading keeps both windows the probe read. The rotator does not use them to decide: an exhausted profile has headroom 0 and is never a target, whatever the figures are. They are kept so that the rotate log, and anything that reads weekly room from it, sees the weekly use read for a login that has only reached its session limit.

Window Shown as
The session The value read, rounded down; for session_exhausted never below 100%. A missing window shows 100% for session_exhausted, the window that ran out, and 0% for weekly_exhausted, as in the decision rule, so a login with no session limit shows s=0% whether or not its week has run out.
The all-models week The value read, rounded down; for weekly_exhausted never below 100%. A missing window shows w=? for session_exhausted and 100% for weekly_exhausted.
Probe result Session read Week read Cycle line
session_exhausted 100% 62% <name>:s=100%,w=62%
session_exhausted 100% none <name>:s=100%,w=?
weekly_exhausted 30% 99.6% <name>:s=30%,w=100%
weekly_exhausted, no session limit none 100% <name>:s=0%,w=100%
session_exhausted 98% 40% <name>:s=100%,w=40%

The same figures are used in the live and target parts of a swap line and in the live= part of an ALERT: no profile has capacity line. A login at its weekly limit with no session window shows s=0%, the same figure it shows before the week runs out; s=100% always means a session limit was reached.

The rotator writes one line to stderr (rotate.err for a background rotator) for each timeout or error result, except a profile with no login to use, with ~/.claude as the name of the live login. Both are fixed text:

warning: rotate: probe of <name> timed out
warning: rotate: probe of <name> failed: <reason>

A direct read that the usage endpoint declined with HTTP 429 and no usable retry deadline writes one more line, once at the start of each run of such reads of that login:

warning: rotate: probe of <name>: http 429 (no retry deadline)

A 429 with a deadline writes no such line. The run ends when a direct read of the login succeeds or is declined with a deadline, and the next 429 with no deadline writes the line again. A passive reading, a read still running, a timeout or another failure does not end a run. A rotator that restarts starts with no run open. The line changes nothing else: the cycle line still shows unknown, HTTP 429, and each failed read still writes its failed: line.

A read that panics, which is a bug, gives no result and reads failed for that cycle; the rotator writes one line for it and reads that login again in the next cycle:

warning: rotate: read of <name> panicked; no result

The reasons for error are fixed text, never the underlying I/O error. A failure to start, write to, read or wait for the usage request is not an error: it falls back to /usage. So the claude reasons below come from the /usage attempt.

Reason When
profile directory refused The profile cannot be resolved, or its directory fails the check just before a read or a spawn.
direct read: <reason> Only under AMPLIHACK_PROFILE_USAGE_PROBE=direct: the direct read failed with one of the fixed reasons.
claude not found A fallback was needed and the claude binary could not be found.
could not start claude Spawning claude failed.
could not read claude output Reading the child's stdout or stderr failed, or a pipe was still open 2 seconds after the child exited (a process that left its group still held it), so the output may be cut short.
could not wait for claude Waiting for the child failed. It is killed and reaped first.

Bar output

By default, profile usage prints one row per profile with the weekly and session usage drawn as bars:

PROFILE      WEEK             W-RESET      SESSION           S-RESET     STATE
review       █░░░░░░░░░  10%  11-05 09:00  ░░░░░░░░░░   5%   11-01 14:00 ok
work (live)  ███░░░░░░░  30%  11-05 09:00  ██░░░░░░░░  20%   11-01 12:00 ok                 * hosts:personal
weekly       ████░░░░░░  47%  11-05 09:00  no session limit  -           ok
credit       ██████░░░░  61%  11-06 02:00  ████░░░░░░  40%   11-01 21:00 ok                 overflow (fallback) spend:ok
team         █████░░░░░  55%  11-05 09:00  ██████████ 100%   11-01 23:50 session_exhausted
api          api-key (billed per token)                                  api_key
personal     no reading (not_logged_in)                                  not_logged_in      leased→work spend:unknown
spare        no reading (timeout)                                        timeout            (fallback) spend:unknown
times: Europe/London
order: rotator pick (most room in the worse of session and week, then name)

The columns are:

Column Content
PROFILE The profile name, followed by (live) when the profile's login is the one in ~/.claude (the condition for the live in ~/.claude mark).
WEEK The all-models week as a bar, or - when the row has no week reading.
W-RESET When the all-models week resets, as a reset time.
SESSION The session as a bar; no session limit for a reading with no session limit; - when the session window is missing.
S-RESET When the session resets; - for a row with no session limit.
STATE The state.
(no heading) Every other mark (*, leased→<dir>, hosts:<account>, overflow, overflow, blocked until <time>, blocked until <time>, (fallback)), then spend:<value> when the row's spend status is not n/a, separated by spaces. Empty when there are none.

Rows without a reading have no bars and no reset cells. From WEEK to the end of S-RESET they show one message:

Row Message
API-key (api_key) api-key (billed per token)
A direct read with no login to use not signed in (<reason>), for example not signed in (no oauth token)
not_logged_in, timeout, unparsed, error no reading (<state>), for example no reading (timeout)
Excluded (excluded) excluded (not probed)

The STATE cell and the marks are still shown on these rows. Rows in state ok, session_exhausted, weekly_exhausted and spend_limit show their bars as read, so a window at its limit shows a full red bar.

The PROFILE column is as wide as the longest label, up to 31 characters. A name longer than 24 characters is cut to its first 23 characters followed by …, and (live) follows the cut name. The header line, and a row in state ok with no marks, fit in 100 columns for any name, in both local and UTC time. Longer state names and the marks column can take a row past 100 columns. Names, accounts and other text from files are cleaned before they are printed, as in the table.

After the rows come, in this order: the --raw blocks, the running on overflow:, live: and blocked: lines described under Marks and API-key usage, then times: and order:. With no profiles there are no rows and no footer; the command prints the same line as --table.

The layout is for people and may change; scripts should use --json.

Bars

A bar is 10 cells of █ (used) and ░ (free), one space and the percentage, right-aligned in 4 characters:

Used Cell
0% ░░░░░░░░░░ 0%
13% █░░░░░░░░░ 13%
41.9% ████░░░░░░ 41%
55% █████░░░░░ 55%
100% ██████████ 100%
130% ██████████ 130%

The percentage is printed as a whole number, rounded down, so every bar cell is 15 characters wide and the columns stay aligned. 41.2% and 41.9% both read 41%, and 99.6% reads 99%, so 100% appears only when the window has reached its limit. --table and --json keep the decimal place (12.5%). The number of filled cells is the percentage divided by 10 and rounded down, between 0 and 10. A percentage above 100 fills the bar and is printed rounded down in the same way.

The bars and the percentage show the reading as it was probed, even when its reset time has passed. Ordering counts such a window as 0%.

Colour

When stdout is a terminal, each bar and its percentage are coloured by the percentage as read, before rounding. Because the printed figure is rounded down, it always falls in the same band as the colour:

Used Colour
Below 70% Green
70% to below 90% Yellow
90% and above Red

Only the bar and the percentage are coloured; the header, labels, states, marks and footer lines never are. Set NO_COLOR to any non-empty value to turn colour off, as described at no-color.org:

NO_COLOR=1 amplihack profile usage

When stdout is a pipe or a file, no colour is used and the output contains no escape sequences. Column widths are the same with and without colour. --table and --json are never coloured.

Reset times

A reset cell reads MM-DD HH:MM in local time, the same width on every row. A window with no reset time, or one whose reset amplihack could not read as a time, shows -. The time zone is named once, in the times: line at the end:

Source of the zone Used when
TZ It is set, not empty, and names an IANA time zone, such as TZ=Asia/Tokyo (a leading : is ignored).
The system time zone TZ is unset or empty and the system zone has an IANA name.
The UTC offset, as UTC+HH:MM or UTC-HH:MM Neither has a usable name, or TZ is set to something other than an IANA name, such as a POSIX rule (TZ=JST-9) or a file path. The times follow such a TZ, so the system zone's name would not match them.

Each time is converted with its own offset, so a reset after a change to or from summer time is shown in the offset that applies on that day.

With --utc, the cells read MM-DD HH:MMZ and the footer reads times: UTC. A reset at 23:30 UTC on 5 November reads 11-05 23:30Z with --utc, 11-06 01:30 at UTC+02:00 and 11-05 22:30 at UTC-01:00:

amplihack profile usage --utc
PROFILE      WEEK             W-RESET       SESSION           S-RESET      STATE
review       █░░░░░░░░░  10%  11-05 09:00Z  ░░░░░░░░░░   5%   11-01 14:00Z ok
work (live)  ███░░░░░░░  30%  11-05 09:00Z  ██░░░░░░░░  20%   11-01 12:00Z ok                 * hosts:personal
weekly       ████░░░░░░  47%  11-05 09:00Z  no session limit  -            ok
credit       ██████░░░░  61%  11-06 02:00Z  ████░░░░░░  40%   11-01 21:00Z ok                 overflow (fallback) spend:ok
team         █████░░░░░  55%  11-05 09:00Z  ██████████ 100%   11-01 23:50Z session_exhausted
api          api-key (billed per token)                                    api_key
personal     no reading (not_logged_in)                                    not_logged_in      leased→work spend:unknown
spare        no reading (timeout)                                          timeout            (fallback) spend:unknown
times: UTC
order: rotator pick (most room in the worse of session and week, then name)

Reset times taken from Claude's /usage text, such as Oct 16, 4:50pm (America/Los_Angeles), are shown in the same numeric form when amplihack could resolve them to a time, as it does for resets_at in the JSON. --table still shows the text as Claude printed it.

Table output

--table prints the eight-column table that was the default output before the bar view. Its columns and cells are unchanged; only the row order follows the ordering rule, and the table ends with the order: line. It has no times: line, because its reset columns show the reset as received.

amplihack profile usage --table --spend
PROFILE      MARKS                                STATE              SESSION           SESSION RESETS                     WEEK  WEEK RESETS                        SPEND
review       -                                    ok                 5%                2026-10-17T04:00:00Z               10%   2026-10-22T09:00:00Z               n/a
work         * hosts:personal                     ok                 20%               2026-10-17T02:00:00Z               30%   2026-10-22T09:00:00Z               n/a
weekly       -                                    ok                 no session limit  -                                  47%   2026-10-22T09:00:00Z               n/a
example-org  -                                    ok                 35%               2026-10-17T03:00:00Z               52%   2026-10-22T09:00:00Z               ok
credit       overflow (fallback)                  ok                 40%               Oct 16, 9pm (America/Los_Angeles)  61%   Oct 22, 2am (America/Los_Angeles)  ok
org2         -                                    session_exhausted  100%              2026-10-16T22:10:00Z               71%   2026-10-22T09:00:00Z               limit_reached
team         -                                    session_exhausted  100%              2026-10-16T23:50:00Z               55%   2026-10-22T09:00:00Z               n/a
personal     leased→work                          not_logged_in      -                 -                                  -     -                                  unknown
scratch      not signed in (no credentials file)  not_logged_in      -                 -                                  -     -                                  unknown
spare        (fallback)                           timeout            -                 -                                  -     -                                  unknown
order: rotator pick (most room in the worse of session and week, then name)

scratch has no .credentials.json, so its direct read was final and its MARKS cell names the reason. credit is marked as overflow, so it was probed with /usage and shows Claude's own reset text. team is at its session limit and has used 55% of its week; the weekly figure is shown as reported. spare failed its direct read and its claude fallback timed out. The other rows came from passive or direct reads. example-org and org2 have usage credits on: their windows come from the direct read, and, because this run used --spend, the SPEND column comes from a spend probe under the normal per-probe timeout, which found org2's spend limit used up. Without --spend both would show not_probed. SPEND is the spend status.

SESSION and WEEK are the session and all-models week. Percentages print as a whole number when they are whole and with one decimal place otherwise (12.5%). - means no value. A timeout or error row shows - in every percentage and reset column: its usage is unknown. Model-specific week lines are not in the table; they are in the JSON.

A row in state ok or weekly_exhausted with no session limit shows no session limit in full in SESSION, never shortened, and - in SESSION RESETS. The label means that no active session window was reported; the profile is ranked on its week. Every other row keeps its usual cells: timeout, error, unparsed, not_logged_in, spend_limit and API-key rows never show the label.

Reset columns show the reset as received, so their form depends on the attempt that gave the row:

Row from Reset column Example
A passive reading The stored reset time, as YYYY-MM-DDTHH:MM:SSZ 2026-10-16T23:50:00Z
A direct read The resets_at string the endpoint sent, as for the usage request 2026-10-16T23:50:00Z
The usage request The resets_at string claude sent, an ISO 8601 time; - when it sent none or not a string 2026-10-16T23:50:00Z, an example of the form (details)
/usage Claude's text as printed Oct 16, 4:50pm (America/Los_Angeles)

Text from Claude and from state files is cleaned before it reaches the terminal: control characters (including escape sequences) and the bidirectional override and isolate characters U+202A to U+202E and U+2066 to U+2069 are replaced with ?, and reset text longer than 64 characters is cut to 64 and followed by …. The table's layout is for people and may change; scripts should use --json. The table has eight columns; SPEND was added as the last. A script that splits rows on whitespace and reads the last field now gets the spend status instead of WEEK RESETS, and the reset columns can themselves contain spaces. Use --json instead.

For each error row, one line goes to stderr, with or without --json:

warning: profile "review": could not start claude

A row with no login to use prints no such line; its reason is in the row. In the table it shows not signed in (<reason>) in MARKS, after any other marks, not_logged_in in STATE, - in every percentage and reset column and unknown in SPEND, as scratch does in the example above.

With --raw, each row whose direct read failed and that went on to claude also prints one note: line to stderr, as shown under Direct read failures, and each direct row whose account has usage credits on prints two, as shown under Usage credits on.

Raw output

With --raw, a row read passively or directly is followed by one fixed line, because no claude ran for it. The examples here use --table; the bar view prints the same lines under its rows:

review    -                 ok                 5%                2026-10-17T04:00:00Z  10%   2026-10-22T09:00:00Z
  (direct: no claude output)

A passive row prints (passive: no claude output). A row with no login to use prints nothing under it. The body of a direct answer is never printed. A direct row whose account has usage credits on prints the same (direct: no claude output) line: the output of its spend probe is not shown. In the JSON, such a row's raw is {"stdout": "", "stderr": ""}.

A fallback row is followed by what claude printed in the attempt that gave the row, indented and cleaned of control characters other than newlines. Each stream is shown up to the 64 KiB read for that attempt. For a row from the usage request, that is the attempt's whole stdout and stderr: every JSON line claude printed, from the system line it prints when it starts, through the control_response answer, to any lines after it. For a row from /usage, it is the text, as in this run with AMPLIHACK_PROFILE_USAGE_PROBE=text:

team      (fallback)        session_exhausted  100%     Oct 16, 4:50pm (America/Los_Angeles)  68%   Oct 22, 2am (America/Los_Angeles)
  raw stdout:
    You are currently using your subscription to power your Claude Code usage

    Current session: 100% used · resets Oct 16, 4:50pm (America/Los_Angeles)
    Current week (all models): 68% used · resets Oct 22, 2am (America/Los_Angeles)
  raw stderr:
    (empty)

Output from a usage request that fell back is not shown. Raw output can include account details, such as your e-mail address, organisation name or subscription type; read it before you share it. amplihack prints it only to stdout and never writes it to usage.json, the rotate log or any other file, and the rotator never collects it.

Ordering

Rows are sorted by the rotator's headroom: the room left in the worse of the session and the all-models week. The bar view, --table and --json use the same order, and the bar view and --table end with a line that states the rule:

order: rotator pick (most room in the worse of session and week, then name)

Rows are in five groups:

  1. Usable (ok): most headroom first, then by name. Headroom is the rotator's: 100 - max(session, week) for the all-models week, rounded down to a whole point. A missing session window, including no session limit, counts as 0%, so a weekly-only profile is ranked by its weekly room. Reset times break no ties: two profiles at 41.2% and 41.9% both have headroom 58 and are sorted by name. After every row with a headroom come the ok rows with no all-models week reading, by name. The rotator treats such a reading as a failed probe and never picks it.
  2. Exhausted (session_exhausted, weekly_exhausted, spend_limit): soonest back first. A profile is back when every window at 100% or more has reset, so "back at" is the latest of those reset times. If any of those windows has no resets_at, the back-at time is unknown, and the profile comes after the others. A spend_limit row's back-at time is always unknown, because the window resets do not lift a spend limit. Then by name.
  3. API key (api_key): by name.
  4. Unavailable: not_logged_in, then timeout, then unparsed, then error, each by name.
  5. Excluded (excluded): by name. See Excluded profiles.

Only the headroom rule is applied. The rules that decide which profiles the rotator may pick at all are not: the overflow tiers, the auto-switch exclude list and the other skip reasons under Rotate candidates, and the thresholds in Rotate settings do not change a row's place. The first row is therefore not always the login the rotator would pick next. An overflow profile at 20% of its session and 30% of its week (headroom 70) is listed above a plan login at 50% of its week (headroom 50), although the rotator moves to the plan login first and uses the overflow profile only as described under Overflow decision. An excluded profile is not probed, so it has no headroom and is listed last.

The headroom used for sorting also differs from the rotator's in one respect. A window whose reset time has already passed counts as 0% used when the rows are sorted, because the quota it reports has since been restored; the bars and percentages still show the reading as probed. profile usage reads every profile afresh, so this happens only for a reading taken just before a reset.

The live row, the default profile and overflow profiles are sorted by their state and numbers like any other row.

The spend status plays no part in the order.

Marks

Mark Meaning
* The default profile, as in list.
(fallback) The row came from claude, not from a passive or direct read. See Reading source.
not signed in (<reason>) A direct read found no login to use. Always the last mark. --table only: the bar view shows this text in place of the bars and leaves it out of its marks column.
leased→<dir> This profile's login is live in profile <dir>'s directory, lent by auto-switch.
hosts:<account> This profile's directory currently holds the login of profile <account>, so the numbers on this row belong to <account>.
live in ~/.claude This profile's login is in the default directory ~/.claude, and the numbers on this row were read from there. See Logins in ~/.claude.
overflow The profile is marked as credit-backed overflow in <root>/.auto-switch.
overflow, blocked until <time> As overflow, and the rotator has blocked it after a spend-limit reading until <time> (UTC, YYYY-MM-DDTHH:MM:SSZ).
blocked until <time> The profile is not marked as overflow, and a step has blocked it after a spend-limit failure until <time>, in the same format.

Several marks are separated by a space (* live in ~/.claude, overflow (fallback)); none prints -. This is the MARKS column of --table. The bar view shows live in ~/.claude as (live) after the profile name instead, and the other marks in the unlabelled column after STATE, which is empty when there are none. A row marked live in ~/.claude is placed by its state and numbers like any other row. An overflow row is placed by its state like any other row too; its session and week numbers are its plan limits, which it can work past on credits.

When the row marked live in ~/.claude is also marked overflow, and that row's own probe in this run reached the session or weekly limit (state session_exhausted or weekly_exhausted, or the session or all-models weekly window at 100%), the rows are followed by one line, in the bar view and in --table:

running on overflow: login-aw

A live overflow row whose probe shows plan capacity left prints no footer: work on it is still covered by the plan. A full per-model weekly window (for example Fable) does not count, because this footer reads only the session and all-models weekly windows. A live overflow row whose probe failed prints no footer either, because nothing in the run shows the limit was reached.

The overflow marks come from <root>/.auto-switch, read once before probing; the block comes from the rotate ledger, read at the same time. A corrupt .auto-switch gives no overflow marks, and a rotate ledger that cannot be read gives no block, each with a warning on stderr. The live in ~/.claude mark, and so the footer, needs the live profile to be identified by account; see Logins in ~/.claude.

While a profile's login is lent out, its own directory has no login, so its row usually shows not_logged_in. That account's numbers are on the row of the profile hosting it (work above, whose account is personal). Lease marks come from the auto-switch ledger, read once before probing without taking the lock; the default mark is read at the same time. The account a row is recorded under is the one from this read, so a swap during the probe is caught when the reading is recorded. If there is no <root>/.auto-switch.d/, there are no lease marks. If the default pointer or the ledger cannot be read, a warning goes to stderr and the marks it would give are left out; the probes still run.

Logins in ~/.claude

A login rotator, either profile rotate or an external one such as the tmux prototype, can move one account's login into the default directory ~/.claude. While it is there, that profile's own directory has no .credentials.json. profile usage does not report that profile as not_logged_in: it probes it against ~/.claude instead, marks the row live in ~/.claude, and sets live_in to "~/.claude" in the JSON.

The default profile (*) is unrelated to ~/.claude. The default profile is the one amplihack claude uses when no profile is named; ~/.claude is the directory claude uses when CLAUDE_CONFIG_DIR is not set. A row can have either mark, both, or neither.

The live profile is found once, before probing, and nothing is written:

  1. ~/.claude/.credentials.json must be a regular file. If it is missing or is a symlink, no profile is live.
  2. Rotator ledger. There are two possible ledgers: <root>/.auto-switch.d/rotate/ledger.json, written by profile rotate, and <root>/.rotator/ledger.json, written by an external rotator. If only one exists, it decides. If both exist and both are trusted, the one with the later since decides; a ledger with no since counts as older than one with it, and on a tie the profile rotate ledger decides. since may be epoch seconds (the profile rotate ledger) or an ISO-8601 time with an offset or in local time (the external rotator writes datetime.now().isoformat()). If one of them cannot be trusted or read, its warning is printed and the other decides. A profile rotate ledger with no live value (written by a cycle that only raised an ALERT or found the rotator idle) names nobody and counts as absent. An open hand-change suspicion does not change which profile the ledger names here: profile usage makes no identity reads and does not compare ~/.claude.json with the ledger. The duplicate-login warning for ~/.claude and a profile M is still printed while both logins are the same account. Both ledgers are only read. The deciding ledger's live field names the profile and its since is used only for the check after the probes; other fields are ignored. The checks run in this order, and the first that fails decides:
live in a trusted ledger Result stderr
Missing or null No profile is live. This is the rotator's idle state. nothing
Not a string, fails the name rules (for example "../x"), or names a profile whose directory does not exist or fails the usual directory check No profile is live. the ledger warning below
Names a profile that still has something at <root>/<live>/.credentials.json (a dangling symlink counts) No profile is live. That profile is probed through its own directory as normal, because its own login is stronger evidence than a ledger that is probably out of date. warning: the login rotator's ledger names a profile that still has its own login; it is not marked live in ~/.claude
Names a profile with no .credentials.json That profile is live. nothing

The account match below is never tried when either ledger file exists, or when amplihack cannot tell whether one exists (for example, a <root>/.rotator/ directory you cannot search). The second case is treated as an unreadable ledger.

The ledger is taken at its word: amplihack does not compare the account in ~/.claude.json with the named profile's account. If the prototype ledger names the wrong profile (the rotator stopped partway through a swap, or someone ran /login in ~/.claude), that profile's row shows the numbers of the login that is actually in ~/.claude.

A ledger is trusted only if the profile root and the directories leading to it (<root>/.rotator, or <root>/.auto-switch.d and its rotate) are real directories (not symlinks) owned by you that no other user can write to (group write is allowed only when the group is your own per-user group), and ledger.json is not a symlink, is owned by you, is not writable by group or others, and is at most 64 KiB. The profile rotate ledger must also be "version": 1. If any of these fails, or the file is not valid JSON, that ledger is ignored and one warning goes to stderr. If no other ledger decides, no profile is live and the account match below is not tried:

warning: could not read the login rotator's ledger; no profile is marked live in ~/.claude

No warning text is ever built from the ledger's contents. 3. Account match, only when there is no ledger file. A missing ledger.json, with or without its directory, is the normal case when no rotator is installed, and prints nothing. A profile counts as live if its directory passes the usual check, it has no .credentials.json, and the oauthAccount in its .claude.json matches the one in ~/.claude.json: - when both have an accountUuid, the uuids decide; - otherwise both emailAddress values are compared without regard to case; - an empty or non-string value counts as missing and never matches.

If the profile root cannot be listed, none is marked and warning: could not list profiles; no profile is marked live in ~/.claude goes to stderr. If more than one profile matches, none is marked and one warning goes to stderr:

warning: more than one profile matches the account in ~/.claude; none is marked live

At most one row is marked. If HOME is unset or empty, no row is marked. The ownership and mode checks above exist only on Unix, so on Windows and other non-Unix platforms no row is marked and no warning is printed. In practice this works on Linux only: on macOS Claude keeps the login in the Keychain and writes no ~/.claude/.credentials.json, so step 1 finds no login and no row is marked. When names are given, the mark appears only if the live profile is one of them, and the warnings above are printed only if at least one named profile has no .credentials.json of its own (a profile with its own login is never live, so the warning could not concern it). The own-login warning is the exception and is always printed, because the profile it is about has a login.

Swaps during the probe

After every window reading has finished, and before any --spend spend probe starts, the same evidence is checked again: the ledger's live and since fields, or the matched account. A long --spend pass therefore never widens the time in which a swap stops the live profile's windows from being recorded. since is only compared for equality; it is never printed or stored. If the evidence changed or can no longer be read, the login in ~/.claude may have been swapped during the probe. The row is still shown, with its numbers and its mark, but its usage is not recorded (the other rows are recorded as usual), and one note goes to stderr. The profile name in it is cleaned of control characters:

note: the login in ~/.claude changed while profile "work" was probed; its usage was not recorded this run

This is a note, not a warning. The command only sees that ~/.claude no longer holds the live profile's login; the change may be a rotator swap or a /login in ~/.claude, and the note does not say which. A rotator swap needs no fix; a login that is not the profile's recorded account is reported by its own warning. The command does not retry the probe, and the exit status is unchanged. A run with no swap during the probes prints no note.

On such a row, the numbers and any --raw text may belong to the login that replaced it. Run the command again for current numbers.

The live profile's spend probe reads ~/.claude, so with --spend the evidence is checked again before it starts and once it has finished. If either check fails, the probe's result is dropped, the row's spend is unknown rather than the spend of the login that replaced it, and one note goes to stderr. The row's windows were read before the change and are recorded as usual:

note: the login in ~/.claude changed while profile "work" was probed for its spend; its spend is unknown this run

The check has two known gaps. Closing them would need a lock on the rotator's ledger, which amplihack does not take:

  • A profile that becomes live only after the run started is not detected. Its row is probed through its own directory, which by then has no login.
  • A swap from A to B and back to A during the run is missed when the ledger has no since field, because the evidence before and after is the same.

profile usage never writes, creates or locks anything under <root>/.rotator/ or <root>/.auto-switch.d/rotate/; the rotators own those files.

Warnings about ~/.claude

Each of these is one fixed line on stderr. None of them changes the exit status, and none marks a profile live when there is doubt.

Warning Cause
warning: could not read the login rotator's ledger; no profile is marked live in ~/.claude ledger.json exists but is not trusted (wrong owner, writable by group or others, a symlink, over 64 KiB, or .rotator is not a real directory you own), is not valid JSON, or its live value is not a usable profile name or names a profile that does not exist.
warning: more than one profile matches the account in ~/.claude; none is marked live No ledger, and more than one profile with no login matches the account in ~/.claude.json.
warning: the login rotator's ledger names a profile that still has its own login; it is not marked live in ~/.claude The ledger names a profile whose directory still has a .credentials.json.
warning: could not list profiles; no profile is marked live in ~/.claude No ledger, and the profile root could not be listed (for example, it is not readable), so no account match was tried.
note: the login in ~/.claude changed while profile "<name>" was probed; its usage was not recorded this run The evidence for the live profile changed during the probe. A note rather than a warning. See Swaps during the probe.
note: the login in ~/.claude changed while profile "<name>" was probed for its spend; its spend is unknown this run With --spend, the evidence for the live profile changed before or during its spend probe. Its spend is unknown; its windows are recorded. See Swaps during the probe.
warning: profiles '<a>' and '<b>' are signed in to the same account and organization (duplicate login); … Two logins are the same account. One line per pair, after the other warnings. The line names the profile whose login is not its recorded account, or ~/.claude when it is not the live profile's recorded account, or says amplihack cannot tell which one is wrong. See Duplicate-login warning. Printed for ~/.claude and M while a manual /login in ~/.claude has left both with the same account. The rotator moves M's copy aside only after two matching credential readings, and only when no profile is left with no login.

A manual /login in ~/.claude replaces whatever login was there; the profile that login belonged to is left with no login. profile usage prints no warning of its own about that; the rotator does, in its log and in rotate status.

Codex accounts

When no profile names are given, profile usage also reads every Codex account and prints one row for each after the Claude output. Each account is read live, on every run, by asking Codex itself; nothing is taken from session files or any earlier reading. An account that cannot be read shows why, never an older value.

amplihack profile usage
PROFILE      WEEK             W-RESET      SESSION           S-RESET     STATE
review       █░░░░░░░░░  10%  11-05 09:00  ░░░░░░░░░░   5%   11-01 14:00 ok
work (live)  ███░░░░░░░  30%  11-05 09:00  ██░░░░░░░░  20%   11-01 12:00 ok                 * hosts:personal
times: Europe/London
order: rotator pick (most room in the worse of session and week, then name)

Codex accounts under /home/you/.codex-profiles
hhale     signed in      credits 4200  plan team  read 19:09:00
jjones    not signed in  read 19:09:00
kkim      timed out      after 20s  read 19:09:00
login-af  signed in      5h █░░░░░░░░░  12% 11-06 21:40 in 2h 31m  7d ████░░░░░░  41% 11-12 08:00 in 132h 51m  plan plus  read 19:09:00
login-ag  signed in      7d ███░░░░░░░  34% 11-10 14:30 in 91h 21m  plan pro  read 19:09:00  <- next
mmoss     error: codex app-server exited (exit status: 1): error: unrecognized subcommand 'app-server'  read 19:09:00
~/.codex  signed in      5h ████████░░  88% 11-06 20:15 in 1h 6m  7d ███████░░░  70% 11-09 03:00 in 55h 51m  plan plus  read 19:09:00

The Codex accounts are read while the Claude profiles are read. The Claude output never waits for Codex, and the Codex block is printed last. In the bar view and with --table, amplihack prints the Claude rows, their footer lines and the capacity summary to stdout and flushes it, then writes the stderr warnings and any --raw notes, then updates the auto-switch readings and the usage history, and only then waits for the Codex reads to finish and prints the Codex block. A slow Codex account delays only the Codex block, never the Claude output. stdout and stderr each keep their own order. --summary-json waits for both and prints one document, as before.

Codex rows never change the Claude rows, the capacity summary, the usage history, the auto-switch readings or the exit status. With profile names given (amplihack profile usage work review), Codex is not read and no Codex block is printed; --summary-json still has the codex key, as an empty array. --json never reads Codex and has no Codex rows.

Which accounts are read
Account Label When it is read
Each subdirectory of the Codex profiles root, in byte order of its name The directory name Always. Names starting with . are skipped, as codex-pick's * glob skips them. A symlink to a directory is followed.
$HOME/.codex ~/.codex When it is a directory and its canonical path is neither the root nor any profile directory's canonical path. It is read with the others and shown last, and only when it is signed in: a not signed in result drops the row. A timed out or error result is shown.

The Codex profiles root is CODEX_PROFILES_ROOT when it is set and not empty, otherwise $HOME/.codex-profiles. A root that is missing, is not a directory or has no subdirectories is not an error. The block is then one line, and ~/.codex is still read:

Codex: no accounts under /home/you/.codex-profiles

When ~/.codex is signed in and the root has no accounts, the header line is printed with the ~/.codex row under it.

A root that exists but cannot be listed (for example, permission denied) prints one line on stderr. ~/.codex is then not read either, and the block is the single Codex: no accounts under line:

warning: cannot list Codex accounts under /home/you/.codex-profiles: Permission denied (os error 13)

The exit status does not change, and codex in --summary-json is an empty array.

Live read

On Unix, for each account, amplihack starts one Codex app server with the account's directory as its home and asks it for the account's rate limits. The program is CODEX_BIN when it is set and not empty, otherwise codex found through PATH:

CODEX_HOME=<account directory> codex app-server

and writes three JSON-RPC lines to its stdin:

{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"amplihack","version":"<amplihack version>"}}}
{"jsonrpc":"2.0","method":"initialized"}
{"jsonrpc":"2.0","id":2,"method":"account/rateLimits/read","params":{}}

No model call is made, so the read uses no quota. Answers are matched by id only; lines without an id, such as the remoteControl/status/changed notification Codex sends first, are skipped, and a "jsonrpc" field is not required. An answer to account/rateLimits/read reads, for example:

{
  "id": 2,
  "result": {
    "rateLimits": {
      "primary": { "usedPercent": 12, "windowDurationMins": 300, "resetsAt": 1794001200 },
      "secondary": { "usedPercent": 41, "windowDurationMins": 10080, "resetsAt": 1794470400 },
      "credits": null,
      "planType": "plus",
      "rateLimitReachedType": null,
      "ordinaryUsageAllowed": true
    }
  }
}
Field Read from Rule
Windows primary, secondary Each that is an object. A missing or null one is not shown.
Used percentage usedPercent A JSON number, or a string of digits with an optional decimal point, that is finite and not negative. Anything else counts as absent. Not clamped.
Window length windowDurationMins A non-negative whole number of minutes.
Reset resetsAt Unix epoch seconds; see Codex reset times.
Credits credits hasCredits counts only as the JSON value true; balance follows the same number rule as the used percentage.
Plan planType A string, cut to 200 characters.
Limit reached rateLimitReachedType A string, cut to 200 characters; JSON only.
Ordinary usage allowed ordinaryUsageAllowed A JSON bool; JSON only.

The figures may sit in result.rateLimits, result.rate_limits or in result itself. Every field is also accepted in snake_case (used_percent, window_duration_mins, resets_at, has_credits, plan_type, rate_limit_reached_type, ordinary_usage_allowed). A result that is not an object gives error: unexpected response from codex app-server, so a reply amplihack does not understand never appears as a reading.

All accounts are read at once, one thread each, alongside the Claude probes, so the whole Codex read normally takes about as long as the slowest account. There is no cap on the number read at once.

Codex read deadline

Each account has one deadline that covers starting the program, the handshake and the answer: 20 seconds, or AMPLIHACK_CODEX_USAGE_TIMEOUT_SECS, a whole number from 1 to 300. Any other value prints one warning on stderr and uses 20:

warning: AMPLIHACK_CODEX_USAGE_TIMEOUT_SECS="0" is not a whole number from 1 to 300; using 20

The last 3 seconds of the deadline (or the last quarter, for a deadline under 12 seconds) are kept for stopping the app server. The answer must arrive before that part starts; if it does not, the row reads timed out.

The app server may be renewing the account's login when the read ends. A renewal stopped after the old refresh token is retired but before the new one is written leaves the account signed out. So on every outcome, including success and timed out, the app server is stopped in this order:

  1. Its stdin is closed. The app server exits on its own when its stdin ends (codex 0.166.0 exits with status 0 about half a second later), so a renewal under way can finish and be written.
  2. If it has not exited by the middle of the stop time, its process group gets SIGTERM.
  3. If it has still not exited when the deadline passes, the group gets SIGKILL.

Each step waits for the exit itself (a blocking waitid reported on a channel), not on a polling loop. After the exit the whole process group is killed and the process is reaped, so no Codex process outlives the command. A read that got its answer early waits at most the 3-second stop time for the exit, not the rest of the deadline.

Only an app server that ignores both the end of its stdin and SIGTERM until the deadline is killed outright. If that one was renewing the login at that moment, the account may have to sign in again; run codex login with CODEX_HOME set to that account directory.

The live read needs process groups, so it runs only on Unix. On Windows and other non-Unix platforms no Codex program is started: the accounts are still listed as described in Which accounts are read, and every row reads error: codex usage read is supported only on Unix. The JSON rows keep the same keys, with state set to error.

Codex states
Text state JSON state When
signed in ok account/rateLimits/read answered with a result.
not signed in not_signed_in It answered with an error whose message contains, ignoring case, authentication required, not logged in, not signed in or login required. Codex 0.166.0 answers codex account authentication required to read rate limits.
timed out timeout No answer before the stop time at the end of the deadline.
error: <reason> error Anything else; see the reasons below.
Reason Cause
codex binary not found: <bin> The program does not exist.
cannot start <bin>: <error> It exists but could not be started, for example for lack of permission.
codex app-server exited (<status>): <last stderr line> It exited before answering. The stderr line is the last non-empty one, cut to 200 characters.
codex usage read is supported only on Unix The platform is not Unix; see Codex read deadline. No program is started.
unexpected response from codex app-server The result is not an object, or a line of stdout is longer than 1 MiB.
The server's message Any other JSON-RPC error, cut to 200 characters. An error answer to initialize counts too.
Codex row layout

Each row is the label, padded to the longest label (up to 24 characters; a longer label is cut to 23 followed by …), then the state padded to 13 characters, then these fields, separated by two spaces:

Field Shown Form
Windows For each window reported, primary first <length> <bar> <pct> <reset> in <time>; see below.
Credits When credits was reported credits <balance>, or credits yes / credits no from hasCredits when there is no balance. The balance is printed with no trailing zeros, as 4200 or 12.5.
Plan When planType was reported plan <type>
No figures A signed in row with no window and no credits no windows reported
Detail timed out rows after <n>s, the deadline that applied.
Read time Always read HH:MM:SS, the time the answer arrived or, for a row with no reading, the time the read was given up.
Marker The next choice only <- next

The window length is 5h for 300 minutes and 7d for 10080. Any other length is <n>d when it is a whole number of days, <n>h when it is a whole number of hours, and <n>m otherwise. A window with no length is labelled primary or secondary.

The bar and the percentage follow the Claude bars: 10 cells and a whole-number percentage, rounded down, coloured the same way. With --table, the bar is left out and the percentage keeps one decimal place where there is one, as 12.5%. A window with no percentage shows - in place of both.

Rows keep the order in Which accounts are read; they are not sorted by room. --raw, --spend and --usable-session-pct do not change the Codex block. The block is printed after the whole Claude output, including its footer, separated by one empty line, and also after the no profiles line when there are no Claude profiles.

Labels, the root path, plan types and error reasons are cleaned before they are printed, so a directory name or a server string cannot send terminal escapes. The layout is for people and may change; scripts should use --json.

Codex reset times

A reset is shown as MM-DD HH:MM in the same zone as the Claude reset cells, and MM-DD HH:MMZ with --utc, followed by in <h>h <m>m from the read time, rounded down to the minute: in 2h 31m, in 132h 51m. A reset at or before the read time shows due instead of in …. With --utc the read time is HH:MM:SSZ.

resetsAt is used as a time only when it is above 0 and no more than 400 days after the read. Any other value is shown as reset <value>, as given, with no in …, and its resets_at_rfc3339 in the JSON is null. A window with no reset shows -.

Codex next choice

The <- next marker goes on the account codex-pick's rule picks from these live readings. It is not always the account codex-pick itself would choose: codex-pick reads the rate limits stored in each account's session files, which can be days old, while this view reads them live, so the two can disagree. The rule:

  1. Only signed in rows are candidates. A row that timed out, failed or is not signed in is never chosen.
  2. Each candidate's room is 100 - max(used percentage) over its windows; a row with no window percentage has room 0.
  3. A candidate with room 0 or less gets 0.5 instead when it reports hasCredits true and a balance above the credit floor, 3000, and -1 otherwise.
  4. The candidates are sorted by room, then by path, both descending. The path is the account directory as built (<root>/<name> or $HOME/.codex), compared as bytes, not resolved through symlinks.
  5. The first candidate with room above 0 is marked. When there is none, no row is marked.

In the example, login-ag (room 66) is chosen over login-af (59), hhale (credits only, 0.5) and ~/.codex (12). Two accounts with the same room are taken in descending path order, so login-ag would come before login-af. codex-pick also counts a signed-in account with no stored reading as full; with live reads that case cannot arise, because a signed-in account always answers with its figures.

What the Codex read does not do
  • It never opens auth.json, config.toml or any other file inside an account directory. Directories are only listed and checked for type. Codex reads its own login.
  • It makes no network request itself; the Codex app server does, as it would for codex in that account.
  • CODEX_HOME is set only in the child's environment, never in amplihack's own. OPENAI_API_KEY and CODEX_API_KEY are removed from the child's environment, so an API key cannot replace the account's login in the reading, and RUST_LOG is removed, so verbose logging cannot put login detail into an error reason.
  • No shell is used. The account path reaches the child only through CODEX_HOME.
  • Readings are not stored anywhere. amplihack writes nothing into an account directory; the Codex app server itself keeps its state files there, as any codex run does.
  • It does not stop the Codex app server from refreshing the account's login. The server may refresh that account's tokens and rewrite its login file, as any codex run in that directory can. This includes ~/.codex and any account a live Codex session is using at the time; a session that still holds the old refresh token may then have to sign in again. How the read stops the app server so that a renewal under way can finish is in Codex read deadline.

JSON output

--json prints one JSON array of Claude profile rows, in display order. stdout holds only the JSON; warnings go to stderr. With no profiles it prints []. This is the stable interface for scripts, and the key table below is its specification. Keys are only ever added, never renamed or removed, and string values that name a state or kind may gain new values. There is no version field.

--json has no Codex rows, and does not read Codex at all. #2001 left it the bare array it was before, because scripts read it with .[] and .[0], often with stderr sent to /dev/null: a top-level object would make jq fail in those scripts and leave them reporting an empty result with no message. The Codex rows are in --summary-json, under codex. The same Claude rows are named profiles there; the arrays are identical.

With one profile:

[
  {
    "profile": "work",
    "account": "personal",
    "default": true,
    "leased_to": null,
    "live_in": null,
    "overflow": false,
    "overflow_blocked_until": null,
    "state": "ok",
    "source": "direct",
    "spend": "n/a",
    "session": {
      "label": "session",
      "used_percentage": 20.0,
      "resets_text": "2026-10-17T02:00:00Z",
      "resets_at": 1792202400
    },
    "session_limit": true,
    "week_all": {
      "label": "all models",
      "used_percentage": 30.0,
      "resets_text": "2026-10-22T09:00:00Z",
      "resets_at": 1792659600
    },
    "week_models": [
      {
        "label": "Fable",
        "used_percentage": 0.0,
        "resets_text": "2026-10-22T09:00:00Z",
        "resets_at": 1792659600
      }
    ],
    "stale": false,
    "error": null
  }
]

Each row has these keys:

Key Type Meaning
profile string Profile name.
account string or null The account whose login is live in the profile's directory: the profile's own name unless it hosts another account. The numbers belong to this account. null only for an excluded row.
default bool Whether this is the default profile.
leased_to string or null The directory this profile's login is lent to.
live_in string or null "~/.claude" when this profile's login is live in ~/.claude and its numbers were read from there; otherwise null. The key is always present, and at most one row has a non-null value. The value is always the literal ~/.claude, never the expanded home path.
overflow bool Whether the profile is marked as credit-backed overflow. Always present.
overflow_blocked_until integer or null Unix epoch seconds until which this profile is blocked after a spend limit, whether by the rotator for an overflow profile or by a step for any login; null when it has no active block. Always present.
state string One of the states. "excluded" for a profile in the auto-switch exclude list; such a row has source, account, session, week_all and error null. See Excluded profiles.
source string or null How the row was read: "passive", "direct" or "fallback"; see Reading source. A row that failed on every step has the source of its last attempt. null for a row that was never probed, such as an API-key row or a profile directory refused row. Always present, immediately after state.
spend string The spend status: "n/a", "ok", "limit_reached", "unknown" or "not_probed". Always present, immediately after source. "unknown" means a probe was asked for or needed and gave no reading; "not_probed" means usage credits are on and no spend probe was asked for (no --spend). Neither says anything about the spend limit. "n/a" does not mean that usage credits are off. Scripts should treat a value they do not know as "unknown".
session window or null The session: five_hour from a passive reading, the direct read or the usage request, or the Current session line from /usage. Always null for timeout and error, and when session_limit is false.
session_limit bool false only when a reading showed no session window; true otherwise, including rows that could not be read. See No session limit. Always present, immediately after session.
week_all window or null The all-models week: seven_day, or the Current week (all models) line. Kept as reported when the session is exhausted. Always null for timeout and error.
week_models array of windows Each usable rate_limits.model_scoped entry, or every other Current week (<model>) line, in the order given. Empty if none, and always empty for passive and direct rows.
stale bool true only when a measured reading is below the rotator's highest reading in a window, judged before the displayed figures are raised. false for every other row, including exhausted, failed, timeout, not_logged_in and API-key rows, and for every row when the rotate ledger is missing or cannot be read. Always present, including in --summary-json's profiles rows.
error string or null The reason for an error row; otherwise null, including a not_logged_in row whose direct read found no login to use.
raw object Only with --raw: {"stdout": "...", "stderr": "..."} from the attempt that gave the row, both empty for passive and direct rows; see Raw output. The key is absent, not null, without --raw.

A window is {label, used_percentage, resets_text, resets_at}. label is session for the session window, all models for the all-models week, and the model name as given (display_name, or the name /usage printed, for example Fable) for a model week. used_percentage is a number as read (not clamped). resets_text is the reset as received, an ISO 8601 time from the usage request or Claude's text from /usage, and null when there was none. resets_at is Unix epoch seconds, or null when there was no reset or it could not be resolved (see Probe method and What is read). JSON strings are not cleaned; they use JSON escaping.

Claude rows in scripts

There is no on_credits key. The live login is running on credits exactly when one row has live_in equal to "~/.claude", overflow equal to true, and either a state of "session_exhausted" or "weekly_exhausted", or a state of "ok" with session or week_all at 100%. This is the same test the footer uses:

amplihack profile usage --json | jq -r '.[]
  | select(.live_in == "~/.claude" and .overflow
           and (.state == "session_exhausted" or .state == "weekly_exhausted"
                or (.state == "ok"
                    and ((.session.used_percentage // 0) >= 100
                         or (.week_all.used_percentage // 0) >= 100))))
  | .profile'
login-aw

The weekly-only row from the table example reads:

{
  "profile": "weekly",
  "state": "ok",
  "session": null,
  "session_limit": false,
  "week_all": {
    "label": "all models",
    "used_percentage": 47.0,
    "resets_text": "2026-10-22T09:00:00Z",
    "resets_at": 1792659600
  }
}

Its other keys are left out here. To list the profiles with no session limit:

amplihack profile usage --json | jq -r '.[] | select(.session_limit == false) | .profile'
weekly
Codex JSON rows

Each row of codex in --summary-json is one Codex account, in the same order as the text rows. --json has no Codex rows. For the hhale, kkim and login-ag rows of the example:

[
  {
    "account": "hhale",
    "path": "/home/you/.codex-profiles/hhale",
    "state": "ok",
    "error": null,
    "windows": [],
    "credits": { "has_credits": true, "balance": 4200.0 },
    "plan_type": "team",
    "rate_limit_reached_type": null,
    "ordinary_usage_allowed": null,
    "read_at": "2026-11-06T19:09:00Z",
    "next_choice": false
  },
  {
    "account": "kkim",
    "path": "/home/you/.codex-profiles/kkim",
    "state": "timeout",
    "error": "timed out after 20s",
    "windows": [],
    "credits": null,
    "plan_type": null,
    "rate_limit_reached_type": null,
    "ordinary_usage_allowed": null,
    "read_at": "2026-11-06T19:09:00Z",
    "next_choice": false
  },
  {
    "account": "login-ag",
    "path": "/home/you/.codex-profiles/login-ag",
    "state": "ok",
    "error": null,
    "windows": [
      {
        "name": "secondary",
        "used_percent": 34.0,
        "window_minutes": 10080,
        "resets_at": 1794321000,
        "resets_at_rfc3339": "2026-11-10T14:30:00Z"
      }
    ],
    "credits": null,
    "plan_type": "pro",
    "rate_limit_reached_type": null,
    "ordinary_usage_allowed": true,
    "read_at": "2026-11-06T19:09:00Z",
    "next_choice": true
  }
]
Key Type Meaning
account string The directory name, or ~/.codex. Not cleaned; JSON escaping only.
path string The account directory as built (<root>/<name> or $HOME/.codex), not resolved through symlinks. Not cleaned.
state string "ok", "not_signed_in", "timeout" or "error"; see Codex states. Scripts should treat a value they do not know as "error".
error string or null For timeout, "timed out after <n>s"; for error, the reason; otherwise null.
windows array The windows reported, primary first. Always [] unless state is "ok".
windows[].name string "primary" or "secondary", the field it came from.
windows[].used_percent number or null As read, not clamped.
windows[].window_minutes integer or null The window length in minutes: 300 for five hours, 10080 for a week.
windows[].resets_at integer or null The reset as Unix epoch seconds, as received, even when it is out of range.
windows[].resets_at_rfc3339 string or null The same reset as an RFC 3339 UTC time ending in Z; null when there is no reset or it is out of range.
credits object or null {"has_credits": bool, "balance": number or null} when Codex reported credits; otherwise null. Always null unless state is "ok".
plan_type string or null The plan, cut to 200 characters and cleaned.
rate_limit_reached_type string or null Which limit Codex says is reached, cut to 200 characters and cleaned.
ordinary_usage_allowed bool or null As Codex reported it.
read_at string When the answer arrived, or when the read was given up, as an RFC 3339 UTC time ending in Z. Present on every row.
next_choice bool true on the one row with the <- next marker, false on the others.

Every key is present on every row; a value that was not reported is null. Percentages and balances are JSON numbers with a fractional part, such as 34.0; read them as floats. Server strings (plan_type, rate_limit_reached_type and the server's part of error) are cleaned before they are stored, so jq -r cannot print terminal escapes from them.

To print the account codex-pick's rule picks from the live readings:

amplihack profile usage --summary-json | jq -r '.codex[] | select(.next_choice) | .account'
login-ag

To list the Codex accounts that could not be read:

amplihack profile usage --summary-json | jq -r '.codex[] | select(.state == "timeout" or .state == "error") | "\(.account): \(.error)"'
kkim: timed out after 20s
mmoss: codex app-server exited (exit status: 1): error: unrecognized subcommand 'app-server'

Capacity summary

After the bar view or the table and their footer lines (running on overflow: and the others, then times: in the bar view and order:), profile usage prints a blank line and six summary lines. The summary is worked out from the rows of this run and the usage history; it runs no extra probe and makes no network call. With these rows, and a history going back six hours:

PROFILE  MARKS  STATE              SESSION  SESSION RESETS        WEEK  WEEK RESETS
review   -      ok                 5%       2026-10-30T19:00:00Z  10%   2026-11-03T09:00:00Z
work     *      ok                 20%      2026-10-30T20:00:00Z  30%   2026-10-31T09:00:00Z
team     -      session_exhausted  100%     2026-10-30T18:00:00Z  68%   2026-11-04T09:00:00Z
night    -      session_exhausted  100%     2026-10-30T18:00:40Z  85%   2026-10-31T02:00:00Z
scratch  -      not_logged_in      -        -                     -     -
spare    -      timeout            -        -                     -     -

weekly headroom      2.07 login-weeks of 4 (52%)
usable now           2 of 4 logins (session < 95% and weekly < 100%)
next session reset   2026-10-30T18:00:00Z  (night, team: +2 usable)
runway               ~9 h at the last 6 h rate (0.230 login-weeks/h)
resets in next 24 h  2026-10-31T02:00:00Z night +0.85; 2026-10-31T09:00:00Z work +0.30
unknown              2 profiles (no valid reading; excluded from all figures)
Line Meaning
weekly headroom The weekly capacity left across all logins with a valid reading, in login-weeks: one login-week is one login's whole weekly allowance. X login-weeks of N (P%), where N is the number of valid readings, X is the sum of (100 − week%) / 100 over them, and P is X / N as a percentage. Followed by [weighted: X' of T] only when some login with a valid reading has a weight other than 1.0; a weight for a profile that is not among them, such as a deleted one, does not count. With no valid reading: unknown (no valid readings).
usable now U of N logins (session < S% and weekly < 100%): how many logins with a valid reading can take work now, and the session threshold S in force. See Usable now.
next session reset The earliest session reset among logins stopped only by their session limit, and every such login whose reset falls within 60 seconds of it: <time> (<names>: +K usable), where K is the number of names. none when there is no such login. See Next session reset.
runway How long the weekly headroom lasts at the rate it was used over the last six hours, with the weekly resets of the next 24 hours added back: ~H h at the last 6 h rate (R login-weeks/h), beyond 24 h at the last 6 h rate (R login-weeks/h; lowest L login-weeks, with the resets below) when the headroom does not reach zero within 24 hours, or unknown. The 6 h is fixed text; the rate is per hour whatever the length of history used, needs at least 4.5 h of history, and is weighted. See Rate and runway.
resets in next 24 h Weekly resets due in the next 24 hours, each <time> <name> +<login-weeks restored>, soonest first, separated by ;. none when there are none.
unknown M profiles (no valid reading; excluded from all figures): the number of subscription profiles without a valid reading, 1 profile (…) for one and 0 profiles (…) for none. Their names are in the table and in summary.unknown. They are left out of every other line.

Times are UTC, YYYY-MM-DDTHH:MM:SSZ, whichever attempt gave the row. Percentages are whole numbers, login-weeks have two decimal places, the rate three, and the runway whole hours, rounded half away from zero. ~0 h means less than half an hour is left at that rate. Each label is padded with spaces to 21 characters, so the values start in one column. Names are cleaned the same way as in the table. The summary's layout is for people and may change; scripts should use --summary-json.

There is no summary with --json or --raw, or when no row is a subscription profile (for example when every profile is an API-key profile). With no profiles, the table form prints only the no profiles line.

Valid and unknown readings

The summary counts subscription profiles only. API-key profile rows are not logins in the summary and are not listed as unknown. An overflow profile is a subscription profile and is counted. A profile in the auto-switch exclude list is left out entirely: it is not in N, not in any sum and not on the unknown line, because it was not probed.

A row's reading is valid only when its weekly figure is known:

Row Reading
ok or session_exhausted with an all-models week Valid, at that week percentage.
weekly_exhausted Valid, at 100% even when no week percentage was read.
ok or session_exhausted without an all-models week Unknown.
A rotator probe that is exhausted but read no all-models week Unknown: the week is not taken to be full.
spend_limit, not_logged_in, timeout, unparsed, error Unknown.
The profile live in ~/.claude, when the login in ~/.claude changed during the probe Unknown: the numbers may belong to another account.

An unknown reading is never counted as 0% or 100%. It is left out of N, of every sum and of the history, and counted on the unknown line. Percentages are clamped to 0–100 first, and sums are kept in whole percentage points, so the figures do not drift: 16 valid readings whose week percentages add up to 1228 give (1600 − 1228) / 100 = 3.72 login-weeks and exactly 23.25%, shown as 23% and given in JSON as 23.3.

Usable now

A login with a valid reading is usable now when its week is below 100% and either its session is below the threshold or it has no session limit. A login has no session limit when its reading showed no session window, that is, when its session_limit is false; it is usable on its week alone. An idle session-limited login at 0% with no reset reads the same way, and is usable too. A valid reading whose session was not read for another reason, with session_limit still true, counts towards the headroom but not as usable, because nothing shows its session is below the threshold. The rotator applies the same rule to the readings it records.

Setting Values Default
--usable-session-pct <n> 1 to 100 none
AMPLIHACK_PROFILE_USAGE_USABLE_SESSION_PCT 1 to 100 95

The flag wins over the variable. A flag value out of range is a usage error (exit status 2). An empty variable counts as unset. A variable that is not a whole number from 1 to 100 prints one warning to stderr, showing the value escaped and cut to 32 characters, then uses 95:

warning: ignored AMPLIHACK_PROFILE_USAGE_USABLE_SESSION_PCT "most" (use 1 to 100); using 95

With the default, a session at 94% is usable and one at 95% is not. The line prints the threshold in force, for example 2 of 4 logins (session < 80% and weekly < 100%) with --usable-session-pct 80. The threshold affects only this line, the usable_now key and the usable count on the rotate status capacity line. It does not change the rotator's or auto-switch's thresholds.

Next session reset

The candidates are logins with a valid reading that are stopped by their session limit only: state session_exhausted, or a session at 100%, with a week below 100% and a known session reset time. A candidate without a reset time is left out. The line gives the earliest reset time and every candidate whose reset is within 60 seconds of it, by name, because probes of logins that reset together report times a few seconds apart. A reset time that has already passed is still shown; the next run reads the login again.

Rate and runway

The rate is how many login-weeks were used per hour over the last six hours. It is read from the usage history:

  1. The newest end is this run's readings. The oldest end is the oldest history entry no more than six hours older than this run that covers every login with a valid reading now: an entry written by profile usage (or an older entry without a writer), or a rotator entry that read all of those logins. A rotator entry that skipped a login, for example one running a session, is never the oldest end. Those busy logins are the ones being used, and leaving them out of the rate while their headroom still counts would make the runway far too long. Entries before the oldest end are not used.
  2. If there is no such entry, or it is less than four and a half hours older, there is too little history: runway unknown, and the rate and runway are null in JSON.
  3. Only logins with a valid reading at both ends count. A login profile usage could not read at the start, or one that is unknown now, is left out. Rotator entries between the two ends are used for the logins they read; a login missing from one of them only skips that step.
  4. For each login, the use is the sum of its rises in week percentage over the window. Its readings are taken in time order: the start, each later entry that read it, and this run. They are split into weeks at each weekly reset. A reset lies between two consecutive readings when the earlier reading's w_reset is at or before the later reading's time, or when the later reading's w_reset is more than one hour after the earlier one's, which is how a week that reset early shows. A fall in the week percentage is never a reset on its own, and when either reading has no w_reset nothing is inferred from a fall. Each week keeps a level: the login's percentage at the start for the first week, and 0 for each later week. A reading above the level is use and raises the level. A reading below the level is a stale reading when a later reading in the same week comes back to within 10 points of the level; it is skipped and adds nothing. Otherwise it is a fall that stays: the level drops to the new figure and nothing is added, and later rises count from there. A low last reading has nothing after it, so it lowers the level and adds nothing. A reading whose own w_reset is at or before the time it was taken belongs to a week that has ended and is not used, and neither is this run's reading of a login when it is a stale passive reading by the rule under Stale readings. For example, with a level of 50, a fall to 30 is stale when a later reading of the week is 40, and stays when the highest later reading is 39, which then counts 9 points of use.
  5. The rate is the sum of each login's use times its weight, divided by 100 and by the hours between the two ends. It is weighted; when every weight is 1.0 it equals the unweighted rate. It is never negative.

For example, on 5 November 2026 one login read 34% at 16:52 and 50% at 18:55. In between, a stale status-line figure of 38% reappeared five times between rising ones (40, 38, 40, 41, 38, 42, and so on), and once 46 appeared between 48 and 49. Each low figure is reversed by the next reading, so none is a reset or use, and the login's use over those two hours is 50 − 34 = 16 points. A login that reads 43, 29, 43, 29 and 43 with the same w_reset uses nothing. One that reads 60, 74, 30, 30 and 34 with the same w_reset uses 14 + 4 = 18 points: the fall to 30 stays, so it is not use, and the rise after it is. Release 1.2.97 counted every fall as a reset and each fall's whole lower figure as use: 269 points. Had the login read 90% at the start, reached 100%, reset to 0% and then read 12% now, its use would be (100 − 90) + 12 = 22 points.

On the same day, profile usage at 16:52 reported a rate of 0.483 and a runway of 7.5 hours. The start was a rotator entry at 10:53:20 that held every login read at 16:52. Under the rule above, three logins used 59 points over those 5.99 hours, a rate of 0.099 and a runway of 36.5 hours. Release 1.2.97 counted 289 points; most came from falls of 1 to 3 points counted as resets.

The plain runway (runway_hours in JSON) is the weighted headroom of this run divided by the rate. When the rate is zero, nothing was used over the window and the runway is unknown; JSON still gives the rate. Weights are 1.0 unless set, in which case the weighted and unweighted figures are the same.

The printed runway also allows for the weekly resets listed on the resets in next 24 h line. With none listed it is the plain runway. Otherwise the weighted headroom is taken down at the rate from now to each reset in turn and checked before that reset's login-weeks are added back; after the last one it runs on to 24 hours. If the headroom reaches zero on the way, the runway is the time it does, ~H h. If it does not, the line says beyond 24 h with the lowest weighted headroom on the way, because resets after 24 hours are not known. For example, a weighted headroom of 4.5 login-weeks at 0.35 an hour lasts about 13 hours on its own, but with resets of 1.0 at +4.5 h, +6.5 h and +9.5 h and 2.0 at +16.5 h it lasts beyond 24 hours, at its lowest 1.1 login-weeks at the 24-hour mark.

History written before stale readings were filtered (see Stale readings) may still hold them, and they affect the rate until they are more than six hours old. A low reading that a later one reverses has no effect. A stale reading at the start shifts that login's use by the difference between the stale and the true figure.

amplihack profile usage --help states the six-hour window, the four-and-a-half-hour minimum and the weighting.

Capacity weights

By default every login counts as one login-week. When accounts have different weekly allowances, for example a Max 20x plan next to Pro plans, set a weight for each login in <root>/.auto-switch.d/capacity-weights.json:

{ "team": 2.0, "scratch": 0.5 }

With that file, the first summary line above becomes:

weekly headroom      2.07 login-weeks of 4 (52%)   [weighted: 2.39 of 5.00]

The weighted headroom is the sum of weight × (100 − week%) / 100 over the valid readings, out of the sum of their weights T, which has two decimal places. The first figure stays unweighted. The rate, the runway and restores on the resets in next 24 h line are always weighted.

A profile has no settings file of its own, so weights are kept together in this one file rather than as a per-profile setting. There is no command to set weights; edit the file by hand. It is read once per run and never written by amplihack. The rules:

Case Result
No file, or no profile root Every weight is 1.0, with no message.
The profile root is a symlink, is not a directory owned by you, or is writable by other users Every weight is 1.0, with the warning below and the reason unsafe file. This is the same root rule as the usage history.
The file is a symlink, larger than 64 KiB, not owned by you, writable by group or others, not valid JSON, or not a JSON object Every weight is 1.0, and one warning goes to stderr: warning: capacity-weights.json ignored (<reason>); every weight is 1.0.
A value that is not a number, or not above 0 and at most 1000 That weight is 1.0, with one warning: warning: capacity-weights.json: weight for "<name>" ignored (use a number above 0 and at most 1000); using 1.0.
A name that matches no profile Ignored.

Weights are applied when the summary is worked out. They are never written to the history, so a change takes effect on the next run, for past entries too.

Summary JSON

--summary-json prints one JSON object instead of the bar view and summary. stdout holds only the JSON; warnings go to stderr. profiles is exactly the array --json would print in the same run. codex, after summary, holds the Codex rows; this is the only JSON form that has them. For the run above, with only the first of the six rows shown and no Codex accounts:

{
  "at": "2026-10-30T16:15:00Z",
  "profiles": [
    {
      "profile": "review",
      "account": "review",
      "default": false,
      "leased_to": null,
      "live_in": null,
      "overflow": false,
      "overflow_blocked_until": null,
      "state": "ok",
      "session": {
        "label": "session",
        "used_percentage": 5.0,
        "resets_text": "2026-10-30T19:00:00Z",
        "resets_at": 1793386800
      },
      "week_all": {
        "label": "all models",
        "used_percentage": 10.0,
        "resets_text": "2026-11-03T09:00:00Z",
        "resets_at": 1793696400
      },
      "week_models": [],
      "error": null
    }
  ],
  "summary": {
    "weekly_headroom_login_weeks": 2.07,
    "weekly_headroom_pct": 51.8,
    "weighted_headroom_login_weeks": 2.07,
    "usable_now": 2,
    "valid_readings": 4,
    "unknown": ["scratch", "spare"],
    "next_session_reset": { "at": "2026-10-30T18:00:00Z", "profiles": ["night", "team"] },
    "rate_login_weeks_per_hour": 0.23,
    "runway_hours": 9.0,
    "runway_with_renewals_hours": 9.0,
    "runway_beyond_24h": false,
    "lowest_room_login_weeks": 0.0,
    "weekly_resets_next_24h": [
      { "at": "2026-10-31T02:00:00Z", "profile": "night", "restores": 0.85 },
      { "at": "2026-10-31T09:00:00Z", "profile": "work", "restores": 0.3 }
    ]
  },
  "codex": []
}
Key Type Meaning
at string When the summary was worked out: after the window readings and before any spend probe, so --spend never makes it later.
profiles array The array of --json, unchanged.
summary object or null null when there are no profiles or no row is a subscription profile.
summary.weekly_headroom_login_weeks number Unweighted headroom, two decimal places. 0.0 with no valid reading.
summary.weekly_headroom_pct number or null Unweighted headroom as a percentage of valid_readings, one decimal place. null with no valid reading.
summary.weighted_headroom_login_weeks number Weighted headroom, two decimal places. Equal to the unweighted figure when every weight is 1.0.
summary.usable_now integer Logins usable now.
summary.valid_readings integer N, the logins with a valid reading.
summary.unknown array of strings Subscription profiles without a valid reading, by name.
summary.next_session_reset object or null {"at": <time>, "profiles": [<names>]}, as on the text line; null for none.
summary.rate_login_weeks_per_hour number or null Weighted rate, three decimal places: the rises of each login's week percentage within each week over the last 6 h, counted from the oldest entry in that window that covers every login valid now (step 1), times its weight, divided by 100 and by the hours covered. null when that entry is less than 4.5 h old, when there is none, or when no login has a valid reading at both ends. 0.0 or above. Unweighted when every weight is 1.0.
summary.runway_hours number or null Hours of weighted headroom at that rate, one decimal place, with no weekly reset added back; null when the rate is null or zero.
summary.runway_with_renewals_hours number or null Hours until the weighted headroom reaches zero with the resets of weekly_resets_next_24h added back at their times (see Rate and runway), one decimal place. Equal to runway_hours when no reset is listed. null when the rate is null or zero, or when the headroom lasts beyond 24 hours.
summary.runway_beyond_24h boolean true when some reset is listed and the weighted headroom does not reach zero within 24 hours at the rate. false otherwise, and when the rate is null or zero.
summary.lowest_room_login_weeks number or null The lowest weighted headroom in login-weeks over the next 24 hours at the rate, with the listed resets added back, two decimal places; 0.0 when it reaches zero. null when the rate is null or zero.
summary.weekly_resets_next_24h array Valid logins whose weekly reset is after now and no more than 24 hours away, and whose weighted restores (weight × week% / 100, two decimal places) is above 0, soonest first, then by name. Each is {"at", "profile", "restores"}.
codex array The Codex JSON rows, unchanged; [] with profile names given. Codex rows never count towards summary.

Numbers are rounded half away from zero only when printed; a value that is not finite is printed as null. Keys are only ever added, as for --json.

Times differ by place, on purpose: inside profiles, resets_at keeps its --json form, Unix epoch seconds, so the array matches --json byte for byte; at and every time in summary are ISO 8601 UTC strings ending in Z. The times in codex are as described under Codex JSON rows. To read the runway in a script:

amplihack profile usage --summary-json | jq '.summary.runway_hours'
9.0

With no profiles it prints {"at":"<time>","profiles":[],"summary":null,"codex":[...]}, with the Codex rows read as usual.

Usage history

The rate needs earlier readings, so profile usage and the rotator append one line per measured cycle to <root>/.auto-switch.d/usage-history.jsonl (mode 0600). Each line is one JSON object:

{"at":"2026-10-30T16:15:00Z","by":"usage","profiles":{"example":{"s":20,"w":30,"w_reset":"2026-10-31T09:00:00Z","observed_ago":18}}}
Key Meaning
at When the cycle was measured, UTC.
by Which command wrote the line: usage for profile usage, which reads every subscription login, or rotate for a rotator cycle, which records only the profiles it probed. Absent in lines written before this key existed; such a line, or one with another value, has no known writer.
profiles Profile name to reading, for valid readings only. Unknown readings are left out, not written as 0 or 100. Excluded profiles are never written, here or under unknown, and a name in the current exclude list is dropped from both on read, so older lines never count it.
s Session percentage, a whole number 0–100, or null when not read. session_exhausted is written as 100.
session_limit Written only as false, beside "s":null, when the reading showed no session window (see Usable now). Absent otherwise. A missing key, null, or false beside a session figure, reads as "not read".
w All-models week percentage, a whole number 0–100. weekly_exhausted is written as 100.
w_reset When the week resets, UTC, or null when not known.
observed_at When the figures were observed, UTC. For a fresh probe with no separate timestamp, this is the batch time. Older points may omit this field.
observed_ago Seconds from the observation to the line's at, written in place of observed_at for a point observed at or before the line's time.
unknown Names of the logins the writer tried and could not read, or whose reading was a stale reading, sorted. Absent when there are none. Never counted in a figure; a name that also has a reading is ignored on read.
Reading times in the history

The capacity summary and rate use the line's at for each reading. A row read directly or by claude was read during the run, so that holds. A passive reading was stored by Claude's status line earlier: up to AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS before the run started, 300 seconds by default and at most 3600.

A passive reading's age is measured from the start of the run, the time it was accepted at. profile usage takes at later, once every row's windows are in and before any --spend spend probe starts, so a slow claude fallback for one row never turns another row the table shows as read into an unknown one. The rotator takes one time for both, so for it the start of the run and at are the same. The rule is:

  • A passive reading at most 300 seconds older than the start of the run is recorded at the line's at. The recorded time is therefore later than the real one by at most 300 seconds plus the time the run took. For the rotator that is 300 seconds. For profile usage there is no fixed bound: each read of a profile may take up to its deadline (AMPLIHACK_PROFILE_USAGE_TIMEOUT_SECS, 120 seconds by default, 600 at most), a claude fallback gets a deadline of its own after a failed direct read, and fallbacks beyond the parallel limit wait for a free slot. A run of several minutes is ordinary. A run of 10 minutes gives an error of at most 15 minutes, about 6% of the 4.5 hours the rate needs at least.
  • A passive reading more than 300 seconds older than the start of the run is unknown, in the history and in the capacity summary alike: it is in no figure and no rate, it is listed under unknown, and the table still shows its numbers. This happens only when AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS is set above 300.

For a probe failure with a cause such as HTTP 429, profile usage and the rotator's live row can show dated history figures up to 300 seconds after observed_at. Candidate rows can show figures under the rotator's existing last good reading rule, up to five hours old. Their age uses the observation time when the history includes it. When the figures expire, the cause stays visible.

A row that could not be read is unknown in the same way, whatever step failed. That includes a row whose direct read failed, with or without a refresh not saved warning, and which reads error or timeout: it is never counted as 0% or 100% used. A row whose direct read failed but whose claude fallback gave a reading is that reading.

A line holds only times, profile names and whole-number percentages. It never holds an account, e-mail address, organisation, plan, credential, error text or anything Claude printed.

Who writes it:

Writer When
profile usage After the probes, when no profile names were given and --raw was not given. With or without --json and --summary-json.
The rotator After every cycle that measured usage, once its state lock is released. It records the profiles it measured, and lists as unknown the plan logins it did not probe: those skipped as busy (a session running, leased, hosting or parked) and those whose login has no usable trusted account evidence (no account). The entry therefore says how many it did not read. Such an entry is not used as the start of the rate, and rotate status does not take a runway from it (see Capacity line). The live login is recorded under its profile, and a login in ~/.claude that belongs to no profile is not recorded. A cycle that measured nothing writes nothing.

Both writers record only when all of these hold, and otherwise write nothing and print nothing about the history:

  • The profile root is a real directory, not a symlink, owned by you and not writable by other users.
  • Auto-switch is set up: <root>/.auto-switch.d/ exists and is a private directory of yours. It is never created by recording.
  • None of ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN or CLAUDE_CODE_OAUTH_TOKEN is set, because every reading might then show that credential's numbers. The rotator measures anyway and warns about the variable, but does not record.

A filtered profile usage run is not recorded either, because the gaps would make the rate wrong.

Writers take an exclusive lock on usage-history.lock beside it, trying every 50 ms for up to one second; the rotator's state lock is never held at the same time. Each line is written in one append; when the file's last line was cut short, for example by a full disk, a newline is written first so the new line stays whole. Under the lock, entries older than eight days are dropped: when the first line is more than an hour older than that or cannot be read, or the new line would take the file past 2,000,000 bytes, the file is rewritten atomically without entries older than eight days or lines that cannot be read, dropping the oldest entries until it is under 1,800,000 bytes. The bound is under 2 MiB (2,097,152 bytes) and holds the longest span a reader uses, the six hours of the capacity summary's rate window, at 128 lines an hour (768 lines). To fit, a line leaves out the full time of each point. When every point was observed at the line's own time, the points carry no time and the line says so with "observed_at_batch": true. Otherwise each point observed at or before the line's time gives its age in seconds as observed_ago. A line of 29 logins is then about 2.2 KiB whatever the mix of times, against 2.8 KiB with a full time on every point, so six hours fit under the low mark. A rewrite writes every kept line in this form. Readers give a point its time from observed_at, observed_ago or the batch flag, and read an older, longer line as before. The hour's slack means a full history is rewritten at most once an hour rather than on every cycle. If the rewrite fails while the new line would still pass the bound, nothing is appended. If it fails on a smaller file, the line is still appended, the trim is tried again on the next cycle, and one warning is printed: warning: usage history not trimmed.

A rewrite writes each kept line again in the current format, so it drops what a reader already ignores: lines that are not valid JSON objects or are over 64 KiB, profiles whose names fail the name rules, and unknown keys. It keeps every entry a reader would have returned, unchanged.

Readers built before the observed_at_batch and observed_ago keys read those points as having no observation time, which the stale check and the last-good reading depend on. During an upgrade or a rollback, install the new build on every host before the history is rewritten, or expect those readers to treat the points as unobserved until the line is older than their window (six hours at most). Readers with this change read every form the same, which the replay of the recorded histories in tests_usage_history_bound.rs checks.

A write that cannot finish never changes the command. Writers ignore SIGXFSZ only while the write runs (the earlier setting is restored afterwards, so child processes do not inherit it), and before an append or a rewrite they compare the length the file would reach with the process's file-size limit (ulimit -f). If it would pass the limit, nothing is written and the fixed warning usage history not updated (too large) is printed. Any other failed write, such as a full disk, is the same warning with its own reason, and a line cut short by a failed append is cut off again. profile usage prints the same reading and exits with the same status as it would without history, and a rotate cycle goes on.

Readers take the last 4 MiB of the file, and skip any line longer than 64 KiB, any line that is not valid JSON, any profile name that fails the name rules, any percentage outside 0–100 and any time more than 100 years from now. A missing s counts as null, and times with a UTC offset are read as the same instant in UTC. Unknown keys are ignored, so a newer writer's lines still read. When any line is skipped, one warning gives the count, so a corrupted history can be told apart from an empty one. Blank lines are not counted:

warning: 3 unreadable usage history lines ignored

Readers check the profile root as writers do. A missing history, or a missing .auto-switch.d/, is an empty history with no warning. A history that exists but is refused, because the root is not trusted, or the file is a symlink, is not a regular file, has another owner, has more than one link, has any group or other permission (its mode is not 0600), or cannot be opened or read, is also treated as empty, and one warning goes to stderr, from profile usage and from rotate status:

warning: usage history ignored (unsafe file)

Readers and writers accept exactly the same files, so a history that is read is also appended to. A history whose mode was changed by hand, to 0644 for example, is refused by both until it is set back to 0600.

The history never decides anything and never fails a command. When it cannot be read, the rate is unknown. When a line cannot be written (the lock stays busy for a second, the file or lock is a symlink, has another owner, more than one link or group or other permissions, or the write fails), one line goes to stderr, or to the rotate log for the rotator, and the exit status does not change:

warning: usage history not updated (lock busy)

The reason is one of lock busy, unsafe file, write failed or too large. Paths and system error text are not printed.

To clear the history, delete usage-history.jsonl and usage-history.lock. Nothing else reads them, and both are created again on the next recorded cycle. Until the history is four and a half hours old again, the runway is unknown.

Stale readings

A passive reading, from profile usage or the rotator, is the figure Claude's status line stored, and it can lag behind the account. A cached figure that reappears after a higher one would show the week falling and rising again. So before a line is written, under the writers' lock, each passive reading in it is compared with that login's newest reading in the history, and is stale when any of these holds:

Rule Example
Its w_reset is at or before the line's at, so its week has ended. This applies even when the history holds no reading of the login. Line at 2026-11-05T18:02:00Z, passive w_reset 2026-11-05T18:00:00Z.
Its w_reset and the recorded one are both known and within one hour of each other, so it is the same week, and its w is lower than the recorded w. Recorded w 50, passive w 38, both resetting at 2026-11-10T09:00:00Z.
Its w_reset is more than one hour earlier than the recorded one, so it belongs to an earlier week. Recorded w_reset 2026-11-10T09:00:00Z, passive w_reset 2026-11-03T09:00:00Z.

A stale reading is not written. In its place the line holds that login's newest recorded reading (its s, w, w_reset and observed_at), so the login stays in the line. A stale status-line reading belongs to a login in use. Leaving it out can underestimate usage. A profile usage line at the start of the rate would leave it out of the rate, and rotate status would say the rotator cycle left a login out and leave its headroom out of the capacity: line. The recorded figure adds nothing to the rate, since the week has not risen above it, and the true figure is at least that high, because within a week it only rises.

The recorded reading is used only while its own week has not ended at the line's at. When it has, or when the history holds no reading of the login, nothing known is left to write: the login is listed under unknown, as for a reading that failed. This happens only under the first rule.

A passive reading equal to or higher than the recorded one in the same week is written. A reading taken during the run, directly or by claude, is never treated as stale, and nor is a passive reading whose own w_reset is unknown. When only the recorded w_reset is unknown, or the history holds no reading of the login, only the first rule applies. The reset rule of the rate covers the rest.

The newest reading of each login is looked for in the last 256 KiB of the history only. When that part cannot be read, the line is not written and the write failed warning above is given; the reading is never written unchecked. The filter changes what is recorded. In the same run, the table, the headroom and usable count of the summary, and the auto-switch readings still use the reading; the rate does not (step 4 of Rate and runway). No message is given when a reading is replaced or left out. Lines already in the history are not rewritten.

Refreshing auto-switch readings

Direct request and text readings from profile usage and the rotator are recorded through the same account-attributed auto-switch storage, so candidate selection can use them on later passive reads. Stored readings now include an optional week_models list. Existing usage files without that field remain readable. Passive reconstruction is read-only. Nothing is recorded, and the output is the same, unless all of these apply:

  1. Auto-switch is set up: its effective setting is on, or <root>/.auto-switch.d/ exists. Otherwise nothing is created, and without --json one line goes to stderr: note: auto-switch not set up; usage record not updated.
  2. None of ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN or CLAUDE_CODE_OAUTH_TOKEN is set to a non-empty value. With one set, claude may report the usage of that credential rather than the profile's login. The warning names the variable, never its value: auto-switch: ANTHROPIC_API_KEY is set; usage record not updated. Whether or not auto-switch is set up, and with or without --json, one more line goes to stderr before probing, because every row may show that credential's numbers: warning: ANTHROPIC_API_KEY is set; claude may report that credential's usage, not each profile's.
  3. The global state lock can be taken within the usual wait. Otherwise: auto-switch: state is busy; usage record not updated.
  4. No swap is in progress (no journal.json). profile usage never runs recovery. Otherwise: auto-switch: swap in progress; usage record not updated.

Then, under the lock, for each row:

  • Only ok, session_exhausted and weekly_exhausted rows are recorded. spend_limit, not_logged_in, timeout, unparsed and error rows are not.
  • Rows with source passive are not recorded: they came from usage.json, and recording them again would keep an old reading fresh.
  • A row live in ~/.claude is recorded against its own profile and account. It is not recorded if the login in ~/.claude changed during the probe.
  • The ledger is read again. If the account live in the profile's directory changed while the probe ran, the row is not recorded: auto-switch: profile "work" changed accounts during the probe; its usage was not recorded.
  • The reading goes to the account live in the directory (the row's account), not necessarily the profile with that name.
  • session becomes five_hour and week_all becomes seven_day. Each model week is stored with its label, percentage, reset and observation time. New observations replace the previous observation of the same model; an omitted model keeps its unexpired observation and its original age. Status-line rate_limits.model_scoped entries also update model weeks, using display_name, used_percentage and resets_at, rather than the request response's utilization field. Missing model data clears nothing. A usage-limit failure updates the session window while preserving each unexpired model observation and its original observation time. Each retained window must pass the same checks as a status-line reading: a finite percentage, clamped to 0–100, and a resets_at from one day before to eight days after now. A window with no usable resets_at can inform the immediate direct decision but cannot be retained as an unexpired passive observation.
  • If no session, all-models or model window passes, nothing is recorded for that account. Omitted windows are kept from the stored reading while their reset times are still in the future.
  • A row with no session limit follows the same rule: its stored five_hour is kept while its reset time is still in the future, and dropped once it has passed. A 0% session line with no reset may come from figures claude stored earlier, so it does not override a live session window. A login that has just stopped reporting a session window can therefore stay session-exhausted until the old reset passes, which is at most five hours. No new five_hour is recorded for such a row.
  • The reading has observed_at set to the time it was read, and never later than the time it is recorded. For profile usage that is when every row's windows were in, before any --spend probe; for the rotator it is when the read ended. The checks above still use the time of recording.
  • source is direct for a row read from the usage endpoint and statusline for a row read through claude (the get_usage request or /usage). The reading is merged with the stored one the usual way.

usage.json is written once, atomically, at the end. The 300-second quiet period after a swap does not apply: a direct read or fallback asks under the live login directly, rather than waiting for a status-line update. Any failure while recording prints one auto-switch: warning to stderr and the exit status stays 0.

After usage.json is written, profile usage also updates the capacity file when the switch is on.

On platforms without auto-switch (Windows and other non-Unix), there are no lease marks, account is always the profile's own name, and nothing is recorded or noted.

Exit status and refusals

Status When
0 The probes ran, whatever states they produced, or there are no profiles. Rows in state excluded, listed when no names are given, do not change it. Codex rows never change the status, whatever their states. Recording failures, usage history failures and weight warnings do not change it.
1 Setup failed: Docker is active, the profile root is invalid, or a name is invalid or does not exist. Printed as error:/hint: like other errors. Nothing is probed. A claude that cannot be found is not a setup failure: only rows that need a fallback read error with claude not found. Also 1 when any name given on the command line is in the auto-switch exclude list: each is refused with <name>: excluded (in auto-switch exclude list); not probed (amplihack profile auto-switch exclude), the other names are probed, recorded and printed first, and the status is then 1. See Excluded profiles.
2 Command-line usage error, such as --timeout-secs 0, --usable-session-pct 101, --summary-json with --json, --raw, --table or --utc, or --table with --json.

With no profiles, the bar view and --table print no profiles; create one with `amplihack profile add <name>` followed by the Codex block, the JSON form prints [], and the summary JSON form prints {"at":"<time>","profiles":[],"summary":null,"codex":[...]}.

--table with --json, and --utc with --json or --table, are usage errors (status 2): the second flag would have no effect.

Like profile run, usage is refused when Docker is activated through the environment (AMPLIHACK_USE_DOCKER), before anything is read or spawned.

Privacy

  • No request is ever made with an excluded profile's token. profile usage and profile verify never open its .credentials.json. The rotator reads that file locally, in memory, only for the byte comparison of rule 3, and writes it only for the write-back of a move off an excluded live profile.
  • Identity checks for an excluded folder use its local account and stored record only. The rotator's local proof of an excluded live login reads the ledger, ~/.claude.json and the record, and may compare two credential files byte for byte in memory. It never sends the token. The reason given when an excluded folder is skipped names no path, e-mail address or account identifier.
  • A profile's .credentials.json is read, in memory only, for its direct read, and written only after a token refresh. Its contents are never printed, logged, stored elsewhere or passed to a child process.
  • Tokens appear only in the Authorization header of the usage request and in the body of the refresh request. They are never in a URL, a command line, the environment of a claude child, the table, the JSON, --raw output, usage.json, the rotate ledger or log, a journal, a tracing event or a panic message. The types that hold them print <redacted> when debug-formatted.
  • Direct read failures are fixed text. A response body other than a 200's is never read, and no body is ever printed.
  • For an account with usage credits on, --raw prints only the shape of extra_usage: its type, its top-level key names with every character outside A-Za-z0-9_.- replaced by ?, and bool and null values. A string or number from the answer is never printed, apart from the fixed words and the numbers 0 and 1 listed for is_enabled, so no e-mail address, account or organisation identifier, currency or amount appears. The shape is kept in memory only, and is never in the JSON, a file or the rotator's output.
  • A spend probe, run only with --spend, is a claude -p /usage run like the fallback's: no token is in its command line or environment, and its output is never printed or stored.
  • Claude's text appears only with --raw. Without it, it is dropped after parsing and never stored, logged or recorded. --raw prints Claude's text as it is, so it can include account details such as an e-mail address or organisation name. Read it before you paste it into an issue or chat.
  • Error reasons are fixed text. Messages contain profile names, states, percentages and times only, never token values, e-mail addresses or organisation IDs. account and leased_to are profile names.
  • The usage request is a fixed line with no profile name, path, e-mail address or token in it. The system line claude prints when it starts (its working directory, session id and tool paths) and any response.error message are never parsed into a message or stored; they appear only in --raw output, and the rotator never collects them.
  • For logins in ~/.claude, the only new text is the literal label ~/.claude. Account uuids, e-mail addresses, the rotator ledger's other fields and credential paths are never printed. To find the live profile, credential files are only checked for existence, without following symlinks.
  • The capacity summary, --summary-json's summary object and the usage history contain profile names, whole-number percentages, counts and times only. They never use the row's account, and nothing Claude printed reaches them, even when its output includes an e-mail address.
  • The probe sandbox never reads, copies or links .credentials.json, and puts no credential in bwrap's arguments or environment. Its note names a reason only, never a path or a value.
  • prune-probe-logs prints paths and counts only, never what a log contains.
  • The Codex read opens no file inside a Codex account directory, including auth.json and config.toml, and passes no API key to the Codex app server. Its rows hold directory names, paths, percentages, times, plan types and error reasons cut to 200 characters; nothing from them is stored.

Prune probe logs

amplihack profile prune-probe-logs [--dir <dir>] [--dry-run]

Usage probes from amplihack versions before the probe sandbox wrote one session log per probe into the shared projects folder, under the folder for the directory amplihack ran in. On a busy host that is thousands of files, and every later /usage read them all. This command removes those logs. It is never run automatically.

Flag Effect
--dir <dir> Folder to clean. Default $HOME/.claude/projects/<encoded home>.
--dry-run Print each matching file and delete nothing.

The encoded home is $HOME with every character outside A-Z, a-z, 0-9 and - replaced by -: /home/you becomes -home-you. The default needs HOME to be set to an absolute path.

What is read. Only files directly in the folder whose names end in .jsonl. Subfolders are not entered. A symlink is never followed and is kept. A file larger than 1 MiB is kept without being read.

What is removed. A file is removed only when all of these hold:

  1. Every non-empty line is a JSON object with a string type.
  2. Every type is user or one of the entries a /usage run writes around it: session-owner, queue-operation, attachment, system, last-prompt and cost-state. Any other type keeps the file: assistant, and the mode, permission-mode and file-history-snapshot entries that /login and typed sessions write. A queue-operation or last-prompt entry can hold a queued or last typed prompt, so it counts as probe-only only when its text field (content or lastPrompt) is missing or is the string /usage, after trimming whitespace. Any other value keeps the file.
  3. Exactly one user entry is the /usage command: its message.content is a string made of <command-name>/usage</command-name>, then optionally <command-message>usage</command-message>, then optionally an empty <command-args></command-args>, with only whitespace between and around them.
  4. Every other user entry is one of:
  5. the caveat: isMeta is the JSON value true and the content is one <local-command-caveat>…</local-command-caveat> element;
  6. the command's output: the content is one <local-command-stdout>…</local-command-stdout> or <local-command-stderr>…</local-command-stderr> element.

A file is kept when it has a typed prompt, content that is an array (a tool result, for example), a second command, any other command such as /login, an isMeta that is not the boolean true, a line that is not a JSON object, or when it cannot be read. When in doubt, the file is kept.

A log written by a probe looks like this, one JSON object per line, with fields the rule does not read left out:

{"type":"session-owner"}
{"type":"queue-operation"}
{"type":"attachment"}
{"type":"user","isMeta":true,"message":{"content":"<local-command-caveat>The command below was run directly in Claude Code…</local-command-caveat>"}}
{"type":"user","message":{"content":"<command-name>/usage</command-name>\n            <command-message>usage</command-message>\n            <command-args></command-args>"}}
{"type":"system"}
{"type":"last-prompt"}
{"type":"cost-state"}

Output. With --dry-run, one matching path per line on stdout:

"/home/you/.claude/projects/-home-you/0b7c….jsonl"
"/home/you/.claude/projects/-home-you/1f3a….jsonl"

Without it, one line:

removed 2467, kept 312

kept counts every .jsonl file in the folder that was not removed, including files that could not be removed. Every path, in --dry-run lines, warnings and errors, is printed in double quotes, with control characters escaped. No log content is ever printed, in output or in errors. A file that cannot be removed is reported on stderr and counted as kept:

warning: could not remove "/home/you/.claude/projects/-home-you/0b7c….jsonl": Permission denied (os error 13)
Exit status Meaning
0 The folder was read. Files that could not be removed do not change it.
1 No --dir and HOME is unset, empty or relative; or the folder does not exist or cannot be read.
2 Usage error.
error: prune-probe-logs needs an absolute HOME, or --dir
error: no such directory: "/home/you/.claude/projects/-home-you"

A session that has so far run only /usage matches the rule, including an interactive one still open. Run --dry-run first, and prune while no interactive claude session is running in your home directory. See Remove logs left by old usage probes.

Configuration

Item Value
AMPLIHACK_CLAUDE_PROFILE_ROOT Profile root. When set and non-empty it must be absolute, and it overrides the saved root. An empty value counts as unset. See Profile root.
~/.amplihack/profile-root The saved profile root: one absolute path and a trailing newline (mode 0600). Written by amplihack profile root <dir> and by the first profile add. Used when AMPLIHACK_CLAUDE_PROFILE_ROOT is unset or empty.
~/.amplihack/rotate-root The root the most recent profile rotate start used, in the same format. Read by rotate status and rotate stop. See Rotate root record.
<root>/.auto-switch.d/rotate/root The root a rotator started with, written by rotate start next to the pid file. Informational.
Default root ~/.amplihack/claude-profiles/, used when neither the variable nor the saved root is set.
AMPLIHACK_CLAUDE_PROFILE Profile name a launch passes to its children so nested launches use the same profile. Set by amplihack on the child process; may also be set by hand. Empty means unset. See Resolution and environment.
<root>/<name>/ Profile directory (mode 0700 on Unix; Windows uses its inherited ACL).
<root>/<name>/{projects,file-history,session-env} Symlinks to ~/.claude/<same name>. See Shared session directories.
<root>/<name>/<dir>.pre-share-<YYYYMMDDTHHMMSSZ> What a migration of <dir> left behind. Never deleted automatically.
<root>/<name>/.no-shared-sessions Opt-out marker. When present, any file type, the profile's session directories are never linked or migrated. See Preconditions.
Root directory Created with mode 0700 on Unix; Windows uses its inherited ACL. A symlinked root is refused. An existing custom root is trusted input.
<root>/.default Pointer file: only the profile name (mode 0600 on Unix, max 256 bytes). Windows uses its inherited ACL. Written by creating a new temp file (create_new, never through a symlink) and renaming it over the pointer.
AMPLIHACK_CLAUDE_AUTO_SWITCH 1 turns auto-switch on and 0 turns it off for this process and its children, overriding <root>/.auto-switch. Empty means unset. See Toggle and precedence.
<root>/.auto-switch Auto-switch settings. See Settings file.
<root>/.auto-switch.d/ Auto-switch state. See State directory.
AMPLIHACK_ROTATE_AUTOSTART 0/off stops launches from starting the rotator, and 1/on lets them, overriding <root>/.auto-switch.d/rotate/autostart. Empty means unset. See Rotate autostart.
AMPLIHACK_RECIPE_RUN_ID Set by amplihack recipe run for its steps. When it is set and non-empty, a launch never starts the rotator. See Rotate autostart.
INVOCATION_ID Set by systemd for the processes of a unit. A rotate watch that sees it non-empty, and runs directly in a service as described in step 2 of Owner unit name, records itself as the rotation owner. A shell in a .scope that inherited it does not.
<root>/.auto-switch.d/rotate/owner The owner marker. While it exists, launches do not start a rotator. Removed only by rotate owner clear.
AMPLIHACK_USAGE_LIMIT_WAIT true or 1 turns the usage-limit wait on, false or 0 off. Outranks recipe.usage_limit_wait in config.toml. See Usage-limit wait settings.
AMPLIHACK_USAGE_LIMIT_MAX_WAIT_SECS No longer read: a usage-limit wait has no length setting. While the wait is on, a step that finds it exported prints a warning saying so. See Usage-limit wait settings and A wait has no length setting.
CODEX_PROFILES_ROOT Directory whose subdirectories are the Codex accounts profile usage reads; default $HOME/.codex-profiles. Empty means unset. See Which accounts are read.
CODEX_BIN The Codex program profile usage runs as <bin> app-server; default codex, found through PATH. Like PATH, it decides which program runs. Empty means unset. See Live read.
AMPLIHACK_CODEX_USAGE_TIMEOUT_SECS Seconds each Codex account's live read may take, 1 to 300; default 20. See Codex read deadline.

Seeding

add calls the store's seed_shared_assets, which copies from the source $HOME/.claude into the new profile by value. The allowlists are fixed constants:

Constant Contents
SHARED_ASSET_FILES CLAUDE.md
SHARED_ASSET_DIRS agents, commands, output-styles, rules, skills
SHARED_SETTINGS_KEYS top-level settings.json keys: alwaysThinkingEnabled, attribution, cleanupPeriodDays, hooks, includeCoAuthoredBy, language, model, outputStyle, permissions, respectGitignore, spinnerVerbs, statusLine (12 keys)

Rules:

  • add omits exactly skills/synced (Claude Code's per-account skill cache) and skills/.trash (deleted skill state), relative to $HOME/.claude. The descriptor-relative copy used on Unix and the path-based copy used on other platforms both skip these paths before examining their type, opening them, creating destination entries, descending or counting towards the copy limit, so neither an excluded entry nor any of its descendants consumes the budget. Their source contents remain intact; Claude Code syncs account skills again for each login.
  • Exclusions use exact, case-sensitive path components. User-owned skills continue to be copied, with their file contents preserved. Names elsewhere, including agents/synced, skills/custom/.trash and skills/custom/synced, follow the usual copy rules. The allowlists above are otherwise unchanged.
  • settings.json is parsed and only SHARED_SETTINGS_KEYS are written to the profile's settings.json. If nothing survives the filter, no file is written. env, apiKeyHelper and all unknown keys are dropped.
  • amplihack install (user scope) refreshes the hooks in every profile's existing settings.json (issue #1661): it applies the same hook update as for ~/.claude/settings.json, so amplihack's entries are replaced and all other keys and hooks are kept. Only real profile directories directly in the root are visited; the file must be a regular file owned by the user (never a symlink), is rewritten atomically with mode 0600 only when it changes, and is never created. A file that cannot be read, parsed or written is reported and skipped; the install still succeeds.
  • The same pass writes the dangerous-command deny entries into each profile's settings.json (issue #2589), so one refusal costs the profile both the hooks and the deny rules. A profile that is skipped is reported on stdout as Profile <name>: settings.json not refreshed (<reason>), one line per profile. A failure of the root itself is reported once for all of them, as Profiles: settings.json not refreshed (<reason>): the plural names the root rather than any profile, because no profile was reached. It covers a root that cannot be resolved, one that is a symlink and one that cannot be listed. The policy section printed later in the same install names that failure again on stderr, under the label managed profiles, and drops its Claude Code line to the partial form. See A profile root that cannot be read. A root that does not exist is not a failure and is not reported.
  • Before it opens any profile's settings.json, the refresh checks the hooks path it is about to write (issue #1699). It refuses the whole refresh when the amplihack-hooks binary does not exist or is not a regular file (a symlink to a regular file is accepted). It also refuses it, wherever the binary lies, when $HOME is not the account's home directory from the passwd database and the profile root is outside $HOME: such a HOME is a scratch one, whether under /tmp or under a work directory such as ~/.amplihack/work, and the profiles belong to the account. This check is skipped when the account has no passwd entry, and on Windows. Otherwise it refuses when the binary's canonical path lies under a temporary directory (/tmp, an absolute $TMPDIR, or the platform temp dir), unless the profile root lies both under $HOME and under a temporary directory. That exception is the layout of an isolated test install, where HOME and the profile root are both temporary. Two cases are refused in particular: a test or scratch install with a throwaway HOME that inherited a real AMPLIHACK_CLAUDE_PROFILE_ROOT (for example HOME=~/.amplihack/work/x/home amplihack install), and a real install whose hooks binary is a temporary build (deploying the binary failed, so install fell back to a source binary such as one named by AMPLIHACK_AMPLIHACK_HOOKS_BINARY_PATH under /tmp). $HOME unset also refuses a temporary hooks path. The path as written is checked as well, so a symlink placed in a temporary directory is refused even when it points elsewhere. A refusal writes nothing; each profile is reported with one line, and the install still succeeds:
Profile work: settings.json not refreshed (HOME /home/user/.amplihack/work/x/home is not the account's home /home/user; profile root /home/user/.claude-profiles is outside HOME)
Profile work: settings.json not refreshed (hooks binary /tmp/.tmpQ3x9/home/.local/bin/amplihack-hooks is under temporary directory /tmp; profile root /home/user/.claude-profiles is outside HOME)
Profile work: settings.json not refreshed (hooks binary /tmp/build/amplihack-hooks is under temporary directory /tmp; profile root /home/user/.claude-profiles is not under a temporary directory)
Profile work: settings.json not refreshed (hooks binary /nonexistent/amplihack-hooks does not exist or is not a regular file)

Paths are canonicalised and compared component-wise, so /tmpfoo is not under /tmp. The ~/.claude/settings.json registration and statusLine are not affected. The second line appears when no passwd home is known; otherwise a temp HOME gets the first. If you run with HOME set to a directory other than your account's home on purpose, keep the profile root under that HOME, or set HOME back before amplihack install. If your real HOME is under /tmp and your profile root is outside it, move the root under HOME (see Root command) and run amplihack install again; changing TMPDIR does not help. If the hooks binary is a temporary build, fix the deploy failure that install reported, or point AMPLIHACK_AMPLIHACK_HOOKS_BINARY_PATH at a binary outside the temporary directories, and run amplihack install again. - On Unix, directories are created 0700 and files 0600; Windows uses inherited ACLs. Files use create_new (O_EXCL on Unix), so nothing is overwritten and no destination symlink is followed. - The 12-key list is kept in sync with the code by tests_docs_sync.rs, which checks both directions (every constant key is documented here and in the how-to guide, and no extra key is documented). - A symlinked source root fails with SymlinkRefused. Nested symlinks and special files (FIFOs, sockets, devices) are skipped. On Unix the source root is opened exactly once with O_RDONLY|O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC and that descriptor anchors the whole copy. The five allowlisted directories, CLAUDE.md and settings.json are opened with openat(root_fd, name, ...) and O_NOFOLLOW, never by absolute path, so replacing ~/.claude (or any ancestor) with a symlink after the anchor is taken cannot redirect the copy: the descriptor still pins the original directory. Ancestors of the root are resolved once, at anchor time. Each directory is opened with O_NOFOLLOW|O_DIRECTORY and entries are read and stat'ed relative to it (openat/fstatat with AT_SYMLINK_NOFOLLOW), so a directory swapped for a symlink during the copy is never followed. Files are opened O_NOFOLLOW and O_NONBLOCK, verified as regular files with fstat on the opened descriptor, and read through that same descriptor with a bounded read. Entry names must be a single path component. A missing CLAUDE.md or settings.json is skipped. Only the final component of the root is no-follow: a symlinked ancestor of ~/.claude is resolved normally, once. Windows opens source files with FILE_FLAG_OPEN_REPARSE_POINT and rejects reparse-point handles; its path-based directory traversal still permits same-user ancestor/directory races. Other non-Unix platforms keep the path-based copy without descriptor-relative hardening. - A missing ~/.claude source produces an empty profile. An existing source that is not a directory fails the add and rolls back the new profile. - The profile root cannot be inside the shared source tree. This is checked before the root is created, including for missing path suffixes, to prevent recursive seeding. - Caps: nesting is limited to 16 levels, the recursive shared-asset copy to 5,000 entries in total across all five allowlisted directories, each file to 64 MiB, and settings.json to 1 MiB; exceeding a cap is an error. The entry budget is shared across directories, rather than reset for each directory, and counts directory entries as well as files. More than 5,000 entries beneath skills/synced alone therefore do not prevent profile creation; more than 5,000 included entries still do. - An entry-limit error names the folders that spent the budget, largest charge first, for example more than 5000 entries; charged before stopping: "skills/vendored" 1500, "agents" 1400, "commands" 1300, and 3 more. Because the budget is aggregate, the folder holding the entry that overruns it is usually not the folder that spent it, so the error names the spenders rather than that one. Each entry is charged to the folder holding it, cut to the first two components of its path relative to $HOME/.claude, so the error points at one subtree of one allowlisted directory, which the user can move or delete. At most three folders are named and the rest are counted. Every number is exactly what that folder had charged when the copy stopped at the limit. A folder name below the top level comes from the source tree, so it is quoted, escaped and cut at 120 characters. - Special files are skipped without being opened, so a FIFO cannot block the copy. - Excluded entirely: .credentials.json, .claude.json, history*, sessions, todos, statsig, shell-snapshots, ide, and every other entry not on the allowlists (so plugins and MCP server settings are not carried over). projects, file-history and session-env are not copied; they are linked after the add (see Shared session directories). - Invalid settings.json yields InvalidSharedSettings. A seeding error removes the private staging directory so no profile is published; if cleanup also fails, the error reports both failures (never a pre-existing profile). - Values are never logged; messages contain paths and counts only. - No sync after creation: later edits to ~/.claude do not update profiles. The three shared session directories are links, not copies, so they are always current.

Shared session directories

Every profile shares one session store with ~/.claude. Logins stay per profile. See the how-to for a walkthrough.

Shared names

Constant Contents
SHARED_SESSION_DIRS projects, file-history, session-env

The canonical root is $HOME/.claude (the same shared_assets path seeding reads). The canonical directory for a name is <canonical root>/<name>. In each profile, <root>/<profile>/<name> is an absolute symbolic link to it. The link target is always the canonicalized canonical root joined with the constant name; no other input reaches it.

file-history/ and session-env/ hold one entry per session id, and --resume reads them, so they are shared with projects/. No other directory is shared. .credentials.json and .claude.json are top-level files of the profile directory, outside all three names, so neither rotate nor auto-switch can reach the shared store when it moves a login.

Entry point

The module is profile::shared_dirs; every item is pub(super).

pub(super) const SHARED_SESSION_DIRS: [&str; 3] = ["projects", "file-history", "session-env"];

pub(super) enum Deferred { LiveSession, LivenessCheckFailed, LivenessUnknown, Raced }

pub(super) enum Mode { Migrate, LinkOnly(Deferred) }

pub(super) fn ensure_shared_session_dirs(
    profile_dir: &Path,
    profile: &ProfileName,
    canonical_root: &Path,
    mode: impl FnOnce() -> Mode,
) -> Report;

pub(super) fn ensure_for(store: &ProfileStore, name: &ProfileName);
  • ensure_shared_session_dirs never returns an error. Every problem becomes a warning in the Report.
  • mode is called at most once, and only when a name is a real directory. When every name is already a correct link it is not called, so no /proc scan happens.
  • ensure_for picks the mode from liveness (below), then prints the report to stderr. It prints nothing when the report is a no-op. It never writes to stdout, so switch output and every --json output are unchanged.

Liveness comes from the auto-switch /proc scan for a process with CLAUDE_CONFIG_DIR=<root>/<name>. In doubt nothing is migrated:

Scan result Mode
No such process Migrate
A matching process, or the scan sees everything as running LinkOnly(LiveSession). The scan decides per profile: a Claude or amplihack executable whose environment cannot be read defers the migration only for a profile its arguments name, and one unreadable process does not defer every profile. See Leases.
The scan failed (Linux) LinkOnly(LivenessCheckFailed); the error is logged at debug level and the next call retries
Unsupported (every Unix except Linux) LinkOnly(LivenessUnknown)

Deferred::Raced is never passed in; the helper sets it itself (see the state table).

Report has one list per outcome: linked, already_ok, migrated, deferred (with its Deferred reason), conflicts and warnings, plus unsupported: bool. Each name appears in exactly one of linked, already_ok, migrated, deferred or a warning.

Call sites

Caller When Mode
ProfileStore::add After the profile is published. Also covers profiles that rotate's adopt creates. The linked line is not printed; only warnings, and the not-supported warning. Migrate (a new directory has nothing to migrate)
profile switch <name> After the pointer is written. from liveness
profile login <name> Before claude is spawned. from liveness
Launch with a profile (--profile, inherited AMPLIHACK_CLAUDE_PROFILE, default pointer, profile run, usage-limit reruns) In the pre-spawn check, after the directory check passes and while holding the launch hold. from liveness
profile rotate, rotate cycles After a swap that ran, for to and from, once the cycle is recorded and the auto-switch lock is released, so a long merge never stalls a launch. Not after --dry-run or a refused swap. from liveness

Auto-switch has no call site. Its in-session swap moves only the top-level login files, and a usage-limit rerun is a launch, so verify_launch_profile_dir in the pre-spawn check covers it. The swap code of rotate (rotate/swap.rs) and of auto-switch is unchanged.

Preconditions

Checked in this order. The first one that fails ends the call with nothing changed.

Condition Result
<profile>/.no-shared-sessions exists (any file type; symlink_metadata, not followed) No-op, debug log only.
Not a Unix system No-op with Report.unsupported set. ProfileStore::add prints the not-supported warning; every other caller logs it at debug level.
$HOME unset (shared_assets is None) No-op, no message.
~/.claude doesn't exist No-op, debug log only. ~/.claude is never created.
~/.claude is a symlink or not a directory Warning, no-op.
~/.claude is not owned by the effective user, or is writable by others, or is group-writable when the group is not your own private group (a group named like your user with no listed members, the usual layout with a umask of 002) Warning, no-op.
The profile directory is not owned by the effective user, or mode & 0o077 != 0 (any group or other bit; the same mask as the pre-spawn check) Warning, no-op.
The profile directory is the canonical root (canonicalized) No-op, debug log only. ~/.claude/projects is never replaced with a link.
The profile directory is inside the canonical root (canonicalized, compared by path components) Warning, no-op.

Then each name is checked on its own. If <canonical root>/<name> is missing it is created with mode 0700. If it is a symlink, not a directory, not owned by the effective user, or writable by group or others (the same private-group rule as the root, checked with fstat on the opened directory), that name is refused with a warning and the other names go on. Modes of existing directories are never changed.

Per-name state table

What exists at <profile>/<name> Action
Nothing Create the link with symlink(), even when the profile is live. EEXIST means something appeared meanwhile: the name is deferred (raced).
A symlink whose canonicalized target is the canonical directory Nothing (already_ok).
Any other symlink, dangling ones included Warning; never followed or replaced.
A real directory, Mode::Migrate Migrate, then swap in the link.
A real directory, Mode::LinkOnly(reason) Deferred with that reason.
Any other file type Warning; left alone.

Migration

The walk is descriptor-based, like seeding: each directory is opened with openat(…, O_NOFOLLOW|O_DIRECTORY), file types come from fstat on the opened descriptor, and every move is a renameat2 relative to the directory descriptors. A path swapped for a symlink during the walk is never followed. Depth is capped at 16; there is no entry or size cap.

Skipped, and left in the source (so they end up in the backup):

  • names matching .credentials* or .claude.json, at any depth, compared as bytes before anything is opened (so non-UTF-8 names and .credentials.json.bak are caught), with a warning;
  • nested symlinks and special files;
  • reserved temporary names (.amplihack-share-tmp-*).

For each regular file at relative path p:

In canonical Action
Absent Set the source's mode to mode & 0o700 with fchmod on the opened file, then move it in with renameat2(RENAME_NOREPLACE).
Same bytes (size compared first, then a streamed comparison) Leave the source copy; it ends up in the backup.
Different bytes Canonical always wins. Move the source to the conflict name with renameat2(RENAME_NOREPLACE).

Canonical always wins because renaming a canonical file could split a session that another profile's claude has open, and would leave a moment with the real name missing. Size and mtime are not compared. A user who wants the profile's copy swaps the two by hand (how-to).

New directories in canonical are created 0700. No file in canonical is ever renamed, overwritten or deleted: every write into canonical uses RENAME_NOREPLACE or O_EXCL, apart from the memory-index append below.

Memory index. In a directory at relative path <project>/memory of projects/, MEMORY.md is handled after every other entry. It merges like any file. If that made a conflict, the source's lines missing from the canonical MEMORY.md (compared after trimming trailing white space; blank lines and lines starting with # are left out; ](<file>) is rewritten to ](<saved name>) for every file in the same directory saved under a conflict name) are appended to the canonical file with O_WRONLY|O_APPEND|O_NOFOLLOW and fsynced. The conflict copy is saved before the append. An index over 1 MiB, or one that isn't UTF-8, is not appended to, and the "entries not added" warning says so. Every link is rewritten at most once. A repeat run appends nothing, because every line is then present. If the append fails (the shared index is read-only, or was replaced by a rename while the entries were written), the merge goes on and a warning names the conflict copy to add the entries from by hand.

Other filesystem. When a rename fails with EXDEV, the file is copied: check free space with statvfs (if the file doesn't fit, stop migrating this name, leave it a real directory, and warn), create .amplihack-share-tmp-<pid>-<n> in the destination directory with O_EXCL and mode 0600, copy, fsync, set the mode to the source's & 0o700 and its modification time, renameat2(RENAME_NOREPLACE) into place, fsync the directory, and only then unlink the source. If the source's size or modification time changed during the copy, the temporary file is removed before the rename and the source is kept: the merge stops with copy failed: <path> changed during the copy; kept, and the next run copies the file again. The same check runs once more before the unlink; a change caught there keeps the source too, and the next run saves it under a conflict name.

Conflict names. <file>.conflict-<profile>, beside the winner. If that name already holds identical bytes nothing more is done. If it holds different bytes the next free name of .conflict-<profile>-2, -3, … is used. <profile> is always a validated profile name. The suffix breaks the .jsonl extension on purpose, so Claude doesn't list the loser as a session. Every conflict is reported. Nested symlinks and special files are counted and reported in one line per name.

After a name's merge:

  1. Create <profile>/.<name>.share-tmp as a symlink to the canonical directory, replacing a stale symlink of that name. If <name> is no longer a directory (another process swapped it meanwhile), stop with the could not swap in the link warning.
  2. On Linux, exchange it with the real directory using renameat2(RENAME_EXCHANGE), then rename the real directory (now at the temporary name) to the backup name.
  3. Without an atomic exchange (EINVAL, ENOSYS, or not Linux): rename the real directory to the backup name, then rename the temporary link to <name>. If the second rename fails, the backup is renamed back. If that also fails, the warning prints the exact mv that restores it; nothing is deleted.

The backup is <profile>/<name>.pre-share-<YYYYMMDDTHHMMSSZ> (UTC), with -2, -3, … if the name exists. Backups are never deleted automatically. profile remove deletes them with the profile directory.

Repeat runs and recovery

A run on a profile whose three names are correct links changes nothing on disk. An interrupted run is resumed by the next one:

  • files already moved are no longer in the source;
  • .amplihack-share-tmp-* files are removed, but only when they are regular files owned by the effective user and the process whose pid is in the name is no longer running, so a merge running at the same time in another process keeps its copy (unlinkat);
  • a stale .<name>.share-tmp is replaced, but only when it is a symlink;
  • if both a backup and a real <name> exist, the real <name> is migrated again.

Those two reserved names are the only things the helper ever deletes.

Messages

All output goes to stderr, prefixed amplihack: profile <name>:. Paths are shortened with ~; only paths, counts and OS error text are printed, never file contents. This is the complete list; nothing else is printed at the default log level.

Message Meaning
merging session history into ~/.claude (one-time; may take a while) Printed once per call, before the first merge starts, so a long merge doesn't look hung. Every other line is printed when the call finishes.
linked projects, file-history, session-env Links created (not printed by add). Lists only the names linked.
projects: moved <n> files into ~/.claude/projects, <n> identical, <n> conflict A merge finished.
projects: conflict: <path> kept the shared copy; this profile's copy saved as ~/.claude/projects/<path>.conflict-<profile> A conflict. Canonical always wins.
projects: memory index <project>/memory/MEMORY.md: added <n> entries from this profile to the shared copy The profile's memory index lost a conflict; its missing entries were appended to the shared index.
projects: memory index <project>/memory/MEMORY.md: entries not added (<error>); add them by hand from <conflict copy> The append failed, or either index is over 1 MiB or not UTF-8; the profile's index is safe under its conflict name.
projects: skipped credential file <path>; left in <backup> A credential-named file was found in a shared directory.
projects: skipped <n> symbolic links or special files; left in <backup> Nested entries that are never moved.
projects: old directory kept as <backup> The backup name.
projects: migration deferred: live session Deferred::LiveSession. The merge runs on a later call.
projects: migration deferred: could not check for running sessions (retried next launch) Deferred::LivenessCheckFailed: on Linux the /proc scan failed, so no session was seen either way. The merge runs on a later call.
projects: not merged: running sessions can't be checked on this system; merge by hand, see docs/howto/claude-profiles.md#merge-by-hand-on-macos Deferred::LivenessUnknown. Printed on every call while the name is a real directory.
projects: link not created: the name appeared during the check; retried next launch Deferred::Raced (EEXIST from symlink()).
projects is a symlink to <target>; left alone A foreign or dangling link at the profile's name.
projects is not a directory or a link; left alone Any other file type at the profile's name.
~/.claude/projects is a symlink or not a directory; projects not shared The canonical name is refused; the other names go on.
~/.claude/projects is not owned by you or is writable by group or others; projects not shared The canonical name fails the ownership/permission check; the other names go on.
~/.claude is a symlink or not a directory; sessions not shared Canonical root refused.
~/.claude is not owned by you or is writable by group or others; sessions not shared Canonical root fails the ownership/permission check (group write is accepted only for your own private group, as for install).
profile directory is not owned by you or has group or other permissions; sessions not shared Profile directory fails the 0o077 check.
projects: not enough free space to copy <path> (<n> bytes) to ~/.claude/projects; merge stopped, nothing removed EXDEV copy refused by the statvfs check. The name stays a real directory and the next call retries.
projects: could not swap in the link (<OS error>); <profile dir>/projects was not replaced; files already merged are in ~/.claude/projects The link swap failed and the rollback worked. The profile's directory is still real, but the files moved before the swap are already in the shared store. The next call merges what is left and retries the swap.
projects: could not restore the old directory (<OS error>); run: mv '<backup>' '<profile dir>/projects' The link swap and its rollback both failed. The mv is printed with the real absolute paths, shell-quoted.
projects: rename failed: <OS error>; nothing removed, the old directory is at <profile dir>/.projects.share-tmp The link is in place but the old directory could not be renamed to its backup name. Printed once; remove the leftover by hand after checking it (see the how-to). While it exists, a later swap of the same name refuses.
projects: <step> failed: <OS error>; nothing removed Any other I/O error during the merge. <step> is open, read, copy, rename, mkdir, chmod or link. The same line is printed when creating, opening or linking the name fails before any merge. The name stays a real directory.
<profile dir> is inside ~/.claude; sessions not shared The profile root is under ~/.claude; move it elsewhere to share sessions.
<path>: <OS error>; sessions not shared The opt-out marker, ~/.claude or the profile directory could not be checked. Nothing changed.
shared session dirs not supported on this platform; profiles keep separate projects/ Not a Unix system. Printed by add only.

The projects in each message is replaced by the name concerned. A moved line is printed only when a merge completes; apart from the merging session history line printed before it starts, there is no progress output.

Shared directories platform support

Platform Links Automatic merge
Linux Yes Yes, when the profile is not live
Other Unix (macOS) Yes No: liveness is Unsupported, so the mode is always LinkOnly(LivenessUnknown). Each call prints the not merged message until the directory is merged by hand (how-to).
Windows and other non-Unix No No. add prints one warning; other callers log at debug level.

Name rules

Pattern ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$ (validated before any path join). Additionally rejected: .. anywhere, trailing ., path separators, NUL, and Windows-reserved names (CON, PRN, AUX, NUL, COM1-9, LPT1-9, also with an extension, case-insensitive). add rejects names that differ only by case from an existing profile on every platform, so Work and work can never coexist.

Profile root

The profile root is the directory that holds every profile, the default pointer and the auto-switch and rotate state. Every amplihack profile command, every launch with a profile and the background rotator choose one root, in this order:

Order Source Shown as
1 AMPLIHACK_CLAUDE_PROFILE_ROOT, when set and non-empty source: env
2 ~/.amplihack/profile-root, when the file exists source: config
3 ~/.amplihack/claude-profiles source: default

~ is $HOME. If HOME is unset or empty and the variable is not set, every profile command fails with InvalidRoot.

Rules:

  • An empty AMPLIHACK_CLAUDE_PROFILE_ROOT counts as unset, so a wrapper script that leaves AMPLIHACK_CLAUDE_PROFILE_ROOT= behind still gets the saved root.
  • A non-empty variable always wins. The saved file is not opened at all, so a damaged profile-root never blocks a command run with the variable set.
  • A non-empty variable that is relative, holds control characters or has a .. component is an error, InvalidRoot. amplihack does not fall back to the saved root or the default. Earlier releases accepted an absolute variable with a .. component, such as /home/you/x/../profiles; set the path without the .. instead.
  • A saved file that exists but is invalid is an error, InvalidSavedRoot. amplihack does not fall back to the default. This applies to every command that resolves the root, including amplihack claude --profile and the other launch paths.
  • A missing saved file means no saved root, and the default is used. Any other error reading it is InvalidSavedRoot.

The saved root is what makes profiles work in shells that do not read ~/.bashrc: cron jobs, systemd units, tmux new-session -d commands, ssh host cmd and env -i. See Use profiles from non-interactive shells.

Root command

amplihack profile root
amplihack profile root <dir>

root runs before the root is resolved for any other purpose, so it works when the saved file is damaged.

With no argument, root prints the root in use and its source, and exits 0:

$ amplihack profile root
root: /home/you/.claude-profiles (source: config)

If the saved file is invalid, it exits 1 with the InvalidSavedRoot error and hint instead.

With <dir>, it saves <dir> to ~/.amplihack/profile-root, prints where it saved it, and exits 0:

$ amplihack profile root /home/you/.claude-profiles
saved profile root: /home/you/.claude-profiles (/home/you/.amplihack/profile-root)

root <dir> makes these checks in order, and writes nothing if any of them fails:

Check Error
<dir> is non-empty, absolute and valid UTF-8, holds no control characters and has no .. component. ~ is not expanded: a quoted '~/x' is relative and is refused. InvalidRoot
One trailing / is removed (/ itself is kept). -
If <dir> exists, it is not a symlink. SymlinkRefused
<dir> is not ~/.claude or inside it. SharedSourceContainsRoot
The file can be written safely (see Saved root file format). InvalidSavedRoot

More behaviour:

  • <dir> is saved as given, apart from the trailing /. It is not canonicalized, and the directory is not created; profile add creates it.
  • A <dir> with trailing whitespace, such as "/srv/x ", is refused with InvalidSavedRoot (has leading or trailing whitespace) and nothing is written. A leading space makes the path relative, so it gives InvalidRoot.
  • A valid <dir> replaces any saved value, including an invalid one. The old file is never read, so root <dir> is how you repair a damaged profile-root.
  • If AMPLIHACK_CLAUDE_PROFILE_ROOT is set and non-empty, root <dir> still saves and exits 0, and also prints to stderr:
note: AMPLIHACK_CLAUDE_PROFILE_ROOT=/tmp/scratch overrides the saved root in this shell
  • There is no option to clear the saved root. Delete ~/.amplihack/profile-root to go back to the default.
  • Profiles under the old root are not moved. Move them yourself, or point the root back.

Saved on the first add

profile add <name> resolves the root first, so a damaged saved file makes add fail before it creates anything. After the profile is created, if ~/.amplihack/profile-root does not exist, add saves the root it used, whether that came from the variable or the default, and prints:

recorded profile root /home/you/.claude-profiles in /home/you/.amplihack/profile-root

If the file already exists, add leaves it alone and prints nothing about it. Later adds therefore never change the saved root.

AMPLIHACK_CLAUDE_PROFILE_ROOT=/home/you/.claude-profiles amplihack profile add work
env -u AMPLIHACK_CLAUDE_PROFILE_ROOT amplihack profile list
root: /home/you/.claude-profiles (source: config)
  work

If the save fails, add prints warning: could not record profile root: <reason> to stderr and still exits 0, because the profile was created. No other command saves the root on its own.

Saved root file format

~/.amplihack/profile-root and ~/.amplihack/rotate-root each hold one absolute path followed by a single \n.

Rule Detail
Write Atomic: a new temporary file in ~/.amplihack, flushed to disk, then renamed over the target. Mode 0600. The temporary file is created without following symlinks. A value that is not valid UTF-8, that fails the content checks, or that has leading or trailing whitespace is refused before anything is written, because the reader trims whitespace and would return a different root.
~/.amplihack Created with mode 0700 when missing. An existing directory keeps its mode; it also holds other amplihack settings such as ~/.amplihack/config.
Read Never through a symlink, at most 4096 bytes. Leading and trailing whitespace is trimmed.
Valid content Non-empty, UTF-8, absolute, no control characters, no .. component.
Permissions The file must be a regular file that is not writable by group or others. Ownership is not checked.

An invalid profile-root gives InvalidSavedRoot. The message names the file and one of these reasons, or the operating system's error text:

Reason Cause
empty The file holds only whitespace.
not an absolute path The path is relative, including ~/....
not UTF-8 The bytes are not valid UTF-8.
larger than 4096 bytes The file is too large to be a path.
contains control characters The path holds a control character, such as an escape.
contains a .. component The path has a .. component.
is a symlink The file is a symlink. It is not followed.
not a regular file The file is a directory or a special file.
writable by others The file's mode grants write to group or others.

The message never repeats the file's contents:

error: saved profile root in "/home/you/.amplihack/profile-root" is invalid: not an absolute path
hint: fix or remove ~/.amplihack/profile-root, or run: amplihack profile root <absolute dir>

A profile-root left behind by sudo amplihack profile add with HOME kept is owned by root and cannot be replaced by profile root <dir>. Remove it with sudo rm ~/.amplihack/profile-root, then save the root again.

On Windows the file is written through a temporary file and a rename, and read with the same size limit. The mode check does not apply; Windows ACLs are out of scope.

Root line

profile root, profile list and profile rotate status print the root on a line of its own:

root: <path> (source: env|config|default)

rotate status prints root: <path> (pinned by running rotator) instead when it found the rotator through the rotate root record. The path is escaped for the terminal, so control characters cannot write escape sequences.

profile list prints the root line first, then the profiles:

$ amplihack profile list
root: /home/you/.claude-profiles (source: config)
* personal
  work

With no profiles, the root line is followed by no profiles; create one with `amplihack profile add <name>`. Scripts that read list should skip the first line, which always starts root:.

Resolution and environment

amplihack claude, amplihack launch and amplihack profile run pick a profile in this order:

  1. --profile <name> (or the <name> given to profile run). The inherited variable and the pointer are not read, so a dangling or corrupt pointer does not block it.
  2. An inherited, non-empty AMPLIHACK_CLAUDE_PROFILE. The pointer is not read, even if it is dangling.
  3. <root>/.default
  4. none — CLAUDE_CONFIG_DIR is left exactly as inherited.

Recipe launches marked by AMPLIHACK_RECIPE_RUN_ID skip step 3. With no explicit profile they use the inherited CLAUDE_CONFIG_DIR, or the live host login in $HOME/.claude when the variable is unset. This also applies when usage-limit waiting is disabled.

When a profile resolves, three variables are set on the child Command only (never set_var), and only for Claude-compatible binaries. This applies to every command that starts Claude with a profile: amplihack claude, amplihack launch, amplihack profile run and amplihack profile login.

Variable Value
CLAUDE_CONFIG_DIR <root>/<name>, overriding any ambient value
AMPLIHACK_CLAUDE_PROFILE <name>
AMPLIHACK_CLAUDE_PROFILE_ROOT <root>, only when AMPLIHACK_CLAUDE_PROFILE_ROOT was set and non-empty in the launching process (that is, when the root's source is env); otherwise the child's environment is left as inherited, so the child reads the same saved root or uses the same default. An inherited empty value passes through unchanged and still counts as unset.

Copilot and Codex children get none of these, but variables already in the environment pass through them unchanged.

A root that came from the saved file or the default is not exported, so a nested launch reads ~/.amplihack/profile-root again, and fails with InvalidSavedRoot if the file has since been damaged. If you change the saved root while a session runs, launches nested in that session use the new root. Set AMPLIHACK_CLAUDE_PROFILE_ROOT before starting the session to pin it.

Nested launches keep the parent's profile

Every amplihack claude started inside a profiled session (recipe agent steps, multitask/orch workstreams, a nested amplihack claude run by hand) inherits AMPLIHACK_CLAUDE_PROFILE and so resolves the same profile at tier 2. The pin holds for the whole tree of sessions:

  • A later amplihack profile switch only rewrites the pointer. Running sessions, and every launch started from them, keep their profile.
  • A parent started with --profile work while the pointer names personal runs every descendant as work.

How the name reaches each kind of descendant:

Launch path How the variables arrive
Direct child, amplihack recipe run Inherited environment (the recipe runner is detached with setsid but keeps the environment).
Recipe agent steps Inherited environment. recipe-runner-rs builds each step's environment from its own, and never drops AMPLIHACK_* variables when it trims the environment to fit its budget. The only AMPLIHACK_* value it removes is one whose KEY=value string is over the kernel's 131,072-byte per-string limit, which no child could receive anyway; a profile name and root are far smaller. In a bash step, values the recipe itself supplies (context keys and their uppercase aliases) that are too large for the environment become shell-local variables and are not exported (checked at the revision pinned in claude-plugin/recipe-runner.rev, 4d5187e). Agent steps take no per-step environment. In bash steps, a step's env: block can set any variable, including these, and so can the runner's uppercase export of context keys (see Recipe context cannot set the profile).
multitask / orch workstreams Inherited environment: each workstream's run.sh is started with the parent's full environment. As a backup, the generated run.sh also exports AMPLIHACK_CLAUDE_PROFILE and AMPLIHACK_CLAUDE_PROFILE_ROOT, single-quoted, when they are set and non-empty, so a run.sh re-run by hand or on resume uses the same profile. CLAUDE_CONFIG_DIR is not exported; the nested launch rebuilds it from the name and checks it again. If either variable is set but is not valid UTF-8, the workstream is refused before any script is written (the error names the variable, not its value), because leaving it out would send the nested launch to the saved or default root.

Only the name and the root are passed on. Each nested launch resolves the name against the root and runs the full check below again, so an inherited CLAUDE_CONFIG_DIR is never trusted on its own.

An inherited value is checked exactly like a flag: it is parsed with the name rules without trimming (so " work" is invalid), resolved inside the root, and re-validated before spawn. Any failure — an invalid name, a value that is not valid UTF-8, a profile that no longer exists, a symlinked or out-of-root directory — aborts the launch with the inherited-profile error. It never falls back to the pointer or to no profile.

You can set the variable by hand to pin a profile for one shell or command:

AMPLIHACK_CLAUDE_PROFILE=work amplihack recipe run default-workflow

A stale export in a shell startup file acts as a per-shell default that beats the pointer; unset AMPLIHACK_CLAUDE_PROFILE removes it.

Agent steps in amplihack recipe run and recipe-mode amplihack multitask without an explicit or inherited profile use the inherited CLAUDE_CONFIG_DIR or ~/.claude. A successful profile switch changes the login used by steps on ~/.claude. Classic multitask launches started from a plain shell still read the default pointer when no profile is selected. Start a run from inside a profiled amplihack claude session, or set AMPLIHACK_CLAUDE_PROFILE as above, to pin one profile for the whole run.

Fleet and remote VM launches do not pass the profile on, so nested launches inside them use the pointer.

Copilot and Codex launches don't set the variables themselves, but they don't remove an inherited value either. A nested amplihack claude started from a Copilot session that inherited AMPLIHACK_CLAUDE_PROFILE uses that profile and checks it again. Without it, the launch uses the pointer.

Recipe context cannot set the profile

amplihack recipe run refuses any context key whose uppercase form starts with AMPLIHACK_, on both the --set and the --context-file path, before the runner starts:

recipe context key "amplihack_claude_profile" is reserved: the AMPLIHACK_ namespace, Git execution configuration and any name that selects or runs a program cannot be set from recipe context

Only the key is printed, never its value. Keys that merely contain amplihack (such as use_amplihack) are allowed.

Known limitation: the recipe runner itself still exports every top-level context key to bash steps under its uppercase name. A recipe's own YAML context: default or a step output: named amplihack_claude_profile (or amplihack_claude_profile_root) is not checked by amplihack and can override the pinned value for an amplihack claude run inside a bash step. The name and directory are still validated, so this can only select one of your own profiles. The runner fix is tracked in rysweet/amplihack-recipe-runner#146.

Pre-spawn check

Immediately before spawn, the profile path is re-resolved and re-validated: it must be a real directory (not a symlink), its canonical path must equal the expected path under the profile root, and it must be owned by the current user with no group/other permission mode bits (mode & 0o077 == 0: 0700 passes; 0755, 0750 and 0705 fail). ACLs are not inspected. Only the profile directory is checked, not its parents. If the check fails, run chmod go-rwx <profile-directory> on Unix. Any failure aborts the launch. Once the check passes, the profile's shared session links are checked and fixed while the launch hold is held; that step never aborts the launch. This check applies only to profile launches; Claude and Copilot launches without a profile are unchanged. Ownership and group/other mode-bit checks are available on Unix. On other platforms, profile launches still require a real, contained directory, but the operating system does not expose the same checks through this command.

The profile selects a configuration directory; it does not change Claude's authentication environment. Claude Code documents separate directories for claude.ai logins and API-key accounts, but two Claude Console sign-ins without API keys are not isolated because their credentials live outside the configuration directory. An inherited ANTHROPIC_API_KEY can also select API billing instead of a subscription login. See the official multiple-account and environment variable documentation.

profile run applies the same check as launch --profile: if Docker is active (including AMPLIHACK_USE_DOCKER), it fails with the unsupported-mode error before resolving or creating anything. It never silently drops the profile.

--profile together with --docker or --auto fails with an unsupported-mode error before anything is spawned. This includes Docker activated through the environment (AMPLIHACK_USE_DOCKER). With Docker activated that way and only a default pointer, the pointer is not applied and a warning is printed.

An inherited, non-empty AMPLIHACK_CLAUDE_PROFILE is refused the same way. With --docker, --auto or Docker activated through the environment, the launch fails with the inherited-profile error and reason not applied with --docker, --auto or Docker:

error: inherited AMPLIHACK_CLAUDE_PROFILE "work": not applied with --docker, --auto or Docker
hint: unset AMPLIHACK_CLAUDE_PROFILE and CLAUDE_CONFIG_DIR to run with --docker/--auto

The refusal happens before the value is parsed and before the profile root is opened, so the value drives no filesystem reads. A value that is not valid UTF-8 gets the same refusal, not an invalid-name error. An empty value counts as unset and does not trigger it.

These modes never set, change or re-check CLAUDE_CONFIG_DIR. A launch that gets past the refusal keeps whatever CLAUDE_CONFIG_DIR it inherited, with no pre-spawn check. Inside a profiled session that is still the parent's profile directory, so unsetting AMPLIHACK_CLAUDE_PROFILE alone would run an --auto launch on the parent's account, not the default one. Unset both variables for that one command:

env -u AMPLIHACK_CLAUDE_PROFILE -u CLAUDE_CONFIG_DIR amplihack claude --auto -- -p "summarise the README"

A --docker launch does not forward CLAUDE_CONFIG_DIR into the container, but unsetting both is still the safe form to use.

Amplihack's own orchestration (recipe agent steps, multitask/orch workstreams) never passes --docker or --auto to nested launches. It does not clear AMPLIHACK_USE_DOCKER, though. A profiled session can carry a truthy AMPLIHACK_USE_DOCKER if you export it inside the session, or if it was exported when the session started but the Docker daemon was not running (env-activated Docker only applies when the daemon is up). Once the daemon is running, every nested launch of a recipe or multitask run started from that session is refused with the error above. Unset AMPLIHACK_USE_DOCKER before starting the run. Inside a container AMPLIHACK_USE_DOCKER has no effect, so nested launches there are not refused.

A default pointer on its own is never an error in these modes: with --docker or --auto it is not read, and with Docker activated through the environment it is skipped with the warning above.

A symlinked profile root is refused by every subcommand and by the pointer reads/writes; a missing root is treated as empty.

Literal argument forwarding

run <name> -- <args> passes args as an argv vector with no shell, so amplihack profile run work -- "; rm -rf ~" hands that string to Claude as one literal argument and executes nothing.

Auto-switch

Auto-switch moves work from an account that is close to its usage limit to another profile with quota left. It is off by default. The how-to walks through using it; this section defines its behaviour.

What "off" means

With the switch off and no <root>/.auto-switch.d/ directory:

  • the lease and recovery guards make one metadata check (does <root>/.auto-switch.d/ exist?) and stop;
  • launches, nested substitution and the rerun supervisor read AMPLIHACK_CLAUDE_AUTO_SWITCH once and, unless it decides the setting, make at most one bounded read of <root>/.auto-switch (4096 bytes);
  • launches do not start the rotator and do not read its autostart setting.

Nothing else happens. No directory is created, no lock is taken, no usage is recorded, no profile is substituted, no output is buffered and no step is rerun. Behaviour is the same as without the feature. The status-line wrapper, if installed, runs the original status line and records nothing.

If <root>/.auto-switch.d/ exists, the lease and recovery checks run whatever the toggle says, so a login moved while the switch was on stays protected after off.

Auto-switch commands

Command Behavior
auto-switch on [--threshold N] [--exclude a,b] Writes enabled=on, plus the threshold and exclusions if given, and prints auto-switch: on (threshold N%). If any profile's status-line wrapper is missing or stale, prints the profiles without the wrapper note to stderr.
auto-switch off [--exclude a,b] Writes enabled=off. The threshold and exclusions are kept; --exclude replaces the exclusions, and is needed only when .auto-switch does not parse or others can write it (Unreadable exclude list). Logins in running sessions are not moved; they return when each session ends. Like auto-switch on, appends a change: line to the rotate log when enabled changes.
auto-switch status Read-only. Takes no lock, runs no recovery and changes nothing on disk. Prints the effective setting and where it comes from (env, file, default or corrupt), the threshold, the exclusions, whether in-session swaps are available, one row per profile (latest readings, where its login is, wrapper state), the hosted directories, an invariant line, and then any notes. Prints profile names, percentages and times only.
auto-switch threshold N Sets the threshold, 1 to 100. Keeps enabled and exclude.
auto-switch exclude [names…] Replaces the exclusion list. With no names, clears it. Each name must pass the name rules; it does not have to exist (status lists names that do not). Keeps enabled, threshold and overflow.
auto-switch install Adds the status-line wrapper to every profile that does not have it. Leaves a stale wrapper alone and reports it. Prints the root it acts on.
auto-switch repair If <root>/.auto-switch.d/ exists, takes the global lock and runs recovery. Then does everything install does, and also rewrites stale wrappers (old or moved binary path, wrapped twice, edited by hand) to the canonical one. Prints the install lines, then one recovery: line per thing recovery did, or recovery: nothing to do. This is the only command whose purpose is recovery.

On Unix, status prints an autostart: line right after the switch: line, in the format described in Rotate status. When auto-switch is off it ends with — inactive (auto-switch off), because launches start the rotator only while auto-switch is on:

switch: off (file)
autostart: on (default) — inactive (auto-switch off)

When any profile is marked overflow, the next line is overflow gate:, the gate auto-switch uses and where it came from (see Auto-switch and overflow profiles):

overflow gate: wait 7200s, unknown reset waits, plan capacity below 85% session and 90% week (from the rotator, pid 4242)
overflow gate: wait 1800s, unknown reset waits, plan capacity below 85% session and 90% week (no rotator runs; from AMPLIHACK_ROTATE_* or defaults)
overflow gate: closed (the running rotator (pid 4242) has not recorded its overflow settings; restart it)

The 5h cell shows no session window when the account's reading has seven_day and no five_hour: no session window was recorded, and the account is ranked on its week (see Readings). This is not the same as no session limit: the stored reading cannot tell a plan with no session limit from a session window that was not recorded (see the known limitations there). An account with neither window, or no reading, shows -.

profile   5h                 7d    observed   login   wrapper
weekly    no session window  47%   2m ago     home    installed
work      93%                61%   5m ago     home    installed

The login column says where the profile's login is. In order of precedence it is live in <dir>, parked, home, keychain, keychain unreadable or none. home means the profile's own .credentials.json exists. On macOS, a profile with no login file reads keychain when the Keychain lookup finds its item, and keychain unreadable when the Keychain could not be read. For those two values the answer comes from the same function as the launch guard, so the two agree. home does not carry that guarantee: it says only that the file exists, whereas the guard treats a login file that is unreadable or has no OAuth login as no login. A profile resolved as an API-key profile that has no login file on macOS shows none in this column, yet still counts as a candidate for selection by the rules in API-key profiles and auto-switch.

status resolves each profile's kind twice, once for the login column and once for its notes, so a profile with no login file on macOS costs two Keychain lookups in one status run.

status prints wrapper as installed, missing, stale (an older or edited wrapper command, one wrapped twice, or one pointing at a different binary) or unsafe (the binary is in a location install would refuse). The in-session swap line is available (Linux) or unavailable (<reason>); see Platform support. The invariant line is invariant: ok (every login is in exactly one place), invariant: pending recovery when a swap journal is waiting, or invariant: PROBLEM: <problem> naming the profile and the problem (a damaged ledger or journal, a journal marked inconsistent, or a login that is not where the ledger says).

install and repair print one line per profile: the outcome, the name and a detail.

Outcome Detail
unchanged (none)
installed (no previous status line), (wrapped existing status line) or (restored the saved status line)
stale (install only) (wrapper pointed at a different binary) or (wrapper command differs from the canonical one), followed by — run: amplihack profile auto-switch repair
repaired (repair only) (wrapper pointed at a different binary) or (wrapper command differs from the canonical one)

The recovery: lines repair prints are recovery: rolled back an interrupted swap in <dir>, recovery: finished an interrupted swap in <dir> and recovery: returned the login of <account> hosted in <dir> (session ended).

Both install and repair are idempotent: a second run leaves every settings.json byte-identical. Neither resolves or writes ~/.claude. profile add does not install the wrapper; run install after it.

Status notes

status prints these notes after the invariant line, each as note: <text> on its own line, only when they apply:

Note When
interrupted swap pending — run: amplihack profile auto-switch repair journal.json exists. status never acts on it.
stale lease: <dir> (session ended) — run: amplihack profile auto-switch repair A hosted directory is no longer live. status does not return it.
ignored AMPLIHACK_CLAUDE_AUTO_SWITCH value (use 1 or 0); the file decides The variable is set to something other than 1, 0 or empty.
profiles without the wrapper: <names> — run: amplihack profile auto-switch install A profile's wrapper is missing or stale.
excluded but missing: <names> An exclusion names no existing profile.
profiles '<a>' and '<b>' are signed in to the same account and organization (duplicate login); … Two logins are the same account: from each profile's own .claude.json, from its saved block while its directory hosts another account, or $HOME/.claude.json (shown as ~/.claude). The fix names the profile whose login is not its recorded account, or ~/.claude when it is not the live profile's recorded account, or the line says amplihack cannot tell which one is wrong. See Duplicate-login warning for every form. No uuid, organization or e-mail is printed.

Every command takes the global state lock only when it needs it, and exits with status 1 on error with the usual error:/hint: lines.

Settings file

<root>/.auto-switch holds key=value lines, written in this order:

enabled=on
threshold=90
exclude=review,shared
overflow=login-aw
Key Values Default
enabled on or off. Required. —
threshold Integer 1 to 100, in percent. 90
exclude Comma-separated profile names, may be empty. An excluded profile is never chosen, and no amplihack command probes it or refreshes its token; see Excluded profiles and Rotate excluded live profile. empty
overflow Comma-separated profile names, in the order the rotator tries them. See Rotate overflow. Written only by profile overflow. empty

overflow is written last, and only when the list is not empty, so a file with no overflow profiles is byte-identical to one written before the key existed. A missing key or an empty value means no overflow profiles. Every command that rewrites the file keeps the overflow list.

It is written like .default: a new temp file in the same directory (create_new, mode 0600, never through a symlink), synced, renamed over the file, and the directory synced. Rewrites produce identical bytes for an identical setting.

Every command that changes the file (auto-switch on, off, threshold and exclude, and profile overflow add and remove) reads it, changes its own key and writes it back while holding the auto-switch state lock in <root>/.auto-switch.d/, the lock the rotator and in-session swaps hold while they work. Two writers therefore never lose each other's change. A command waits up to 10 seconds for the lock and otherwise fails, leaving the file unchanged, with AutoSwitchConfig and the message:

.auto-switch is being changed by another process (the rotator or auto-switch); retry

It never falls back to an unlocked write. When the change leaves every key as it was, for example overflow add on a name already marked, nothing is written. A change that would make the file larger than 4096 bytes is refused with AutoSwitchConfig and the file is left as it was.

The file is corrupt, and the switch counts as off, if it is larger than 4096 bytes, not UTF-8, not a regular file, not owned by the current user, writable by group or others, has an unknown or repeated key, has no enabled, has an out-of-range value, or has an overflow list with an invalid or repeated name. status shows switch: off (corrupt). A corrupt file also gives no overflow profiles, so the rotator never moves onto credits because of it.

An amplihack binary older than the overflow key counts a file that has the key as corrupt: auto-switch counts as off and the exclusion list is lost for that binary. Upgrade every amplihack binary that uses the root before running profile overflow add.

What each command writes depends on the current file:

Current .auto-switch on / off threshold N / exclude …
valid rewrites it with the new enabled rewrites it, keeping the other keys
missing creates it creates it with enabled=off, defaults for the key not given
corrupt regular file owned by you replaces it; threshold starts from its default unless given. exclude keeps the file's list when it parses and is private; when it does not parse, on and off are refused with AutoSwitchExcludeAtRisk unless --exclude names the list (on --exclude … or off --exclude …; see Unreadable exclude list) refused with AutoSwitchExcludeAtRisk, naming the recovery: on or off first when it parses, on --exclude … or off --exclude … when it does not
owned by another user refused with AutoSwitchExcludeAtRisk, even with --exclude: while it is there every profile counts as excluded, so the message says to fix the owner with chown, not to delete it refused with AutoSwitchExcludeAtRisk, as for on / off
owned by you, writable by group or others its list is not trusted (anyone who can write the file could have removed an entry), so on and off are refused with AutoSwitchExcludeAtRisk unless --exclude names the list; with it, the file is replaced with mode 0600 refused with AutoSwitchExcludeAtRisk; run on --exclude … or off --exclude … first
symlink or not a regular file refused with AutoSwitchExcludeAtRisk, even with --exclude: the message says to replace it with a regular file of yours holding the same exclude= line, not to delete it refused with AutoSwitchExcludeAtRisk, as for on / off

A file is never written through a symlink, and a file owned by someone else is never replaced.

The file is read again on every check and never cached, so a change applies to running sessions from their next check.

Toggle and precedence

AMPLIHACK_CLAUDE_AUTO_SWITCH Effective setting
1 on
0 off
unset or empty the file's enabled; off if the file is missing or corrupt
anything else the file decides; one warning per process goes to stderr, and status shows the note

Only 1 and 0 are recognised. The file is read on every check, so a change to it applies to running sessions from their next check. The variable is inherited when a session starts and cannot be changed afterwards; while it is set, it overrides the file, so =1 keeps switching on even after auto-switch off. The threshold and exclusions always come from the file.

Readings

A reading is the latest usage seen for one account:

{
  "version": 1,
  "accounts": {
    "work": {
      "five_hour": { "used_percentage": 93.0, "resets_at": 1760630400 },
      "seven_day": { "used_percentage": 61.0, "resets_at": 1761040800 },
      "observed_at": 1760621000,
      "source": "statusline"
    }
  }
}

That is <root>/.auto-switch.d/usage.json. Times are Unix epoch seconds. source is one of:

  • statusline for readings from the wrapper, and for readings that profile usage or the rotator took through claude;
  • direct for readings that profile usage or the rotator took from the usage endpoint, with observed_at the time of the read;
  • usage_limit_failure for a reading recorded from a step that hit its usage limit (see Usage-limit reruns).

Every reader treats direct as it treats statusline. A build from before direct was added cannot read a file with a direct entry; see Older builds and direct readings.

  • Parsing. Status-line input is capped at 1 MiB and only its rate_limits object is read. resets_at is accepted as epoch seconds (integer or float) or RFC 3339. A window is dropped if its percentage is not a finite number or its resets_at is not within one day before to eight days after now. Percentages are clamped to 0–100. Input without rate_limits records nothing.
  • Reset. A window whose resets_at is at or before now counts as 0%.
  • Attribution. A reading belongs to the account whose login is live in that directory (per the ledger), not to the directory's owner.
  • Identity. An account is identified by the name of the profile that owns its login. Leases, the ledger and readings all use that name; oauthAccount is only used to patch what Claude displays. Two profiles signed in to the same Anthropic account are not supported: they are treated as two accounts, and status warns about them.
  • After a swap. For 300 seconds after a swap, readings from that directory are not recorded and do not trigger another swap. After that, a reading identical to the last reading before the swap (same percentages and reset times) is still ignored, because it describes the previous account. Readings recorded by profile usage skip this quiet period; see Refreshing auto-switch readings.
  • No session window. A reading may hold seven_day with no five_hour: Claude reported no session window for that login (see No session limit), or the status line gave none. It is judged on seven_day alone. When profile usage records such a reading, a stored five_hour is kept until its reset time passes; see Refreshing auto-switch readings. usage.json has no session_limit field and its format is unchanged.
  • Merging. The reading with the newer observed_at wins; on a tie, the one with the higher usage wins.
  • Errors. A damaged usage.json is treated as empty and overwritten by the next reading.
  • Readings from ~/.claude. The ~/.claude status line never writes usage.json. It records into <root>/.auto-switch.d/home-usage.json, which has the same format and is read only by the status line's spare count: nothing checks which account ~/.claude held when such a reading was taken (see Why the readings are kept apart). Passive readings, candidate selection, profile rotate and the capacity file never read it.

Older builds and direct readings

The direct source was added without changing version, which stays 1. An amplihack build from before it cannot parse a usage.json with a direct entry, and rejects the whole file, for every account, not only that entry. A higher version would not help such a build, which rejects an unknown version in the same way; it would instead reject every file a newer build writes, including one with no direct entry. A newer build reads every file an older build writes.

Until the file is rewritten without a direct entry, an older build:

  • finds no passive reading, so its profile usage and its rotator send a request for every login;
  • gives auto-switch, the capacity file, the capacity governor and the status line's spare count no readings;
  • writes this warning from profile auto-switch status, from the usage-limit rerun supervisor, and when its profile usage or rotator records a reading (the rotator's goes to rotate.err):
auto-switch: warning: auto-switch state is inconsistent: .auto-switch.d/usage.json: invalid JSON at line <L> column <C>; usage readings treated as empty
  • shows alert: unavailable (...) in profile rotate status, and writes skip: alert check failed: ... to rotate.log on a paused cycle, when auto-switch is turned off.

The first reading such a build records, from the status-line wrapper, profile usage, its rotator or a usage-limit failure, rewrites the file with its own readings alone. Every other entry, including a usage_limit_failure reading, is dropped, and each login has a reading again once it is next read. The older build can then read the file until a newer build next records a direct read.

An older build runs beside a newer one while a process started before an upgrade is still running, such as a rotator or an agent step's usage-limit supervisor, while a profile's status-line wrapper still runs the older binary, and after a rollback. After an upgrade:

  1. Restart each running rotator: amplihack profile rotate stop, then start it again with the settings it had.
  2. Run amplihack profile auto-switch status. If any profile's wrapper is stale, run amplihack profile auto-switch repair.

After a rollback, the older build's warnings stop once it has recorded its first reading.

Candidate selection

An account is exhausted when the higher of its two adjusted windows is at or above the threshold (max(five_hour, seven_day) >= threshold). An adjusted window is one whose resets_at is at or before now, which counts as 0%. A window without resets_at is used as read. A reading with no five_hour is judged and ranked on seven_day alone, so a login with no session limit is eligible while its week is below the threshold. An account with no reading is not exhausted. Exhausted plan accounts are never chosen; an overflow profile's own reading does not count.

An account is eligible when it is not excluded, not the current account, not leased, and not exhausted (overflow profiles: not spend-blocked instead), plus the extra conditions for an in-session swap or a nested launch.

Eligible accounts are ordered:

  1. accounts with a reading, by the higher of their two adjusted windows, lowest first, then by name;
  2. accounts with no reading, by name.

The first one is chosen. A known reading below the threshold always beats no reading. If none is eligible, nothing is switched. An excluded account is never chosen, and its stored reading is never refreshed by a probe. When an excluded account is the live one, the rotator moves off it without probing or refreshing it; see Rotate excluded live profile.

Auto-switch and overflow profiles

Overflow profiles are chosen only after every plan profile, by the rule the rotator follows, with the rotator's own gate. The gate has four values: the overflow wait, the unknown-reset choice, and the two thresholds that define plan capacity. A plan account has capacity when its five-hour use is below the rotator's --session-at and its seven-day use is below its --week-at (85% and 90% by default), the test the rotator applies to its plan pool. Every selection (in-session swaps, nested launches and usage-limit reruns) works like this:

  1. The best plan profile, by the order above, with the overflow profiles left out, among those with plan capacity or no reading. From a plan profile, the target must also be below the auto-switch threshold, as for any move between plan profiles. From an overflow profile, plan capacity alone decides, whatever the auto-switch threshold: a session moves back as soon as a plan profile has plan capacity and is eligible, whether or not the overflow profile is near its own limit. This is the rotator's rule for leaving overflow. For example, with auto-switch threshold 80 and the default 85%/90%, a plan account whose session has reset and whose week reads 85% brings the session back: 85% is over 80 but under the 90% week threshold. The status-line check that decides whether a session on an overflow profile is worth a full check uses the same rule, plus step 2's spend block: without either, it stops there, whatever the overflow profile's own reading, so a session on credits does not run recovery or the /proc scan on every update.
  2. A session on an overflow profile moves to the plan profile with the most room, by its own room ranking (the rotator uses the target rule), when any plan profile is below 100% on both windows. Otherwise, a session on an overflow profile that is not spend-blocked stays where it is. Its own plan reading plays no part: a credit account reads at or near 100% of its plan limits while it spends credits, and that is the account overflow exists for. Only a spend block moves a session from one overflow profile to the next, as in the rotator.
  3. An overflow profile, only when both hold:
  4. no plan profile has room below 100% on both windows, the current one included, whether or not this session could use it (one leased to another session still counts, so no money is spent while it exists). A plan profile with no reading, or whose probe failed, counts as having no room. The API-key profile also waits for every plan profile with no reading, which may have room: it is passed over, and a launch or rerun writes ALERT: API key not used session=<account>: …; auto-switch from <profile> to stderr every time and to the rotate log once per set of unmeasured profiles (again once the set changes or every plan profile has a reading). The usage-limit wait's own capacity check applies the same candidate rules without writing the line, so a step waiting out a limit does not repeat it on every write it reads. session= is the account of the session that ran out; live=, in the rotator's form of the line, is the login in ~/.claude. Excluded profiles do not count, and neither do those the rotator skips as no login or not oauth, which nothing can measure. Nor does a profile the rotator's last measuring cycle found with no room, while the ledger's no_room record holds: auto-switch has no reading of its own for the login in ~/.claude, and the rotator measures it every cycle. The record ends at the first reset the rotator read for a login it names, since that login has room again. It names every login the cycle measured, so a login the rotator has just moved off is covered too. Without a record in force, as when no rotator runs or the rotator found room on the login, it counts until a reading is recorded for it (a session on it, or profile usage) or it is added to exclude. The capacity file plays no part here: the rotator writes it as ok when it can use the key, and the status line and profile usage rewrite it. A current plan profile at 82%, or at 97%, still has room: the rotator would not leave it for overflow, so the session stays on it rather than spend, and it cannot move onto overflow only to move straight back;
  5. the earliest plan reset is more than the overflow wait away. The plan reset of an account is the reset of its window at its threshold, or the later of the two when both are; the earliest plan reset is the earliest of those over every plan account, the current one included.

The first overflow profile by tier, then by list order within a tier, that is not current, not excluded, not spend-blocked and eligible is chosen. Its own plan reading is not checked, so a tier 1 credit account at 100% of its plan limits is still chosen before the API key. The API-key profile is tier 10, after every credit profile, and is a candidate only when it is marked and passes its login check. 4. Otherwise the best plan profile below the auto-switch threshold, by the order above. A plan account between the gate's thresholds and the auto-switch threshold (for example at 87% session) is used only here: when overflow is not allowed, it beats waiting, and it costs nothing.

The rotator decides in the same order (plan capacity, then plan room, then per-token profiles by tier; see Rotate decision order), and both use the same room test before spending, so on the same readings the two agree on when money is spent, for any auto-switch threshold. The auto-switch threshold only decides when a session on a plan profile asks, and which plan profiles it may move to from another plan profile. In particular, a plan account at 87% session has room for both: neither moves onto an overflow profile while it exists, whatever the plan reset.

Auto-switch takes the gate from the running rotator. rotate watch writes its pid and the gate it resolved from its flags to <root>/.auto-switch.d/rotate/gate.json when it starts, so profile rotate start --overflow-wait 7200 gives every Claude session the same two-hour wait with nothing to keep in step. Where the gate comes from:

Rotator Gate auto-switch uses
Runs, and gate.json names its pid The recorded gate. AMPLIHACK_ROTATE_* in the session's environment is ignored.
Runs, and gate.json is missing, damaged, out of range or names another pid (for example a rotator from an amplihack without this record, which never uses overflow) None: no overflow profile is chosen. Restart the rotator.
Cannot be verified (no /proc) None.
Not running AMPLIHACK_ROTATE_OVERFLOW_WAIT, AMPLIHACK_ROTATE_OVERFLOW_UNKNOWN_RESET, AMPLIHACK_ROTATE_SESSION_AT and AMPLIHACK_ROTATE_WEEK_AT from auto-switch's own environment, with the rotator's defaults (1800 seconds, off, 85, 90). An invalid value of one of these four means no gate; other AMPLIHACK_ROTATE_* variables play no part.

auto-switch status prints the gate and its source on its overflow gate: line. A rotate ledger that cannot be read (so spend blocks are unknown) also means no overflow profile is chosen.

The status-line check that runs a swap normally does nothing while the session is under the threshold. When the account in the session's directory is an overflow profile and some plan profile reads under the threshold, it goes on to the selection above, so the session moves back. The note then reads profile "<overflow>" is an overflow profile and a plan profile has capacity again; .... A nested launch that inherits an overflow profile is started under a plan profile with capacity in the same way.

Status-line wrapper

install and repair set each profile's statusLine to a hidden command:

"statusLine": {
  "type": "command",
  "command": "'/home/you/.local/bin/amplihack' profile statusline --root '/home/you/.claude-profiles' --owner 'work'",
  "padding": 0
}

The binary path is the one that ran install. Each value is single-quoted for sh; a path containing NUL, a newline or non-UTF-8 bytes is refused. The original statusLine object is saved in <root>/.auto-switch.d/statusline/<name>.json and run by the wrapper.

The profile's statusLine is… install repair
the canonical wrapper does not write does not write
missing installs the wrapper; uses a saved original if one exists same as install
another command saves it as the original, then installs the wrapper same as install
exactly amplihack profile statusline, or a quoted path to amplihack followed by it, with no --owner (the ~/.claude entry) saves ~/.amplihack/.claude/tools/statusline.sh as the original when that script passes the script checks, otherwise saves no original; then installs the wrapper same as install
an old, moved, edited or doubly wrapped wrapper (has the words profile statusline and --owner) does not write; reports stale rewrites it to the canonical wrapper, keeping the saved original (never saving a wrapper as the original)

The ~/.claude entry is never saved as an original, and a saved original that is exactly that entry, left by an older install, is never run: ~/.amplihack/.claude/tools/statusline.sh runs in its place. A user's command that does more, such as amplihack profile statusline | my-filter, is another command: it is saved and run, and the inner profile statusline runs only statusline.sh (details).

The original padding is kept. A missing settings.json is created at 0600. Writes use a temp file, rename and a directory sync. Other keys and their values are kept; key order may change. install checks each profile directory like a launch does, refuses a symlinked settings.json, and never resolves or writes ~/.claude. It refuses to install when the amplihack binary, or any directory above it, is writable by group or others or is owned by someone other than you or root. Group write is accepted only for your own private group (a group named like your user with no listed members, the usual layout with a umask of 002). It warns when the binary is inside a target/ directory. There is no uninstall command; restore the saved original by hand if you need to.

When Claude runs the wrapper, it:

  1. checks that --root is absolute and private, that --owner is a valid name, and that CLAUDE_CONFIG_DIR resolves to <root>/<owner>. If any check fails, it only runs the original status line;
  2. waits at most 50 ms for the state lock, then runs recovery if <root>/.auto-switch.d/ exists and, if the switch is on, records the reading. If the lock is still busy after 50 ms, it skips recovery, the update and the swap check for this run; the next wrapper run, launch, login or repair runs them. It never delays or changes the output;
  3. runs the original command with sh -c, the same standard-input bytes, working directory and environment, and copies its standard output through byte for byte;
  4. runs the in-session swap check.

After the original output, the wrapper prints the login capacity line when the step 1 checks passed and the saved original is statusline.sh. A wrapper around your own command adds no capacity line, and a wrapper with no saved original prints none (see Inside profiles). The capacity notice follows while it is due. Step 2 also updates the capacity file when the recorded reading is at or over the threshold, or the file reports low or no capacity; any other reading cannot change the file.

--root may be left out; the root is then resolved as for other profile commands (see Profile root). Run without --owner inside <root>/<name>, amplihack profile statusline behaves as --owner <name>, except that it never swaps or updates the capacity file; see Modes.

The saved original in statusline/<name>.json is run only if it passes the state directory checks (a regular file owned by you, mode 0600, not a symlink, at most 64 KiB, valid JSON). If it fails them, the wrapper does not run it, prints nothing to standard output (Claude shows an empty status line), and writes one stderr line naming the path and telling you to run amplihack profile auto-switch repair.

If the --root it was installed with is not an absolute path, cannot be resolved, or fails the profile-root checks (a real directory owned by you and not writable by other users), the wrapper does nothing else: it runs neither the original status line nor any bookkeeping, prints nothing to standard output, and writes one stderr line, auto-switch: status line disabled: profile root <path>: <reason>.

Trigger point and coverage

The wrapper is the only passive source of rate_limits: hooks receive no usage data. It is therefore the trigger for in-session swaps, which happen only in sessions that render a status line (interactive sessions). Non-interactive claude -p launches may never run the status line. They are covered instead by nested substitution when they start and by usage-limit reruns when they fail.

The wrapper writes to standard output itself only to add the capacity line and the capacity notice after the original output. Its exit code is the original command's, or 0 if there is none or it was not run. Its own errors, including a panic, are one line on stderr naming paths only.

The wrapper makes no network request and never opens a profile's .credentials.json. It records the rate_limits Claude passes it and reads usage.json, home-usage.json and the ledgers. A profile in the auto-switch exclude list is therefore never probed or refreshed by it, and an in-session swap never chooses one (see Candidate selection).

In-session swap

Runs from the wrapper, on Linux only, when the switch is on and the session's account is exhausted. The target must be eligible and, in addition, its login must be in its home slot, and if that home slot is its own profile directory, no running process may be using that directory.

The home slot of account X is <root>/X/.credentials.json when directory X holds X's own login, and <root>/.auto-switch.d/parked/X/.credentials.json when directory X is hosting another account. At any moment each account's login is in exactly one of: its home slot, or one directory where it is live.

The swap holds two locks: the global lock <root>/.auto-switch.d/lock, and Claude's own refresh lock <live dir>/.oauth_refresh.lock, taken with a non-blocking mkdir. If either is busy, the swap is skipped until the next update. The refresh lock is never broken, and is removed afterwards only if it is still the one amplihack created (recovery also removes it after a crash, using the inode recorded in the journal).

  1. Finish any interrupted swap, then write journal.json and sync it.
  2. Move <live dir>/.credentials.json to the outgoing account's home slot with renameat2(RENAME_NOREPLACE). Sync both directories.
  3. Move the target's home slot to <live dir>/.credentials.json the same way, set its modification time to now so Claude reloads it, and sync.
  4. Update ledger.json, set oauthAccount in <live dir>/.claude.json to the target's saved block, delete the journal and sync.

Before each move the file must be a regular file owned by you, readable by nobody else (no group or other mode bits), with exactly one hard link.

After a swap the wrapper writes one line to stderr (never to the status line):

amplihack: profile "work" reached the auto-switch threshold; the session in profile "work" now uses the login of profile "personal"

If either move fails because the destination exists (EEXIST), a file is where the state says none should be, and amplihack cannot tell which copy is current. The swap stops at once: nothing else moves and nothing is rolled back, so a move already done in step 2 stays done. The journal is kept with phase set to inconsistent. Recovery never acts on an inconsistent journal, so launches and logins of both profiles fail with AutoSwitchInvariant until it is repaired by hand.

The swap does not check the shared session links. It moves only the top-level login files, which are outside the shared names. Both profiles are checked the next time they are launched, including the usage-limit rerun, by the pre-spawn check.

If the filesystem cannot do the move (EXDEV, EINVAL, ENOSYS), the swap rolls back any move already done, deletes the journal, and disables swaps for that directory; status says so. A login is never copied as a fallback.

oauthAccount

oauthAccount is the account name and organisation Claude shows in /status. amplihack saves each profile's block to accounts/<name>.json while that profile holds its own login. In step 4 it patches only that key in <live dir>/.claude.json:

  • the file is opened without following symlinks and read up to 32 MiB;
  • if the file is missing, larger than that, a symlink, or not a JSON object, the patch is skipped silently and only the login moves;
  • if no saved block exists for the incoming account, the patch is skipped with a warning that ends /status may name the previous account;
  • if the saved block is damaged, the patch is skipped with the warning auto-switch ignored damaged account details: <error>;
  • if oauthAccount already equals the saved block, nothing is written;
  • otherwise the new content goes to a temp file in the same directory, which is synced and renamed over the file, keeping the file's existing mode; if that write fails, it warns auto-switch could not update <dir>/.claude.json: <error>;
  • if the file changes while it is being patched (inode, size or mtime differ), it retries once and then skips with the warning <dir>/.claude.json kept changing; account details not updated.

.credentials.json decides which account is live; oauthAccount is only a display. Claude keeps .claude.json in memory and rewrites it, so a write by Claude can bring back the previous account's name in /status until Claude next rewrites the file or the session restarts. Requests still use the moved login. Other cached account fields are left alone.

Leases

A directory is live when a process of yours, other than amplihack itself and not a zombie, has a CLAUDE_CONFIG_DIR in /proc/<pid>/environ that resolves to it, and that process is a Claude or amplihack executable (by its name or the basename of argv[0], or node running Claude Code) or is named by the directory's sessions/<pid>.json. Any other process with the variable set, such as a shell or a tmux server, is not evidence (issue

3495). Relative values are resolved against that process's working

directory. Only processes with your real user ID are read.

A process whose environment cannot be read (not dumpable, changed credentials, or an environment over 16 MiB) is judged from its command line and its name, never from its environment:

  • It counts only when it is a Claude or amplihack executable: the name in /proc/<pid>/status, or the basename of argv[0], is claude, amplihack or amplihack-*, or it is node running the Claude Code cli.js. Text elsewhere in the command line does not make a process Claude-like, and /proc/<pid>/exe is never read.
  • A Claude or amplihack executable makes doubtful only the profiles it can be tied to, and a doubtful profile counts as live. When it is tied to several profiles, each is doubtful. Two things tie it to a profile:
  • Its arguments: an argument after argv[0] that is <root>/<name>, a path under it, or any =-separated part of an argument that is such a path (KEY=<that path>, --env=CLAUDE_CONFIG_DIR=<root>/x).
  • Claude Code's own session file for it, <root>/<name>/sessions/<pid>.json. Claude Code writes that file in the config directory it runs under, including for -p runs (checked with Claude Code 2.1.330; an older one may not write it). Only the file's name is looked up; the file is never opened. A file of any age counts, because a stale one can only delay a swap. A profile directory or sessions directory that is a symlink ties nothing, so one sessions directory shared by several profiles cannot make all of them live.
  • A Claude or amplihack executable tied to no profile makes no profile live, and is logged as profile cannot be told. The login it uses is not protected. Suppose it uses a profile through CLAUDE_CONFIG_DIR set only in its own environment, and Claude Code has written no session file for it under that profile. The rotator can then move that login out from under it. This is the one case where the scan's guess leans unsafe. The alternative, making every profile live, would let one such process stop all rotation, which is the fault issue #2820 fixed. Two other sources were considered, and neither helps. A readable relative with CLAUDE_CONFIG_DIR set makes its profile live by the rule above only when it is itself a Claude or amplihack executable or is named by a session file, such as the amplihack launcher that started it. /proc/<pid>/cwd is behind the same access check as environ for a process that is not dumpable or changed its credentials, and it names a working directory, not a config directory.
  • Any other unreadable process, such as tailscaled be-child ssh or ssh-agent, is not evidence and makes no profile live.

One unreadable process therefore never makes every profile live. A readable process whose environment names a profile makes that profile live only when it is a Claude or amplihack executable, by the same test, or when that profile holds Claude Code's sessions/<pid>.json for it (issue #3495). A shell, a tmux server or a helper left from an earlier launch keeps the variable for as long as it lives, and is no evidence. When the process table itself cannot be read (every system but Linux), every profile counts as live. The session archive reads the same table and still fails closed for any unreadable Claude or amplihack executable, because it cannot tell which directory that process uses; the cost is one deferred archive.

Each unreadable process that mentions claude or amplihack, or is a Claude or amplihack executable, is named once in the rotate log.

Account X is leased to directory Y when Y is not X and the ledger says X is live in Y. These are refused before claude is spawned:

Action Refused when Error
Launch, run or login of profile X X is leased elsewhere Leased
Launch or run of profile X directory X is hosting another account, unless the launch joins the session using it HostsForeignAccount
login X directory X is hosting another account (no exception) HostsForeignAccount
remove X X is in the ledger, has a parked login, or hosts another account Leased or HostsForeignAccount

Joining a hosted session

A launch joins the session in directory X only when all of these hold:

  • the profile was inherited (tier 2 of resolution), not given by --profile, profile run or the default pointer;
  • the launcher's own CLAUDE_CONFIG_DIR is set; and
  • that value, canonicalised, is equal to the canonical path of <root>/X.

The comparison is between whole canonical paths. It never uses the value of AMPLIHACK_CLAUDE_PROFILE, a profile name, or a string prefix. A fresh shell that runs export AMPLIHACK_CLAUDE_PROFILE=work without the session's CLAUDE_CONFIG_DIR does not join and is refused with HostsForeignAccount.

A launch that joins shares the session's current login. The checks run under the global lock and again just before spawn.

Leases are interlocks against accidents. They are not a security boundary against other processes running as you.

Session end and recovery

These steps run at the start of every launch, profile login, wrapper run and auto-switch repair, and when a launched Claude exits (before amplihack exits, on success and on error). auto-switch status does not run them; it only reports what they would do. They run whether the switch is on or off, as long as <root>/.auto-switch.d/ exists:

  1. Interrupted swap. If journal.json exists, the state is worked out from which of the two known paths each login is at. If the incoming login has not reached the live directory, the swap is rolled back; if it has, step 4 of the swap is finished. A journal whose phase is inconsistent, or a layout that matches neither case, is reported as inconsistent and nothing is moved. Recovery replays forward or back by moving files; it never copies one.
  2. Return. Every hosted directory that is no longer live (no running process of yours uses it; see Leases) is returned: the borrowed login goes back to its home slot, the owner's parked login goes back into its directory, the owner's oauthAccount is restored, and the ledger entry is removed. If the borrowed login is missing (for example after /logout), the owner's login is still returned.

A damaged, unknown-version or unknown-field ledger.json or journal.json is never overwritten. Launches and logins for the profiles involved fail with AutoSwitchInvariant and nothing is moved. The how-to's Recovery section explains how to repair it by hand.

Nested launches and auto-switch

Applies only when the switch is on and the profile was inherited (tier 2 of resolution). An explicit --profile and the default pointer are never redirected.

If the account live in the inherited directory is exhausted, the launch uses the first eligible candidate that holds its own login at home and is not hosting another account. The child gets AMPLIHACK_CLAUDE_PROFILE=<candidate> and CLAUDE_CONFIG_DIR=<root>/<candidate>, the candidate gets the normal pre-spawn check, and one line naming both profiles goes to stderr. Nested launches never move logins. With no candidate, the inherited profile is used as today. --docker and --auto are still refused with an inherited profile.

multitask workstreams apply the same choice to the AMPLIHACK_CLAUDE_PROFILE line their run.sh exports, and each nested launch checks again when it starts.

Usage-limit reruns

Applies when the switch is on, the profile was inherited, there is no --profile, Claude's arguments contain -p or --print, and the launch is not --docker or --auto. That is how recipe agent steps run.

The launch runs Claude under a supervising amplihack process:

  • stderr streams live; its last 64 KiB is kept;
  • stdout is written to a private temp file under <root>/.auto-switch.d/rerun/ and printed once, after the final attempt;
  • the first attempt inherits stdin unchanged, except a prompt piped on stdin, which is copied as it arrives and replayed on every attempt (see Stdin). A rerun gets a regular file again from where the step started reading it, a terminal unchanged, and, for a piped prompt, a read-only regular file holding the stored copy, opened at offset 0 (not a pipe). A closed descriptor gets /dev/null, as does a pipe or a socket on a launch whose prompt is in the arguments instead, since nothing was copied from it. The supervisor's main thread never reads stdin. The copier thread does, and only once the first attempt is running; the supervisor joins it before a rerun, and only when it is certain to finish, so a pipe that never reaches end of file refuses the rerun rather than holding the step up (see Stdin);
  • SIGTERM and SIGHUP are forwarded to the attempt; SIGINT reaches it through the terminal.

An attempt counts as hitting a usage limit only when all of these hold:

  1. it was not killed by a signal;
  2. it exited with a non-zero status; and
  3. the recipe runner's own classifier, applied to the kept stderr tail followed by the last 64 KiB of buffered stdout, returns its usage_limit class. That is the same classifier, with the same markers (session limit, 5-hour limit, usage limit, usage_limit_reached, quota exceeded, monthly limit, weekly limit, hit your opus limit, hit your sonnet limit, hit your fable limit, spend limit) and the same precedence, the runner uses to end a run with a usage-limit message. Work markers are checked first, then environmental ones, then usage-limit ones, so a tail that also matches a work or environmental marker is not a usage limit. For example, a claude -p stdout tail that contains permission denied anywhere is classed as environmental and the step is not rerun, even if it also says usage limit. Two usage-limit-like messages are environmental for the same reason and never cause a rerun: credit balance is too low (an environmental marker, checked first) and disk quota exceeded (which matches the environmental marker before quota exceeded).

Using one classifier means the supervisor and the runner cannot disagree: a step the runner would end the run for is always offered a rerun first. A false match costs one extra attempt, which is no worse than today's termination.

The reset time comes from Claude's own message: if a line starts with Claude AI usage limit reached| followed by digits, those digits are the reset epoch. The last such line in the stderr tail is used, else the last in the stdout tail. The text must start the line: a line such as model: Claude AI usage limit reached|1 does not supply a reset time. Otherwise it is five hours from now. The account's five-hour window is recorded as 100% used until that time, and never later than five hours from now. A note naming both profiles goes to stderr, and the step runs again under the next eligible profile. Each remaining profile is tried at most once per step. When none is left, the usage-limit wait runs if it is enabled. Otherwise the last attempt's output and exit code are passed back unchanged, and the recipe runner reports the usage limit and ends the run.

Reruns happen at the step-launch layer: inside the nested amplihack claude -p that each agent step runs. The recipe runner's retry loop, its executor and its failure classifier are unchanged; the runner only sees the final attempt.

The supervised attempt runs with AMPLIHACK_AUTO_SWITCH_SUPERVISED=1, which stops it supervising itself; amplihack removes that variable before it starts Claude. If the supervisor cannot start, the launch runs unsupervised, with a warning.

The stdout buffer is rerun/<pid>-<n>.out, where <pid> is the supervisor and <n> the attempt. It is deleted when the attempt is rerun or its output has been printed. If the supervisor is killed first, recovery deletes it once no process with that <pid> is running, and any buffer older than 24 hours regardless. Files whose names do not match <pid>-<n>.out are never deleted, whatever their age. Recovery runs at every supervisor start as well as at the points listed in Session end and recovery. Until then each buffer holds whatever the step printed, at mode 0600 in a 0700 directory.

A rerun starts the step again from the beginning, so anything the attempt that hit the limit had already done (a commit, a push, a comment) may be done again.

Capacity notice

When auto-switch is on and every eligible account is at or above the threshold, amplihack says so in the status line, in Claude Code (through the hooks), and when amplihack claude or amplihack recipe run starts. The notice only informs: it makes no swap, refuses nothing and changes no exit status. With the switch off, none of this runs and behaviour is unchanged.

Capacity file

The state lives in <root>/.auto-switch.d/capacity.json:

{
  "version": 1,
  "state": "low",
  "threshold": 90,
  "over": ["personal", "work"],
  "earliest_reset": "2026-10-22T09:00:00Z",
  "written_at": "2026-10-20T14:03:11Z",
  "writer": "statusline"
}
Field Type Meaning
version integer Always 1.
state "ok", "low" or "exhausted" See Capacity states.
threshold integer 1–100 The auto-switch threshold the state was computed with.
over array of profile names The eligible accounts at or above the threshold, sorted, no duplicates. Excluded and overflow profiles are not eligible.
earliest_reset RFC 3339 UTC string or null When the first of the over accounts gets capacity back. null when no reset time is known.
written_at RFC 3339 UTC string When the file was written.
writer "statusline", "usage" or "rotate" Which command wrote it.

The file holds profile names, the state, the threshold and times only. It never holds account IDs, e-mail addresses, tokens or credential paths, and no reader ever shows over or writer to you or to the model.

Capacity states

The eligible accounts are the profiles that profile list shows, minus the exclusion list. Listing reads the root directory; it runs no probe.

  • An account is over when it has a reading and the higher of its two adjusted windows is at or above the threshold. This is the same test that makes an account exhausted in Candidate selection.
  • An account is at its limit when the same test passes at 100%, when it has a usage_limit_failure reading whose window has not reset yet, or, for the rotator only, when its probe reported session_exhausted or weekly_exhausted.
  • An account with no reading, or whose probe failed, is not over. Missing data never raises a notice.
State When
exhausted Every eligible account is at its limit.
low Every eligible account is over, and at least one is not at its limit.
ok Anything else, including no eligible profiles.

With a single eligible profile, the state is low as soon as that account crosses the threshold.

With overflow profiles, a state that would be low or exhausted is ok when an in-session swap would move onto an overflow profile now (Auto-switch and overflow profiles), judged by the same functions the selection uses:

  • the gate allows it: no eligible plan account has room (both windows below 100%; an API-key profile is never a plan account; the API key also needs a reading for each of them), and the earliest plan reset is more than the overflow wait away. The plan reset here is the gate's, the reset of the window at the gate's threshold, or the later of the two when both are, not the reset of the window over the auto-switch threshold;
  • some overflow profile is listed, not excluded and not spend-blocked. Its own plan reading does not count.

For example, an account at 87% session (resetting in two hours) and 95% week (resetting in ten minutes) has plan capacity again only in two hours, so with the default 30-minute wait the session moves onto credits and the state is ok, although the week window alone would reset inside the wait.

An account's reset time is the time it gets capacity back: the later of the two resets_at values when both windows are over, otherwise the resets_at of the window that is over. Only reset times in the future count. earliest_reset is the earliest known reset time among the over accounts, or null when none is known.

When the notice clears

Readers do not trust the stored state forever. The state they act on is:

  1. ok when the stored state is ok;
  2. ok once earliest_reset has passed. The first account to reset means not every account is over any more, so the notice stops without anyone rewriting the file;
  3. when earliest_reset is null, the stored state until 5 hours after written_at, then ok.

The 5-hour bound is the only time-based expiry, and it applies only when the reset time is unknown, so a notice can never stay up indefinitely. 5 hours is the length of the session window. A writer that keeps seeing the same state rewrites the file at least hourly in that case, so the bound does not clear a state that is still true.

Capacity writers

Only the three commands that already evaluate capacity write the file. None of them makes an extra network call or probe for it.

writer Written Readings used
statusline By the status-line wrapper each time it records a reading, under the state lock it takes for that. The ~/.claude status line never writes the file. usage.json as just recorded.
usage By profile usage, each time it records readings, under the state lock it takes for that. usage.json as just recorded.
rotate By the rotator, in a cycle that reaches the swap, stay or ALERT, under the lock taken in step 6. That cycle's probes. A session_exhausted or weekly_exhausted probe counts as at its limit; a failed probe, including one that timed out, counts as no reading and never as at its limit. Reset times come from the profile's usage.json entry while they are in the future, and are otherwise unknown.

All three use the auto-switch threshold and exclusion list, not the rotator's --session-at and --week-at, so they agree on the state. None of them probes or refreshes an excluded profile to write the file: the statusline writer reads only files, the usage writer gets no reading for one (see Excluded profiles), and the rotate writer never counts an excluded live login as room (see Rotate excluded live profile). None of them counts an overflow profile as eligible: its capacity is credit capacity, used only by the rotator's overflow rule. While the rotator's last cycle left the live login on credits, its own write sets the state to ok. The API-key profile counts only while its login check passes: reachable, the rotator's check, in the rotator's writes and in any write while a rotator runs, and otherwise auto-switch's check of the profile's own files. A live API-key profile that fails the check does not set the state to ok. An overflow profile that holds no login of its own, as auto-switch checks it, is not counted either, unless the rotator has made it live. On macOS, when that is because its Keychain could not be read, the writer says so: the usage and statusline writers print one line on stderr, and the rotate writer writes the same line to the rotate log, for each such profile that is not excluded. The rotator's own ALERT line still follows its own thresholds. All three write while holding the global state lock, so writes never interleave and the last one wins. A writer that cannot get the lock records nothing and writes no capacity file. The three take reset times from the same usage.json entries, so a later write differs from an earlier one only by the readings taken in between.

Usage-limit reruns do not write the file. A step that runs out of profiles shows no notice until one of the three writers next runs.

When the rotator's cycle ends on an overflow profile (last_cycle.overflow is in or on), the rotate writer records ok whatever the readings say, because work can go on at the cost of credits. Like any ok, this replaces an existing file but never creates one. The statusline and usage writers apply only the overflow rule in Capacity states; they do not know whether the rotator's live login is on credits, and may write an exhausted state in between. The rotator's next cycle replaces it.

Write rules:

  • The file is written only while the effective setting is on. With the switch off it is neither written nor read, and a file left from before is ignored. This gate applies to the rotator too: with no <root>/.auto-switch and no AMPLIHACK_CLAUDE_AUTO_SWITCH, the rotator still rotates and writes its ALERT, but no notice appears anywhere. Turn auto-switch on to get the notice.
  • Writes go through a private temp file, are synced and renamed into place. The file is 0600 in the 0700 state directory, and is never written through a symlink.
  • The write is skipped when state, over, threshold and earliest_reset are all unchanged, so the status line does not sync a file every turn. The exception: when earliest_reset is null and written_at is more than 1 hour old, the file is rewritten to keep the 5-hour bound from expiring a state that still holds.
  • An ok result never creates the file. It only replaces an existing one.
  • A failed write is logged at debug level, naming only the operation and the error kind. It never changes the writer's output or exit status.

Reading the capacity file

The hooks, the status-line wrapper, launches and recipe run read the file the same way. They take no lock, start no process and use no network.

  1. Root. Chosen in the same order as the profile root: AMPLIHACK_CLAUDE_PROFILE_ROOT, then ~/.amplihack/profile-root, then ~/.amplihack/claude-profiles, with the same checks on each value. A value that fails them means no notice; the reader never falls back to the default root.
  2. Gate. The notice is shown only when the effective setting is on: AMPLIHACK_CLAUDE_AUTO_SWITCH=1 or 0 wins, any other value is ignored, and otherwise <root>/.auto-switch must be a valid settings file with enabled=on. Nothing is printed about a bad variable on this path.
  3. File. It is opened without following symlinks and without blocking, so a FIFO cannot hang a hook. It must be a regular file owned by you, at most 16 KiB, valid JSON with "version": 1, a threshold from 1 to 100, and a written_at no more than 5 minutes in the future. Unknown fields are accepted. An earliest_reset more than 8 days after written_at is treated as unknown.

If any step fails, the reader acts as if the state were ok: no notice, no error, and the caller's output is unchanged.

Notice text

The line has two forms, built only from fixed text, the state, the threshold and the reset time:

⚠ all Claude accounts ≥90% · next reset Oct 22 2am
⚠ all Claude accounts at limit · next reset Oct 22 2:30am

The first is low and shows the configured threshold; the second is exhausted. The reset time is in local time, with minutes only when they are not zero. When the reset time is unknown, the end reads next reset unknown.

Where When What is shown
Status line Every render while the state is low or exhausted. The line, below the original status line.
Claude Code, through the SessionStart and UserPromptSubmit hooks Once per state per session, and again when the state gets worse. The line plus — run 'amplihack profile usage' as a user-visible message, and a note to the model. See Hook specifications.
amplihack claude and amplihack launch At start, on stderr. The line plus — run 'amplihack profile usage'.
amplihack recipe run At start, on stderr, before the recipe runs. amplihack recipe run: + the line + — run 'amplihack profile usage' (continuing anyway).

Examples:

⚠ all Claude accounts ≥90% · next reset Oct 22 2am — run 'amplihack profile usage'
amplihack recipe run: ⚠ all Claude accounts at limit · next reset Oct 22 2am — run 'amplihack profile usage' (continuing anyway)

amplihack claude and launch print nothing when the arguments contain -p or --print, or when they run inside a recipe (AMPLIHACK_SESSION_DEPTH is a number above 0), so recipe agent steps do not repeat the warning. recipe run prints nothing when it is itself nested. Neither ever prompts, refuses to run or changes the exit status.

Status line. When the state is low or exhausted, the wrapper passes the original command's standard output through unchanged, with no size cap, then writes the line on its own line: a newline first only if the original output was not empty and did not end with one, then the line, then a newline. The original command's standard error and exit status, including death by a signal, pass through unchanged. When the switch is off or the state is ok, the wrapper runs exactly as it did before this notice existed and its output is byte-identical.

work · opus 4 · 5h 93%
⚠ all Claude accounts ≥90% · next reset Oct 22 2am

Notice records

The hooks remember the last state they showed for each session in <root>/.auto-switch.d/notice/<session id>. The file name is the session ID with unsafe characters replaced, cut to 128 bytes. The file holds one word, low or exhausted, and is read up to 64 bytes; anything else counts as no record.

Current state Last shown Result
low or exhausted none Show, record the state.
low low or exhausted Nothing.
exhausted low Show again, record exhausted.
exhausted exhausted Nothing.
ok anything Nothing, and delete the record, so a later drop shows again.

A hook call without a session ID shows the notice every time the state is low or exhausted, because there is nothing to key a record on.

Records are written only when .auto-switch.d/ and notice/ are real directories owned by you with no group or other permissions (notice/ is created 0700). Each record is a 0600 temp file renamed into place. If the directories fail the check, nothing is written and the notice is still shown. When the state goes back to ok, the session's record is removed only if both directories already pass that check; otherwise it is left alone. Each write also deletes records older than 7 days, looking at no more than 256 entries, never following a symlink and removing only regular files you own. Two hooks in the same session racing on a record can at worst show the notice twice.

State directory

Everything is under <root>/.auto-switch.d/ (directories 0700, files 0600). Profile names cannot start with ., so it never clashes with a profile and never appears in profile list.

Path Contents
lock Global exclusive file lock for every ledger, journal, usage and login change.
ledger.json {"version":1,"hosts":{"<dir>":{"live":"<account>","swapped_at":<epoch>,"pre_swap_fingerprint":"<sha256 hex>"}}}. pre_swap_fingerprint is null when there was no reading before the swap. Lists only directories hosting another account.
journal.json The swap or return in progress: op, dir, from, to, phase (a step name, or inconsistent after EEXIST), plus started_at and pid for diagnosis.
usage.json Readings, as shown in Readings.
parked/<name>/.credentials.json The home slot of a profile whose directory is hosting another account.
accounts/<name>.json The profile's saved oauthAccount block. No tokens.
expected/<name>.json The profile's recorded account: {"account":"<key>","org":"<uuid>"|null}, both keys required (see Recorded account). No version field. A damaged file counts as no record; a swap from that profile prints one warning.
statusline/<name>.json The profile's original statusLine object.
rerun/ Buffered stdout of supervised steps, <pid>-<n>.out; see Usage-limit reruns for how long each is kept.
capacity.json Whether any account has capacity left; see Capacity file. Unlike the other state files, it accepts unknown fields and is capped at 16 KiB.
capacity-weights.json Optional, written by you. Each login's weight in the capacity summary; see Capacity weights. A JSON object, capped at 64 KiB, with no version.
usage-history.jsonl One line per measured cycle from profile usage and the rotator, kept for eight days; see Usage history. JSON lines, not one JSON document; read from the last 4 MiB.
usage-history.lock Lock for writers of usage-history.jsonl. Separate from lock.
key-held The unmeasured plan profiles named by the last ALERT: API key not used session=… that auto-switch wrote to the rotate log, one name per line, so the same set is logged once. Removed once every plan profile has a reading. Written by the launch and rerun checks only, never by the usage-limit wait's capacity check. Not JSON.
notice/<session> The last capacity state shown in a Claude session; see Notice records. Unlike the other state files, it is a bare word, not JSON, and is read up to 64 bytes.

Apart from capacity.json, capacity-weights.json, usage-history.jsonl and notice/<session>, every state file has "version": 1, rejects unknown fields and is capped at 64 KiB. Each name in them is checked with the name rules before it is used in a path. A damaged accounts/ or statusline/ file is ignored with a warning and not overwritten.

Before any state write or login move, the root must be owned by you and not writable by group or others (with the same private-group exception as install), and every path must be inside the root, owned by you and not a symlink.

Platform support

Platform In-session swap Nested substitution and reruns
Linux, /proc/self/environ readable, login in .credentials.json yes yes
Linux where /proc/self/environ cannot be read (for example hidepid) no; status says so and nothing is moved yes
Other Unix (no /proc) no; status says so and nothing is moved yes
macOS with logins in the Keychain no; no credentials file to move, skipped silently with a status note yes, for a profile with an identifiable oauthAccount and a Keychain item. A profile whose Keychain could not be read is not a candidate. A profile resolved as an API-key profile counts with no login file, as before.
Windows and other non-Unix no no; every auto-switch command is refused with AutoSwitchUnsupported, and every other auto-switch path does nothing

An in-session swap only happens when <live dir>/.credentials.json exists. Moving a file is the only primitive that keeps one copy of a login, so there is no fallback for other storage.

Rotate

profile rotate keeps the login in ~/.claude on the account with the most capacity left by moving logins between ~/.claude and the profiles. The how-to walks through using it; this section defines its behaviour. It is separate from auto-switch, which swaps logins inside profiled sessions, but shares its toggle, its exclusion list and its state lock.

The rotator also runs a daily session archive that moves old session logs out of ~/.claude/projects.

Rotate commands

amplihack profile rotate [--dry-run] [--session-at N] [--week-at N] [--margin N] [--upgrade-margin N] [--hold SECS] [--target-week-max N] [--overflow-wait SECS] [--overflow-unknown-reset 0|1]
amplihack profile rotate start  [--session-at N] [--week-at N] [--margin N] [--upgrade-margin N] [--hold SECS] [--target-week-max N] [--overflow-wait SECS] [--overflow-unknown-reset 0|1] [--interval SECS]
amplihack profile rotate watch  [--session-at N] [--week-at N] [--margin N] [--upgrade-margin N] [--hold SECS] [--target-week-max N] [--overflow-wait SECS] [--overflow-unknown-reset 0|1] [--interval SECS] [--supervised[=UNIT]]
amplihack profile rotate stop
amplihack profile rotate status
amplihack profile rotate autostart [on|off]
amplihack profile rotate owner [clear]
Command Behaviour
rotate Runs one cycle: recover, measure, decide, and swap if needed. Prints its log lines to stdout and appends them to the log. Runs whether the toggle is on or off.
rotate --dry-run Measures and decides, then prints would ... lines and the cycle line to stdout. Takes no rotate state lock, writes no rotate state, moves nothing, and never refreshes a token or starts claude: every read is a direct read with refresh off, so an expired login shows as unmeasured with its cause, and the dry run can pick a different target than a real cycle that would have refreshed that login. It prints would refresh: expired login in ~/.claude when a real cycle would refresh the live login, and the would lines of seeding for a live profile with no record. It skips both the prototype check and journal recovery. Reports a pending journal as would recover an interrupted swap (phase <phase>) and decides as if it were not there. Reads the pin: a pin in force prints would stay (held by switch to <name>), or would stay (pin unreadable), and measures nothing. Makes the same hand-change identity reads as a real cycle, never writes hand_suspect, and reports the result as would recover: <recovered line>, would note: <note>, or would alert: <ALERT line> with its fix lines; see the dry-run table there. An inconsistent journal is reported as would alert: rotate recovery is inconsistent, and a damaged one as would alert: the rotate journal is damaged.
rotate start Checks for the prototype, runs recovery under the lock, warns on stderr if auto-switch has been turned off, refuses if a verified rotator is already running, then starts rotate watch as a detached process and writes the pid file. The check, the start and the pid file all happen under the state lock, so two starts cannot both start one. Fails with rotate: lock busy when the lock stays held for 2 seconds, and with the auto-switch error when auto-switch recovery is inconsistent. Pins the child to its root and records that root; see Rotate root record. Prints rotate: started (pid <pid>), checking every <interval>s, log: <path> and root: <path>, and returns at once.
rotate watch Runs a cycle in the foreground until SIGTERM or SIGINT, and wakes for the next one on a limit event: a change to the ledger, or the earliest recorded reset. --interval is only the outer bound of that wait. A signal is never acted on during a swap; see Signals. Refuses if another verified rotator is running. Writes only to the log, apart from the owner marker when it runs supervised.
rotate watch --supervised[=UNIT] As rotate watch, and records itself as the rotation owner so that launches do not start a second rotator. UNIT names the service manager unit, for example --supervised=amplihack-rotator.service; the = is required. Without UNIT the name is found as described in Owner unit name. A watch that systemd runs as a service records itself without the flag: INVOCATION_ID is set and the unit is found in /proc/self/cgroup as in step 2 of Owner unit name. Like any watch, it refuses with status 1 when another verified rotator is running, and then writes no marker; stop that rotator with rotate stop before starting the unit. rotate start --supervised is refused with RotateRefused (--supervised applies to rotate watch only, status 1).
rotate stop Finds the rotator as described in Rotate root record. Sends SIGTERM to a verified rotator, waits up to 10 seconds for it to exit, then removes the pid file and prints rotate: stopped (pid <pid>).
rotate status Read-only. Prints the status lines and exits 0.
rotate autostart Read-only. Prints the effective autostart state, for example autostart: on (default).
rotate autostart on\|off Writes the autostart setting and prints autostart: on (setting) or autostart: off (setting). Does not start or stop a rotator. When the value changes, appends a change: line to the log. Any other value is a usage error (status 2).
rotate owner Read-only. Prints the owner line, as in rotate status, for example owner: none.
rotate owner clear Removes the owner marker and prints owner: cleared (was <unit>), or owner: none when there was no marker. Does not stop a running rotator. Under a profile root that is not private, it reads and removes nothing and fails with RotateRefused (profile root <reason>; the owner marker was left in place, status 1).

--dry-run belongs to the one-shot form only. Tuning flags go after start or watch; amplihack profile rotate --margin 3 start is a usage error and exits with status 2.

On platforms without Unix file semantics, such as Windows, every form fails with RotateUnsupported before doing anything else. That is the only use of RotateUnsupported. On a Unix system or filesystem that cannot exchange two files atomically, the swap is refused with RotateRefused; see Rotate swap.

Overflow commands

amplihack profile overflow add <name> [--tier N]
amplihack profile overflow remove <name>
amplihack profile overflow list
amplihack profile overflow clear <name>

These act on the resolved profile root, the same root the rotator uses. The marks are kept in the overflow key of <root>/.auto-switch; spend blocks are kept in the rotate ledger. What the rotator does with them is in Rotate overflow.

The marks live in .auto-switch, not in the layered config.toml, because the rotator and auto-switch already re-read that file on every cycle and every check, and auto-switch takes its exclusions from it. Keeping the marks there gives one source of truth for which profiles are skipped and when.

Command Behaviour
overflow add <name> [--tier N] Appends <name> to the overflow list in tier N (1 to 9, default 1). For an API-key profile the mark is the consent to per-token billing: it is stored as the bare name and always read as tier 10, after every credit tier, and --tier is refused with PlatformTierFixed before anything is written. The name must pass the name rules and be an existing profile directory under the root (not a symlink); otherwise the command fails, names the profile and changes nothing. Prints overflow: added <name> (tier N) and the cost note below. For a profile already marked, --tier moves it (overflow: <name> moved from tier A to tier B), and without --tier the tier is kept (overflow: <name> is already marked (tier N)); both exit 0. Prints a warning when <name> is in the exclude list, and another when the default pointer names it.
overflow remove <name> Removes <name> from the list. The name must pass the name rules; it does not have to exist. Prints overflow: removed <name>, or overflow: <name> is not marked and exits 0; overflow list agrees with it, showing the profile as marked before a successful remove and not at all (or, for an API-key profile, as not marked (not used)) after it. A spend block for the profile is left in the ledger and expires on its own.
overflow list Read-only. Prints one line per marked profile, in the order the rotator and auto-switch try them (by tier, then list order within a tier): the name, tier N, marked, then missing when the root has no profile directory of that name, then blocked until <time> (spend_limit) when it has an active block. After them comes one line per API-key profile, marked or not: <name> api-key tier marked or <name> api-key tier not marked (not used). Prints overflow: none when there is no line to print. Takes no lock. A rotate ledger that cannot be read prints a warning on stderr and the marks without blocks; the command still exits 0.
overflow clear <name> Removes the spend block for <name> from the rotate ledger. Takes the rotate state lock, retrying for up to 10 seconds; if it is still held, fails with RotateDaemon and the message rotator busy, retry. Prints overflow: cleared the spend block on <name>, or overflow: <name> has no spend block and exits 0. The name must pass the name rules; it does not have to be marked or exist, so a block left after overflow remove, or one a step wrote for a plan login, can still be cleared. Never creates the ledger.

What add prints for a new mark, with the cost note:

overflow: added login-aw (tier 1)
note: login-aw is used only when no measured plan login is below 100% on both windows and the earliest plan reset is more than --overflow-wait away; work on it is billed to that account.
note: set a spend limit for the organization at https://claude.ai/settings/usage; the rotator is not a spending cap.

The warnings add prints, on stderr:

warning: login-aw is in the auto-switch exclude list; excluded profiles are never used, even as overflow
warning: the default profile is login-aw; launches use it directly and spend credits whatever the rotator does (run: amplihack profile switch --none)

overflow list with one blocked profile:

login-aw  tier 1  marked  blocked until 2026-11-01T00:00:00Z (spend_limit)
team-credits  tier 1  marked
old-credits  tier 1  marked  missing
api-key  api-key tier  not marked (not used)

What add prints for an API-key profile:

overflow: added api-key (api-key tier, tier 10)
note: api-key is billed per token; it is used only when every plan login is measured and none is below 100% on both windows, no credit profile can be used, the earliest plan reset is more than --overflow-wait away and its login check passes.

overflow list after that add:

login-aw  tier 1  marked  blocked until 2026-11-01T00:00:00Z (spend_limit)
team-credits  tier 1  marked
old-credits  tier 1  marked  missing
api-key  api-key tier  marked

Overflow tiers

A credit profile's mark has a tier from 1 to 9. Tier 1 is tried before tier 2, and so on; within a tier, the order the profiles were added decides. Tiers rank credit profiles by cost, so the order of names in the file never has to carry that meaning. A marked API-key profile is always tier 10, after every credit tier, whatever tier the file gives it. Only marked profiles have a tier: an API-key profile that is not marked has none and is never used. In .auto-switch an entry is written name:tier, and a tier-1 entry as the bare name, so a file written before tiers existed reads the same:

overflow=login-aw,team-credits:2,api-key

Here team-credits is tier 2 and api-key, an API-key profile, is tier 10 whatever its position or written tier.

Every tier, credit and API key alike, is billed per token or per credit, so the rotator uses none of them while a measured plan login is a usable target under the target rule. Auto-switch keeps the room test of below 100% on both windows. The API key also waits for every plan login to be measured. See Rotate decision order.

The rotator and auto-switch move onto an overflow profile only from a plan profile, or from an overflow profile that is spend-blocked or exhausted. They do not move from a tier-2 profile to a tier-1 profile that becomes usable again; they move back to a plan profile as soon as one has capacity, or has room. For the rotator, a login with room is moved back to when it is eligible under the target rule, which a login with its week above --target-week-max or a recorded block is not.

add and remove change only the overflow key of <root>/.auto-switch, through the same locked write as the auto-switch commands (see Settings file). A missing file is created with enabled=off. A corrupt file is refused with AutoSwitchExcludeAtRisk and left unchanged. Because the write holds the lock, a remove that reports success is never lost to a concurrent auto-switch exclude, on or rotator cycle. If the lock is busy for 10 seconds, the command fails with the .auto-switch is being changed by another process message and changes nothing; run it again. Messages and warnings are printed after the lock is released.

All four commands exit 0 on success and 1 with the usual error:/hint: lines on failure. Output holds profile names, times and fixed text only.

Rotate settings

Flag Variable Default Range
--session-at N AMPLIHACK_ROTATE_SESSION_AT 85 1-100 (%)
--week-at N AMPLIHACK_ROTATE_WEEK_AT 90 1-100 (%)
--target-week-max N AMPLIHACK_ROTATE_TARGET_WEEK_MAX 95 1-100 (%); a login whose week use is above N is never a move target; see Rotate target choice
--margin N AMPLIHACK_ROTATE_MARGIN 5 0-100 (points)
--upgrade-margin N AMPLIHACK_ROTATE_UPGRADE_MARGIN 30 0-100 (points)
--hold SECS AMPLIHACK_ROTATE_HOLD 3600 0 or more (seconds); 0 disables the hold; see Rotate hold
--overflow-wait SECS AMPLIHACK_ROTATE_OVERFLOW_WAIT 1800 0-604800 (seconds); see Rotate overflow
--overflow-unknown-reset 0\|1 AMPLIHACK_ROTATE_OVERFLOW_UNKNOWN_RESET 0 1 lets a plan reset that no reading reports count as further away than --overflow-wait, so it can move work onto an overflow profile and spend money; see Overflow decision
--interval SECS AMPLIHACK_ROTATE_INTERVAL 600 1-86400 (seconds); start and watch only

--interval is the longest the rotator waits between cycles. A limit event or a recorded reset ends the wait sooner; with neither, a cycle still runs once per interval. It stays as that outer bound while limits arrive as events, and a later change may remove it.

A flag beats its variable, and the variable beats the default. An empty variable counts as unset. Values are unsigned decimal integers: a sign, whitespace, a fraction or an overflow is an error. The error names the flag or variable and shows the value escaped and cut to 32 characters:

error: invalid rotate setting --session-at "eighty": expected a whole number from 1 to 100
hint: run `amplihack profile rotate --help` for the accepted values

start resolves every setting and passes them to the background process as explicit flags, so the variables are read once, when start runs. A rotator started by autostart takes them from the environment of the launch that started it. The background process sets no AMPLIHACK_ROTATE* variable in the environment of the claude processes it starts.

The probe method, deadline and parallelism are not rotate settings: they have no flags and come from the AMPLIHACK_PROFILE_USAGE_* variables in the rotator's environment. See Probe settings in the rotator.

The thresholds and margins are independent of the auto-switch threshold. The auto-switch exclude list applies to rotation, and so does the overflow list in the same file; see Rotate overflow. --overflow-wait has no effect while no profile is marked as overflow.

--target-week-max is independent of --week-at, and the two are not checked against each other. With the defaults a login at 91% of its week is past --week-at, so the rotator leaves it, and is still a valid target, because it is not above 95%. start passes the resolved value on to the background process like every other setting. Auto-switch does not read it.

Rotate cycle

Every non-dry-run cycle runs these steps in order:

  1. Prototype check. See Prototype coexistence.
  2. Toggle. watch only: if auto-switch has been turned off, by auto-switch off or AMPLIHACK_CLAUDE_AUTO_SWITCH=0, or its settings file is damaged (see Toggle and precedence), write idle: auto-switch is off once per change from on to off, and skip the rest. With no setting at all (no <root>/.auto-switch and no variable), rotation runs.
  3. Lock and recover. Take <root>/.auto-switch.d/lock, waiting up to 2 seconds. If it is busy, log skip: state lock busy and end the cycle. Under the lock, run auto-switch recovery, then read the exclude list (an unreadable list counts every profile as excluded and pauses the cycle before it measures), then rotate recovery, then the one refresh of an expired live login, then the unreadable-ledger stop, then hand-change recovery, then identify the live profile, seed its record if one is missing and allowed, and find the candidates. Hand-change recovery makes its identity reads here, under the lock, unless the last swap is under SWAP_GRACE old. Identification and swap authorization have their own required trusted readings, including during that recovery grace. If recovery refused or holds an open suspicion, it writes its note or guidance and the cycle ends as alerted; if it moved a login, or found nothing, the cycle carries on from the resulting state. An ALERT about the live login (no-login, hand-change, an identity refusal, or ambiguous) is written here and ends the cycle. Then check the rotation pin: if it holds rotation, log the skip: held by switch ... or skip: pin unreadable ... line, clear the stored ALERT key, record the cycle as held (unless the last cycle is the switched record of a profile switch, which is kept) and end the cycle without measuring. Release the lock.
  4. Measure. Read the live login and every candidate, as profile usage does (passive, direct, then claude). A live profile in the exclude list is not read; see Rotate excluded live profile. Reads use the same method, deadline and parallelism bounds. The cycle waits for the reads only until --interval minus 2 seconds after it started; a read still running then is used by a later cycle, as described in Reads that outlast a cycle. The live probe counts against the bound, so a cycle never runs more probes at once than the bound: with a bound of 2 or more the live probe runs beside the candidate probes, and with a bound of 1 it runs first and the candidates follow one at a time. The live login is probed with CLAUDE_CONFIG_DIR removed from the environment, so claude uses ~/.claude and ~/.claude.json. Candidates are probed with CLAUDE_CONFIG_DIR=<root>/<name>. A live login or candidate marked as overflow is probed with /usage only, as profile usage does. Claude's output is parsed and dropped; only percentages, reset times and states are kept, and --raw output is never collected. No lock is held.
  5. Decide. See Decision rule and Rotate target choice. The cycle reads the usage history once, and only when a candidate is unknown, for its last good reading. A swap target chosen by its reading is then confirmed by a fresh reading and passes the freshness gate, which may read it again and decide again. No lock is held.
  6. Revalidate and swap. watch first checks for a pending signal and, if there is one, ends the cycle and exits without taking the lock (see Signals). Take the lock again, identify the live profile and the candidates afresh, and compare them with step 3 as described in Rotate revalidation. A change that affects the decision ends the cycle with skip: state changed during measurement (<labels>). It records last_cycle as skipped only when the ledger's last_cycle is older than this cycle's measurement. A record written while the cycle measured, such as the switched record of a profile switch, is newer and stays. A switched record always stays. Otherwise run the swap, still under the same lock. After a swap that ran, check the shared session links of to and from.
  7. Record. Write the log lines and the ledger's last_cycle, with overflow set when the cycle moved onto, off or stayed on an overflow profile. Add any new spend blocks and drop expired ones. A stay records stayed or stayed-unread, and a no-capacity ALERT or stay note is hard or advisory, by the live reading; see Stays and capacity. When the cycle stays or raises the no-capacity ALERT and the live profile is known, also record it as live, with its account. Update the ledger's swapped_away entries: lift those that a later reading shows to have room, add the login just left when the swap moved off a full one, and prune old entries.

The overflow list is read in step 3 with the exclusion list. A change to it between steps 3 and 6 counts as a state change, so the cycle ends with skip: state changed during measurement (overflow). When overflow profiles are marked, a rotate ledger that cannot be read ends the cycle before the decision with the RotateInconsistent ALERT; the rotator never moves onto credits without knowing the spend blocks. A missing ledger means no blocks.

Between steps 6 and 7, after the swap, stay or ALERT and still under the lock taken in step 6, the cycle updates the capacity file from that cycle's readings. This writes nothing under rotate/ and does not change the decision. A cycle that ends before then does not update it: the lock busy in step 3 or 6, skip: state changed during measurement, a pending signal or stop, an inconsistent recovery, an ALERT about the live login, or a refused swap. The update is also skipped when the effective setting is off, which includes having no setting at all, even though rotation still runs then. A swap made after a reconsideration updates the file in the same way as any other swap.

Rotate revalidation

Step 4 measures without the lock and can take a minute or more, so other processes may change profiles while it runs. Step 6 compares the state it reads under the lock (the fresh state) with the state read in step 3, and looks only at what bears on the decision from step 5. Changes to profiles the decision does not use are ignored: another profile being parked, starting a session, losing its login or being leased does not stop a swap to a different target, a stay or an ALERT.

Change since step 3 Label Applies to
The rotate journal exists journal Every decision
The live profile, full trusted live account, material ownership evidence, prototype ledger state, display-file safety of ~/.claude.json, or login kind in ~/.claude/.credentials.json differs live Every decision
The rotation pin differs pin Every decision
The overflow list or its ignored entries differ overflow Every decision
The swap target is no longer a candidate target eligibility: <reason> Swap only
The swap target is still a candidate, but its full trusted account differs from step 3 or cannot be bound to the current login target identity Swap only

The live and target accounts come from login-bound trusted readings. Session JSON rewrites do not change these fields. A missing or unsafe login, or unavailable identity evidence, cannot retain an earlier authorization.

For the target, <reason> is the skip reason it now has, such as no login, excluded, session running, parked or not oauth, or gone when the profile no longer exists. When /proc can no longer be scanned, every profile is skipped as session running, so a swap ends with target eligibility: session running and a stay or ALERT goes ahead. Whether /proc can be scanned is not compared in its own right: a change in it shows only through the target's skip reason, so it has no label of its own and never affects a stay or an ALERT.

The target's full trusted account is compared with the snapshot using the account identity rule, including organization. A changed login invalidates its binding. If usage measurement refreshed the token, fresh matching identity evidence is required before the old measurement can support a swap. An account key alone cannot prove continuity. Material records and duplicate claims are revalidated when they support the selected placement, adoption or backfill; unrelated profile changes remain irrelevant.

Every usage-based swap also passes the freshness gate under the lock, using the current clock and ledger, even when none of the snapshot dependencies changed. Unchanged identity and eligibility do not prove that usage evidence is still fresh. This check uses Reread::Never: it makes stale targets unknown and decides again on the retained readings. Any replacement target must pass the same freshness, identity and eligibility checks. No external usage read runs under the lock. The unchanged-state path applies this gate before proceeding, as does target-change reconsideration.

When the snapshot is unchanged but the swap target's reading is no longer fresh under the lock, for example because it has aged past the age limit while the cycle measured, the cycle decides once again from the retained readings, with no read, as in steps 1 to 3 below. If that gives the same swap, the cycle proceeds. If it gives a swap to a different target that is a candidate in the fresh state with its step 3 account, the cycle logs revalidate: target <old> no longer eligible (stale reading); reconsidered and swaps to the new target. Any other result, including a stay or an ALERT, ends the cycle with the bare skip: state changed during measurement, with no labels, since nothing in the snapshot changed.

Exclusion is checked for the target only. Exclusion of the live profile is decided earlier, when the cycle reads the exclude list under the lock, and is not compared again here: a live profile excluded when the cycle loaded the exclude list under the lock is never probed and never re-read in that cycle, and is swapped away from as described under Rotate excluded live profile. A change to exclude made while a cycle measures takes effect on the next cycle.

A journal, live, pin or overflow change ends the cycle with a skip. One of these means a person or another process has acted, for example with profile switch or auto-switch settings, and the rotator does not act against it. The next cycle measures again.

A readable session block naming the previous account does not require an identity retry or invalidate a trusted reading. The existing readability gate remains: a missing/unusable oauthAccount pauses movement and uses the documented readability retry, even when trusted identity is available. A changed login does require fresh bound evidence. If that evidence is unavailable or conflicting, the operation refuses before movement and remains visible on subsequent affected attempts.

When the only changes are to the target's eligibility or identity, the cycle reconsiders once. The unchanged-state case above follows the same steps:

  1. The failed-live-probe count is put back to its value before this cycle, so a failed live probe is not counted twice (see Failed live probes).
  2. The step 4 readings are kept, minus those of profiles that are no longer candidates or whose account has changed since step 3. Nothing is probed again, so the lock is held throughout and the readings are as recent as those of the first decision.
  3. The decision rule runs again on the fresh state and those readings, recorded with the time of the original measurement. Damping and spend-limit blocks are judged against the current time. The new target passes the freshness gate without any read: a target that is stale counts as unknown, and the decision runs again without it. That includes a target with a swapped_away entry in the ledger read under the lock whose reading is not strictly later than that entry. No reread: or damp: line is written.
  4. If it gives a swap to a profile that is a candidate in the fresh state with its step 3 account, the cycle logs revalidate: target <old> no longer eligible (<reason>); reconsidered, where <reason> is the old target's bare skip reason, such as session running, gone, account changed for a target identity change, or stale reading for the unchanged-state case, without the target eligibility: text used in the skip line. It then swaps to the new target and records the cycle from the fresh state and the new decision. Any other result, including a stay or an ALERT, ends the cycle with skip: state changed during measurement (target eligibility: <reason>) or skip: state changed during measurement (target identity).

There is at most one reconsideration per cycle. The swap still makes its own checks on the target's login and on ~/.claude before it moves anything, so a login that disappears after step 6 still causes a refusal: the revalidate: line is then followed by ALERT: swap refused: <reason> rather than a swap line.

For example, live login work is exhausted, spare and third are spare logins at 0% session use, and third is parked while the cycle measures. The decision is a swap to spare, third is not part of it, and the cycle logs:

2026-10-29T20:16:25Z cycle live=work work:s=100%,w=72% spare:s=0%,w=43% third:s=0%,w=50%
2026-10-29T20:16:31Z swap work->spare live s=100% w=72% target s=0% w=43% reason=threshold

If instead spare starts a session while the cycle measures, the cycle reconsiders and takes third:

2026-10-29T20:16:25Z cycle live=work work:s=100%,w=72% spare:s=0%,w=43% third:s=0%,w=50%
2026-10-29T20:16:31Z revalidate: target spare no longer eligible (session running); reconsidered
2026-10-29T20:16:31Z swap work->third live s=100% w=72% target s=0% w=50% reason=threshold

With spare the only candidate, the same change ends the cycle:

2026-10-29T20:16:31Z skip: state changed during measurement (target eligibility: session running)

A held cycle that records a spend-limit block makes the same comparison with the rules for a stay: it stops only on a journal, live, pin or overflow change, logs the same skip line, and never reads again or reconsiders.

The liveness scan behind live, session running and the target's eligibility reads the system process table, /proc. It decides per profile; see Leases for what an unreadable process counts for.

In the test suite, a fixture can supply a synthetic process table instead, so that sessions running elsewhere on the host do not change a test's result (#1860). The table is the one named by AMPLIHACK_TEST_PROC_ROOT, selected through procfs::proc_root(). The override is honored only when AMPLIHACK_TEST_HOME_GUARD is non-empty and the canonical path is a directory strictly inside the canonical temporary directory, owned by the current user and not writable by group or others. Otherwise the scan uses /proc. The shared rotate fixture (tests/support/profile_rotate.rs) gives every fixture an empty synthetic table by default. Tests add sessions with FakeProc and select their tree with with_proc() (#2042), including the session-running case in issue_1691_switch_live.rs; they do not read the host's sessions. The rotation-owner tests (#1803) use synthetic process tables too. Checks that precede signalling a rotator still read the real /proc, so a synthetic table cannot select a host process to signal.

Revalidation and swap completion use trusted identity; later session rewrites cannot restore the previous account in the ledger. These checks do not change the separate usage-selection and stale-reading policies.

A profile has been seen read as exhausted after its reset time: #1754.

Rotate decision rule

Headroom is 100 - max(session_used, week_used), rounded down to a whole point.

week_used is the largest of the all-models week and every per-model week in the reading (for example Current week (Fable)). Retained model weeks participate in passive readings until their individual resets. The deciding percentage and model label are separate from the all-models reset window. For equal maxima, all-models takes precedence, then models in label order. An ok reading with a per-model week at 100% or more counts as weekly_exhausted, so a login whose week for one model is used up has headroom 0 and is never chosen.

Probe result Session used Week used Headroom
ok with both windows as reported as reported as computed
ok with no session window, including no session limit 0 as reported as computed
ok with no week window probe failed
session_exhausted or weekly_exhausted 0
any other state probe failed

A profile with no session limit is ranked on its week alone: its headroom is 100 - week_used, and session-at never triggers for it. When every other login is session-exhausted, such a profile with weekly room is the best candidate. Once its week reaches week-at it is treated like any other profile over the week threshold, and at 100% it is weekly_exhausted.

Room is the same number as headroom, but only for a login with both windows below 100%. A login with a window at 100% (an exhausted reading, or a finite figure of 100 or more) has no room, and a login with no usable reading has no room figure at all.

Every swap the rotator makes for usage, whatever its reason, chooses its target by one rule, Rotate target choice: a target must be eligible, then must qualify against the live login, and the qualifying logins are ranked by the room they can use now. The rule is the same in the threshold, projected, upgrade, plan-room, failed-probe and overflow-out passes. A candidate that fails it is never chosen, whatever the pass:

  • A candidate whose probe failed for a credential reason (an expired token, a refused login, no token) is failed. It is not chosen and is counted as failed. So is a candidate whose reading holds a figure that is NaN, infinite or negative: it has no usable reading.
  • A candidate that is exhausted, has a recorded block or is above --target-week-max is not chosen. It is counted as exhausted, blocked or above the ceiling, as the no-target line says.
  • A probe that was rate-limited (HTTP 429), failed in transport, could not read the account identity, timed out, could not start claude, read its output or wait for it, or was still running is unknown, not exhausted: it is never counted or recorded as exhausted, does not have capacity, always keeps a move onto overflow out, and is probed again on the next cycle. It can be ranked on a last good reading that qualifies, but it is swapped to only after a fresh reading confirms it. See Rotate unknown readings and Failed and exhausted results.

Failed or unknown probes on some candidates do not stop a swap to another candidate that has room: with live work exhausted, a and b failed and c at s=0%,w=43%, the cycle swaps to c, in watch and in the one-shot rotate alike. The cycle writes no ALERT while any candidate has room now: the no-target line is written only when none does.

Live login (all comparisons inclusive) Outcome
In the exclude list, and a candidate is eligible Swap to the first-ranked eligible candidate, reason=threshold or plan-room. The live login counts as having no room, so every eligible candidate qualifies, and no damping, hold or home-key stay applies. See Rotate excluded live profile.
In the exclude list, no candidate is eligible, and no overflow move is possible ALERT excluded-live. No swap.
Has no room now: a window at 100%, a spend limit, or an active recorded block Swap to the first-ranked eligible candidate, reason=threshold or plan-room. No margin applies: every eligible candidate qualifies, so a login below 100% on both windows is always a target. The rotator cannot swap straight back, because a login with no room is never a candidate. No eligible candidate: ALERT no-capacity, see Rotate no target.
Probe failed The failed-probe rule below: the live login counts as room 0 and a candidate qualifies when its room is at least --margin. The swap is subject to failed-probe damping.
Has room, and session_used >= session-at or week_used >= week-at on a measured reading Swap to the first-ranked qualifying candidate: one whose room is at least max(--margin, 1) more than the live login's. reason=threshold when the target is below both thresholds, otherwise plan-room. Eligible candidates but none qualifies, or the only qualifying ones are held or not confirmed: stay, with a stay note. No eligible candidate: ALERT no-capacity.
No threshold reached on the live reading, but its projected session use one interval ahead is at or above session-at The same qualifying rule, with the live login's room taken on the projected figures and the target never in another organisation. Swap, reason=projected. No qualifying candidate: stay with a stay note, or the ALERT when no candidate is eligible.
No threshold reached, now - swapped_at >= hold (or no earlier swap), and the best candidate's room is more than the live login's and at least upgrade-margin more Swap to it, reason=upgrade. Never in another organisation.
Otherwise Stay.

max(--margin, 1) is the margin in every row where the live login has room. The floor of 1 stops two logins with the same room from swapping back and forth when --margin 0 is set. After a failed probe the margin is --margin as set, since the swap is held by damping. Auto-switch is unaffected.

swapped_at and previous (the profile swapped out) come from the ledger. During the hold no upgrade happens at all, so previous cannot come straight back by upgrade. The hold also covers one move made while the live login still has room. A move made because the live login has no room is never held, and nor is a projected swap.

Before a usage-based swap, the chosen target receives one direct confirmation, even when the current reading is fresh. Passive readings are disabled. Selection runs again on the new figures; a different target waits until a later cycle for its own confirmation.

Rotate target choice

One rule chooses the target of every usage swap: threshold, projected, upgrade, plan-room, failed-probe and overflow-out. The one-shot rotate, rotate watch and --dry-run all go through it, so a dry run reports the swap the next real cycle makes. An overflow-in move is chosen by tier, not by a reading, and is outside it. The rule has four parts: which logins are eligible, which of them qualify against the live login, how the qualifying ones are ranked, and the order in which organisations are tried.

Eligible logins

A login is a move target only if all of these hold:

  1. It is not the live login, is not in the exclude list, and, in a pass that moves onto a plan login, is not an overflow profile.
  2. It has a reading in use: a reading taken in this cycle or, for an unknown login, its last good reading.
  3. Both windows are below 100%. A login with a window at 100% has no room.
  4. Its week use is at or below --target-week-max (95% unless configured). The test is on the figure as read: 95 is eligible, and 95.4 and 98 are not. The ceiling applies in every pass, plan-room included.
  5. It has no active recorded block of any kind (a spend limit, a session limit or a weekly limit, from the rotator or from a limit event) and no spend_limit reading. The login is eligible again from the block's until time, or, for a session or weekly block a step wrote, from the cycle whose reading shows that window has reset; see A spend limit blocks the login the step ran under. The block is the first part of the rule: it rules the login out before any reading is looked at, so a roomy, stale or kept reading never overrides it. The cycle writes reject: <name> blocked until <time> (<kind>) for it; see Block reject lines.
  6. It is not failed: it is signed in, and its token has not expired.

Nothing else removes a login. A reading older than the newest reading the rotator holds for that login (this cycle's probe, the kept reading and the usage history are the candidates) is superseded: it is dropped, never ranked or swapped on, and the login counts as unknown if nothing newer is left. A reading with no time counts as older than any dated one. A failed probe and a spend-limit probe carry no figures and never move the newest time forward. In particular a login at or above --session-at is eligible; whether the rotator moves to it is decided by the next part and by the hold.

Qualifying

Eligible logins qualify against the live login's room, R, as follows:

Live login An eligible login qualifies when
Has no room now (a window at 100%, a spend limit or an active block), or is an overflow profile Always
Has room and is past --session-at or --week-at Its room is at least R + max(--margin, 1)
Has room and is below both thresholds The upgrade rule passes: its room is more than R and at least R + --upgrade-margin, the hold has ended, and it is in the live login's organisation or one that is unresolved
Probe failed Its room is at least --margin; damping then applies

So a login with room is moved off for another only when the other has clearly more to use now, and a login with no room is always moved off for any login that has some.

Ranking

Qualifying logins are ranked by the room they can use now, not by week use alone. Organisation preference comes first (see below), then these keys in order:

  1. tier: a login with session use below --session-at ranks before one at or above it;
  2. room, floor(100 - max(session, week)), larger first;
  3. week use, lower first;
  4. name, ascending by byte value.

The first login in the ranking is the target. It is then confirmed by a fresh reading, and the next login in the ranking is tried when it is not.

Organisations

Within the ranking the rotator tries logins in this order, and takes the first group that has a qualifying login:

  1. logins in the live login's organisation, whatever their tier;
  2. logins whose organisation is unresolved;
  3. logins in another organisation, a confirmed crossing, only when the live login has no room now, has its week use at or above --week-at, is an overflow profile, or its probe failed.

While a move onto a credit profile can be made, a plan login at or above --session-at does not stop the rotator from reaching a credit profile in a later group of this order. When the third group is available, the rotator moves onto a credit profile in another organisation, a confirmed crossing with the affinity: warning, in place of such a plan login in the live login's organisation. Such a plan login still keeps the API key unused. See Plan logins near their session limit.

The crossing test counts a live login whose week use is at or above --week-at as having no room, because its week does not reset within hours. An upgrade never crosses, and a live login that still has room and whose week use is below --week-at never crosses, even past --session-at, so a projected or threshold move that only another organisation can satisfy is a stay. A live login whose probe failed may cross only by the failed-probe swap, after three failures in a row, as before this rule. Every crossing writes the existing affinity: warning in the same cycle. Once the swap is authorised, the rotator compares the incoming login's organisation with the outgoing one's, using the two organisations that authorisation already read and making no further read; a crossing that the rule did not allow is refused with ALERT: swap refused: the incoming login is in a different organisation from the live login, and when either organisation is unknown the swap goes ahead as it did before. The comparison is made on both authorisation reads, including the last one before the exchange. On the organisations the decision saw, it applies the same rule and never refuses. It refuses only when a login's organisation changes after revalidation in a way the account comparison does not catch: a login with no account uuid, whose account is compared by e-mail alone. The refusal moves nothing; the next cycle reads the new organisation, passes over that login as a crossing, and chooses the next login that qualifies. Auto-switch keeps its own rule: see Organisation affinity.

Swap reason
reason= The target
threshold is below both --session-at and --week-at
plan-room has room but is at or above one of them
upgrade, projected, failed-probe, overflow-out unchanged: the reason names the pass that made the move

A swap line never carries a suffix about the target's reading: a target is swapped to only after a fresh reading confirms it; see Rotate confirmation.

Example: the day the live login filled

The reporter's flags were --session-at 85 --week-at 90 --margin 3 --upgrade-margin 30 --hold 3600, the default ceiling of 95. The live login rrowan reached 100% of its session at 05:56Z. Several logins had room:

2026-11-22T05:56:57Z cycle live=rrowan rrowan:s=100%,w=67% login-aa:s=0%,w=100% login-ae:s=96%,w=82% login-af:unknown, still running login-aj:s=90%,w=10% login-al:s=0%,w=95% login-ar:s=88%,w=20%
2026-11-22T05:56:58Z swap rrowan->login-al live s=100% w=67% target s=0% w=95% reason=plan-room

rrowan has no room, so every eligible login qualifies. login-aa has a window at 100%, and login-af is unknown with no last good reading, so neither is eligible. login-al has room 5 and login-aj, login-ar and login-ae have 10, 12 and 4, but login-al is the only login below --session-at, so its tier ranks first. Its week use of 95% is at the ceiling, so it is eligible, and reason=plan-room records that the target is past --week-at 90. The cycle writes no ALERT, because a login has room. At 05:48Z, rrowan had read s=86%,w=65%, which is room 14. A move needed 14 + 3, and the most any other login had was login-ar's 12 (login-al had 5), so the rotator stayed. With every login in one organisation the note reads:

2026-11-22T05:48:27Z stay: live room 14, best other login has room 12, a move needs 17

If rrowan is alone in its organisation, a live login with room never moves to another one, so no other login counts and the same note reads only a login in another organisation has room in place of the figure.

Rotate hold

--hold stops two logins from trading places. It applies to three kinds of move, and to nothing else:

Move Held for --hold seconds after the rotator's last swap
upgrade Always, as before
failed-probe Always, as before; see Failed live probes
A move off a login that still has room, onto a login whose session use is at or above --session-at Yes

A move to a login below --session-at, and any move made because the live login has no room, is never held: the rotator never waits to leave a login that cannot run work. A projected swap is not held either.

The third row is why login-al in the example above is not left again one cycle after the move. It has room 5 and login-ar has 12, which would qualify against 5 + 3, but login-ar is at s=88%, at or above --session-at. While the hold lasts the cycle stays and writes the held note once:

2026-11-22T05:57:58Z stay: held after last swap (60s of 3600s): login-ar is at s=88%, at or above --session-at

Once --hold seconds have passed since the swap, the next cycle swaps to login-ar if it still qualifies. The hold counts from the last swap, the ledger's swapped_at, which a rotator swap and a profile switch both write. A change made outside amplihack, such as a /login in ~/.claude, writes none and starts no hold. After the clock was set back, a swapped_at later than the clock does not hold the third kind of move. upgrade and failed-probe moves keep their existing treatment: for them a swapped_at in the future still holds the move. --hold 0 turns the hold off.

Rotate unknown readings

A probe that did not read the login says nothing about the login's usage. The rotator keeps that apart from a login that read as full.

Label The probe
HTTP 429 was answered with HTTP 429
transport could not connect, or the connection failed
identity unavailable could not read the trusted login identity, or the profile was skipped as no account
timeout timed out
still running had not finished when the cycle stopped waiting
probe error ended another way: an HTTP 3xx or 5xx answer, an answer that could not be parsed, or claude that could not be started, written to, read or waited for

A login with a label is unknown. A probe that failed for a credential reason (an expired token, HTTP 401 or 403, a refused or failed refresh, an unreadable or missing credentials file, no token) or for any reason not in the table, such as an HTTP 4xx other than 429, is failed, and a login that is failed has no label, no last good reading and is never a target. A read that produced no result at all is failed too: one that panicked, and one a rotate stop cancelled before it ran, observed nothing, so nothing is claimed about the login.

An unknown login is never counted or recorded as exhausted. The rotator does not retry it in the same cycle, adds no backoff and sets no timer: the next cycle probes it again.

Last good reading

For a candidate that is unknown, the rotator uses the login's last good reading together with its recorded blocks, so a login known to have room stays a candidate while its probes fail. The reading is the newest point for that login in usage-history.jsonl (see Usage history), used when all of these hold:

  • the point is at most 18,000 seconds (one session window) old, and is not dated in the future;
  • the point is the login's newest one: when it cannot be used, older points are not tried;
  • the week reset recorded with it, when there is one, has not passed;
  • it has a session figure, or it records that the login has no session limit, which counts as 0.

A point written in place of a stale passive reading can still inform candidate selection, which uses the batch time. The recorded week figure is a lower bound of the current figure, so such a point can overstate room. Target confirmation requires a fresh reading before a swap.

The history records a point only for a probe that read the login. A login whose later probe reported a spend limit or a refused token has no newer point, so its older point can still stand for it when a still later probe says nothing (an HTTP 429, a timeout). The age limit of 18,000 seconds and the same two rules bound it; a recorded block (spend_limit, session_limit, week_limit) always keeps the login out until its reset, or until a reading taken after it shows that a session or week block's window has reset, and the next cycle that reads the login ends the doubt.

A login skipped as no account is not a candidate, so it has no last good reading in use: it is counted as unknown and is never a target. The figures are whole percentages, so a stored w=95 may have been 95.4. The rule that a login above --target-week-max is never a target is applied to the stored figure. A last good reading is used for candidates only. A live login whose probe fails keeps the failed-probe rules. The history file is read once per cycle, and only when a candidate is unknown. A history file that is unsafe to read, owned by another user or open to group or others, is refused with one warning on stderr, and nothing is substituted.

The substitution changes the decision only. The cycle's usage history line, the capacity file, the ledger's no_room record and last_cycle.live_room keep the probe's own reading, so a guess is never written back as a measurement. A login that qualifies on a last good reading is confirmed before the swap like any other target.

In an overflow decision, an unknown plan login always keeps credits and the API key out, whatever its last good reading says: the login is still unknown after the substitution. A last good reading that shows room adds a second reason, because the login then also counts as a plan login with room. A last good reading that shows the login full, or no usable reading, adds nothing: the unknown probe alone keeps overflow out.

A login's standing shows in the cycle line:

2026-11-22T00:02:05Z cycle live=work work:s=100%,w=71% login-al:unknown, HTTP 429 login-ar:unknown, HTTP 429 login-bf:failed

login-al is unknown and has a last good reading, so it can be a target. login-ar is unknown with no usable reading, so it is not. login-bf's token has expired, so it is failed. The probe's own error is in the line, beside the login it was for.

Model-week storage upgrade limitation

Per-model observations add a nonempty week_models field to account readings in .auto-switch.d/usage.json. Older binaries use deny_unknown_fields and reject this file. Their usage loader substitutes empty readings on that error; their next status-line observation, direct usage observation or limit-failure write can overwrite the file and erase readings for every account. This differs from a strict rotate-ledger error that stops rotation without writing.

Before recording model weeks, stop older writers, upgrade every binary sharing the profile root (including status-line hooks and supervised launches), and restart long-running rotators. Back up usage.json before a downgrade and keep older writers off the upgraded root; preserved model observations cannot be relied on during mixed-version operation. Tolerant readers that preserve additive data through subsequent writes are tracked in #3319. This release does not repair readers in already released binaries.

Rotate confirmation

Every proposed usage-based swap confirms its selected target through the configured probe method, with passive readings disabled, unless its measurement already failed this cycle or confirmation is unavailable. A fresh direct or passive measurement still gets one confirmation. There is at most one direct target confirmation probe per decision; rejecting a target does not start another candidate's probe.

Result of the confirmation Outcome
Fresh usable figures, no model week at or above --week-at, and the same target still qualifies The swap goes ahead.
A model week is at or above --week-at, including equality Reject the target and reconsider selection using the updated readings.
Session or all-models limits make the target ineligible, or its standing block prevents a move Reject the target under the existing eligibility rules and reconsider selection.
Failed or unknown confirmation, with a standing block on the live login and a recent usable target reading, with at least one per-model week of the target's current week known and none at or above --week-at Accept the target on that recent reading under issue #2820's recovery rule. With no current per-model week known, the target is unknown and rejected.
Superseded or still-stale confirmation Reject the target.
Selection proposes another target after the confirmation Stay unless the blocked-login recovery rule permits accepting the alternative on its recent reading.

Issue #2820 retains the owner's rule: "when the live login is spend-blocked, staying on it is never better than moving to any measured login". It applies to a standing recorded spend, session, week, credit or API-key block, never merely a full measured login. The target must remain eligible, its reading must be at most five hours old and strictly after its last departure or damping, at least one per-model week of its current week must be known from its stored reading or its probe, and no stored model week may reach --week-at. A reading with no per-model week, such as one stored before model weeks were recorded, leaves the target unknown (issue #3347). A labelled measurement failure can use its last good reading without a retry. A labelled confirming-read failure can use the reading selected before that read. A target's own block, an old reading or a superseded confirming read never qualifies.

The existing time budget can also leave a recent target unread. After the one confirmation probe is used, the next eligible recent target may be accepted under the same recovery rule, without a second probe. Locked revalidation reuses that acceptance only while the live login is still blocked and the target's stored model weeks are known and remain below --week-at.

The swap line reports unconfirmed (HTTP 429), the corresponding probe label, unconfirmed (confirmation limit 1) or unconfirmed (time limit), followed by the live login's recorded block. The existing rejection-count guard can report unconfirmed (re-read limit 3). An unconfirmed swap establishes no capacity for waiting sessions until a later cycle reads room on the new live login. Waiting sessions use the existing capacity rule.

The model threshold is inclusive and uses the observed percentage, without rounding. Existing session eligibility, candidate limits and the all-models --target-week-max rule remain unchanged. The deciding weekly percentage is still the maximum of the all-models week and available model weeks.

Block reject lines

A standing block (see Eligible logins) rules a plan login out in every cycle and every decision in it. In a cycle whose decision looks for a target (it names one, confirms one, or ends on a no-target or no-candidate-confirmed line), the rotator writes one line per blocked plan login, after the cycle line:

2026-11-26T06:18:21Z reject: held blocked until 2026-11-26T10:40Z (spend limit)

<kind> is the fixed label of the block's kind (spend limit, session limit, week limit, credit limit, or a recorded limit for any other), taken from the block's kind when it has one and from its reason otherwise, and the line holds no probe or response text. These lines make no read and do not use the single target confirmation probe. A block whose until has passed no longer applies. A cycle that stays because the live login is fine writes no block line.

The reasons in a reject: line are fixed text:

Reason Meaning
model week at or above <n>% on a fresh reading A directly observed model week is at or above --week-at.
no room on a fresh reading A window is at 100%.
week above ceiling <n>% on a fresh reading The week is above --target-week-max.
spend limit on a fresh reading The reading is a spend limit.
no usable reading The reading has no figures, or a figure that is NaN, infinite or negative.
reading unknown (<label>) The confirmation was unknown, with its probe label.
reading <n>s older than one already held The re-read is dated <n> seconds before the newest reading the rotator holds for the login.
blocked until <utc_minute> (<kind>) The login has a standing block; see Block reject lines.

The target confirmation uses the existing probe deadline. Rejected targets are reconsidered on the updated readings, but an alternative is not probed or swapped to in the same decision. See Re-reads.

Rotate no target

A cycle with no move writes a stay note, or an ALERT in one of two wordings. Neither ends the rotator or a cycle with an error: the next cycle decides again on its own measurements.

A stay note. When the live login still has room or its probe read nothing usable, and eligible logins exist but none qualifies, the only qualifying ones are held, or none was confirmed, the cycle is a stay with capacity and writes a note, not an ALERT:

Note Case
stay: live room <R>, best other login has room <M>, a move needs <N> No eligible login has N = R + max(--margin, 1) or more room. <M> is the most room of a login the rotator may move to: while the live login has room, a login in another organisation is not one. When only such logins have room, the note reads only a login in another organisation has room in place of best other login has room <M>. When the live probe read nothing usable, <R> is unknown and <N> is --margin.
stay: held after last swap (<S>s of <H>s): <name> is at s=<n>%, at or above --session-at The hold applies.
stay: no candidate confirmed by a fresh reading Every qualifying login was rejected at confirmation, and a rejected login is still eligible because its re-read was unknown. When every rejection showed no room, no login is eligible and the no-target line below is written instead.

The note is written once per key, under the keys listed below. It follows the same rule as an ALERT: when the live reading qualifies it is advisory, so the cycle records stayed and a waiting step reruns, and when it does not (a stale, carried or failed live reading, for example) the key is stored in alert like a hard ALERT and the cycle records the outcome that the stay rules give. --dry-run prints it as would stay (<note without "stay: ">).

The no-target line. When no login is eligible, and the live login is past a threshold or has no room, the cycle writes one ALERT with kind no-capacity:

ALERT: no profile has capacity live=<name> s=<n>% w=<n>% (candidates: <counts>)
ALERT: no capacity known live=<name> s=<n>% w=<n>% (candidates: <counts>)

The first wording says that every other plan login is known, by a fresh or last good reading, to have a window at 100%, a spend limit or an active block; a spend limit is counted as exhausted. The second is used in every other case: when any login is unknown, not read, failed, above the ceiling or not tried, the rotator has not seen that no login has room. <counts> lists these parts in this order, leaving out any that is zero:

  1. <N> unknown (<label>), one part for each label in the order HTTP 429, transport, identity unavailable, timeout, still running, probe error;
  2. <N> not read (<reason>), one part for each reason a plan login was skipped before any probe, in the wording of the cycle's own skip: line: directory refused, session running, leased, hosting or parked. The room of such a login was never read, so the stronger wording is never written while one exists;
  3. <N> failed, which includes a login whose reading holds a figure that is not a finite number of zero or more (NaN, infinite or negative): it has no usable reading;
  4. <N> blocked until <time>, the earliest block end, UTC to the minute;
  5. <N> exhausted;
  6. <N> above week ceiling <n>%;
  7. <N> not tried (re-read limit 3), the candidates that the cap of three re-reads left unread. A candidate that the shared re-read time limit left unread is counted in the first part, as unknown (timeout).

With nothing to count, <counts> is none. The line holds no profile names, and its ALERT key is no-capacity for the first wording and no-capacity/known for the second, so a change of wording writes a new line and a change in the counts does not. The stay notes use the keys no-capacity/stay, no-capacity/held and no-capacity/unconfirmed. --dry-run prints the line as would alert: ... without the ALERT: prefix.

For example, with --session-at 85 on 22 Nov, when 429 answers hid six logins and three more had expired, and no login had a usable last good reading:

2026-11-22T00:02:05Z ALERT: no capacity known live=rrowan s=100% w=71% (candidates: 6 unknown (HTTP 429), 3 failed)

When every other login is known to be full or blocked, the first wording is used:

2026-11-26T08:00:05Z ALERT: no profile has capacity live=rrowan s=100% w=71% (candidates: 2 blocked until 2026-11-27T00:00Z, 5 exhausted)

Unreadable process lines

The first cycle that sees an unreadable process of yours that mentions claude or amplihack, or that is a Claude or amplihack executable, writes one line for it:

2026-11-23T11:00:00Z unreadable process 41207 (tailscaled) "tailscaled be-child ssh --remote-ip=192.0.2.10 amplihack recipe run wait": not counted (not a Claude executable)

The line gives the pid, the executable (the basename of argv[0], or the name in status when argv is empty or argv[0] is NAME=value, cut to 32 characters), and the command line cut to 120 characters, then one verdict:

Verdict Meaning
counted as a session on <a>, <b> A Claude or amplihack executable is tied to these profiles, by its arguments or by Claude Code's session file for it. They count as live.
not counted (not a Claude executable) The command line mentions claude or amplihack, but the executable is something else. No profile is live because of it.
not counted (profile cannot be told) A Claude or amplihack executable is tied to no profile. No profile is live because of it, so the login it uses is not protected; see Leases.

Arguments are joined with a space; NUL is only the separator between them. " and \ are escaped with a backslash, any other ASCII control character (0x01 to 0x1F, including an embedded one, and 0x7F) is shown as \xNN, and a Unicode control character (U+0080 to U+009F) as \u{NN}. The executable and the profile names in the verdict are escaped the same way. A trailing ... marks a command line or executable that was cut.

Each argument is masked before it is escaped and cut. The first rule that fits applies. A secret word is token, secret, passw, passphrase, key, auth, cred, cookie or bearer, found anywhere in a name and in any case.

Argument Shown as
The argument after a flag written without = whose name holds a secret word (--token abc, --api-key sk-...), whatever it is <hidden>
An environment assignment, NAME=value NAME=<hidden>
--flag=value, where the flag's name holds a secret word --flag=<hidden>
--flag=NAME=value --flag=NAME=<hidden>
An argument, or the value of any other --flag=value, that starts with a known token prefix: sk-, ghp_, gho_, ghu_, ghs_, ghr_, github_pat_, glpat-, xoxa-, xoxb-, xoxp-, xoxr-, xoxs-, AKIA, ASIA, AIza, eyJ, npm_ or hf_ <hidden>
An argument or flag value Name: value, where Name is one word holding a secret word (Authorization: Bearer ..., --header=X-Api-Key: ...) Name: <hidden>
A URL with a user or password, anywhere in an argument or flag value (https://bob:pw@host/r) https://<hidden>@host/r
Anything else as it is

Masking hides what is shaped like a secret, not every secret. A secret passed as a bare argument, with no secret-named flag before it and no known prefix, is still shown within the 120 characters. So is a token inside other text. Any process of yours can already read it in /proc/<pid>/cmdline, and so can other users unless /proc is mounted with hidepid. The log is created with mode 0600, and the rotator refuses to write a log that other users can read or write. The process environment is never read or logged.

A process is logged again only when it was not in the previous cycle's set, so a long-lived one is named once. A restart of the rotator names it again. At most 32 process lines are written per cycle, followed by unreadable processes: <N> more not listed when there are more. The cap limits the log only; every process is still judged. Revalidation inside a cycle does not log these lines.

Rotate failed live probes

When the table above gives a threshold swap only because the live probe failed, the rotator applies these rules in order. An excluded live profile is not probed, so its swap is not a failed-probe swap and none of these rules applies to it. k is the number of consecutive cycles, including this one, whose live probe failed.

Condition Outcome Log line
The live login has a standing recorded block in the ledger None of these rules applies, including the home-key stay below: a failed live probe is read as the recorded block, which is evidence of no room, so it does not hold the move off. A target that could not be read fresh is taken unconfirmed on its recent reading. as the swap line
k < 3 Stay. stay: live probe failed (<k>/3)
k >= 3, the post-swap hold applies, and the rotator has no evidence of high use Stay. stay: live probe failed; held after last swap (<N>s left), where N = hold - (now - swapped_at), or hold if swapped_at is in the future
The API-key login check passes on the $HOME files and the API key is not live Stay. stay: live probe failed; home key (<detail>) applies to every login once live, a swap changes nothing; see API-key login check
Otherwise Swap to the first-ranked qualifying candidate after a fresh confirmation, per Rotate target choice. swap <from>-><to> live failed target s=<n>% w=<n>% reason=failed-probe, with the usage evidence appended when the swap occurs during the hold

Use counts as high if either figure from the last accepted post-swap reading meets its threshold (--session-at or --week-at) while its own window is still open. A weekly figure with no known reset time can count for less than five hours from the reading. An open high-water reading also counts if it meets its threshold and no newer window supersedes it. A rise between two accepted post-swap session observations at least --interval seconds apart in the same window also counts if it projects --session-at before the hold ends and before any known session reset. The projection starts at the last observation's original time, including when later cycles reuse that reading. The swap line gives the figures and thresholds used.

k is kept in memory by watch. It is reset to 0 by a cycle whose live probe does not fail, by a completed swap, and by restarting the rotator. The one-shot rotate always uses k = 1, so it never swaps on a failed live probe alone. With --hold 0, the post-swap hold is disabled and the three-failure count still applies.

Nothing else changes: an ALERT when no candidate meets the margin, swaps on a measured threshold, swaps on an exhausted live login and upgrade swaps behave as in the table above.

The near-threshold rule also changes the timing of these rules. When the live login was near --session-at on a last known reading whose session window can still be open, and the swap target has at least --margin more headroom than the larger of --session-at and that last known session use, and is not in another organisation, the failed-probe swap is made on the first failure, with reason=projected: neither the count nor --hold delays it, as for any projected swap. The home-key rule still applies, so with a key in the $HOME files the early swap is a stay, as the failed-probe swap would be. Otherwise these rules apply unchanged: the exception never changes the target and never turns the failed-probe swap into an ALERT. See Failed or stale reading near the threshold.

A damped stay is recorded as stayed-unread, not stayed: the cycle did not read the live login, so it cannot say that login has room. A stayed-unread cycle is not capacity by the rotator capacity rule, and it leaves the stored ALERT key and the ledger's alert as they were. A no-capacity ALERT written before the probe failed therefore stays in place, and a recipe step in the usage-limit wait keeps waiting. The next cycle whose live probe succeeds with the live login below 100% on both windows records stayed again and clears the key; see Stays and capacity.

Rotate stays and capacity

A cycle that stays on the live login records one of two outcomes. Which one depends only on the reading of the live login taken in this cycle.

The live reading qualifies when all of these hold:

  • the probe succeeded in this cycle with measured figures: it is not failed, not unknown, still running, not a result collected from a read started in an earlier cycle, and not unknown;
  • it is not a spend limit, and the live login has no active spend block: no unexpired entry for it in the ledger's overflow_blocked, and none added in this cycle;
  • session_used is below 100 and week_used is below 100, as numbers (a value of exactly 100.0, or one that is not a number, does not qualify).

The reading freshness gate does not apply here, as it does not apply to any stay or ALERT. A passive reading of the live login that is measured and below 100 on both windows qualifies, but its age still matters. A stayed cycle records, as last_cycle.measured_at, the time the live reading was taken: its observed_at for a passive reading, otherwise the time the cycle started measuring, whichever is earlier. The usage-limit wait counts only a measured_at strictly later than the limit hit, so a passive reading taken before the limit never reruns a step that the limit stopped; the next reading taken after the limit does. A stay never resumes a session through the limit-resume hook, which acts only on a swap record.

A live login with an active spend block cannot spend, whatever its plan windows read. A stay on it records stayed-unread, and its no-capacity ALERT is never advisory: the key is stored in alert and the hook does not resume.

A live login on the platform tier has no usage windows. Its reading counts as qualifying for a stay, so a platform stay records stayed as before, but it never makes an ALERT advisory: platform-blocked always blocks.

A stay on an overflow profile (overflow=on) runs on credits, so its plan windows may read 100. When its probe read the login in this cycle, the stay records stayed, whatever the figures, and the hook resumes as before. Like a platform stay, it never makes an ALERT advisory. A failed, carried, unknown or spend-limited probe of the overflow profile, or a stay on one with an active spend block, records stayed-unread.

Live reading Stay outcome Capacity ALERT key
Qualifies stayed yes alert and advisory_alert cleared
Read in this cycle on an overflow profile (overflow=on) with no active spend block, at any figures stayed yes alert and advisory_alert cleared
Qualifies, but a passive reading taken before the limit hit stayed, recorded at the reading's time not for that limit alert and advisory_alert cleared
Failed, carried, unknown, still running, spend-limited, or at 100% on either window (and not a read overflow stay) stayed-unread no unchanged
Live login with an active spend block, at any figures stayed-unread no unchanged

Every stay that does not read the live login records stayed-unread: a damped stay after a failed live probe, a stay because the home key applies to every login, a stay on an overflow profile whose live probe failed, and a stay on a carried result.

A threshold reached on a candidate never changes this. Which candidate is best, whether any candidate has room, and whether the cycle writes a stay note, does not decide whether a stay is capacity; only the live reading does.

Rotate advisory alert

When no candidate is eligible, the decision rule gives the no-capacity ALERT, and when eligible candidates exist but none qualifies, it gives a stay note. If the live login's reading qualifies at the same time (below 100% on both windows, with no active spend block), the login in ~/.claude can still be used, so the ALERT or note is advisory:

  • the ALERT: no profile has capacity ... or ALERT: no capacity known ... line, or the stay: ... note, is written to the log once per key, exactly as for any ALERT;
  • the key is stored in the ledger's advisory_alert field, and alert is set to null;
  • the cycle records stayed, which is capacity by the rotator capacity rule, so a recipe step in a reset or capacity wait reruns. A step in a login-change wait does not: it is waiting for the login to change, and a stay is the rotator reporting that it did not. It is a stay, so it writes no swap record and the limit-resume hook does not act on it.

For example, with --session-at 90 and three logins, where both candidates are known to be exhausted:

2026-11-03T10:02:05Z ALERT: no profile has capacity live=work s=92% w=60% (candidates: 2 exhausted)

The ledger after this cycle and the next, which writes no second ALERT line:

{
  "version": 1,
  "live": "work",
  "account": "<accountUuid>",
  "since": 1793696405,
  "advisory_alert": "no-capacity:work",
  "last_cycle": { "at": 1793701445, "measured_at": 1793701325, "outcome": "stayed" }
}

Every other ALERT is hard: alert is set, advisory_alert is cleared, and the cycle records alerted, which is not capacity. That covers no-capacity when the live reading does not qualify (live at 100%, a spend limit, or a failed probe), platform-blocked, key-held, the swap-refused ALERTs and every ALERT written before measuring, such as no-login and hand-change.

alert and advisory_alert are never both set; a hand-edited ledger that sets both is refused as RotateInconsistent. The two share one de-duplication key: when the same key moves from advisory to hard, or back, no second ALERT line is written, but last_cycle.outcome changes. Every step that clears the ALERT key (a completed swap, a stay recorded as stayed, a held cycle, hand-change recovery) clears both fields.

The one-shot amplihack profile rotate exits 0 after an advisory ALERT, as after a hard one; only the ledger differs. --dry-run writes no ledger and prints would alert: in both cases.

Rotate reading freshness and swap-back damping

A candidate's figures can be several minutes old: a passive reading of up to 300 seconds, or the result of a read that outlasted an earlier cycle. Near a limit, such a reading can show room the login no longer has, and the rotator would swap to a login that is already full and then swap away again on the next cycle. Before a swap stands, the rotator therefore checks that the target's reading is fresh, and reads the target again when it is not, the way AMPLIHACK_PROFILE_USAGE_PROBE says.

The gate applies to swaps with reason=threshold, projected, upgrade, failed-probe, plan-room and overflow-out, in the one-shot rotate, in rotate watch and in --dry-run. It does not apply to overflow-in, whose target is chosen by tier, not by a reading, or to a stay or an ALERT. It checks only the target the decision chose, after failed-probe damping and the home-key check, not every candidate.

Reading time
Reading Reading time
Passive Its observed_at.
A direct or claude read started and finished in this cycle Its evidence timestamp when supplied; otherwise when this cycle started measuring (last_cycle.measured_at).
A target re-read by the gate Its evidence timestamp when supplied; otherwise when the re-read finished.
A live re-read Its evidence timestamp when supplied; otherwise the cycle clock taken after the re-read.
A result collected from a read started in an earlier cycle None.
unknown, still running or failed None.

A re-read preserves a supplied observed_at, including an older timestamp. Completion or collection alone cannot turn old evidence into a new observation. Only a re-read without an evidence timestamp receives the fallback time in the table. Target and live re-reads retain supplied timestamps.

A live re-read finishes after the clock the cycle started with, so a live re-read is not discarded for being dated after that clock. It is discarded when it is dated after the clock taken once the read has finished, or more than one --interval before the cycle clock. When the live re-read fails or is discarded, the held reading does not stand in for the cached figures, and the cycle ends in one of three ways:

  1. A live login that has an active spend or limit block in the ledger and is not an overflow profile keeps the cycle's decision, which already counted that block as no room: the cycle swaps to a usable target, or raises the no-capacity ALERT when there is none.
  2. Otherwise the rotator looks for evidence of high use in the readings it already has, as for a failed live probe during the post-swap hold. It considers the last reading the live step accepted after the last swap, a high-water peak that still applies (peaks are recorded from readings that give a reset time, cached readings included), and a rise between accepted session readings after the last swap that projects --session-at before the cycle clock. With no swap recorded, every accepted reading counts. With evidence, the cycle is decided as for a live login at the threshold the evidence is for: a session level or projection puts the session figure at no less than --session-at, and a week level puts the week figure at that level. A swap line then ends with the evidence, as the failed-probe swap line does. When no login qualifies, the outcome is the stay note or the no-capacity ALERT.
  3. With no evidence, an overflow live login, or a decision on the evidence that is a stay (only a login in another organisation has capacity), the rotator writes reread: <name> live re-read failed; live login kept, decides no swap in that cycle, and reads the live login again in the next cycle.

Neither of the first two writes the live login kept line. The replacement evidence must then pass the applicable target or live freshness checks. A failed, unknown, still-running or carried result has no usable reading time.

A target's reading is fresh when all of these hold:

  • it has a reading time;
  • the reading time is no more than 300 seconds before now;
  • the reading time is not earlier than the live login's reading time. Equal times count as fresh. A live reading time later than when this cycle started measuring (last_cycle.measured_at) counts as that start time. This covers a live re-read, which runs after the measurement and is dated then, and a passive live reading observed during the measurement. So a target read directly in the same measurement is never older than the live login, however long the measurement took. The required target confirmation still runs after selection. A reading before the measurement started is still older than a live reading taken after it. When the live probe failed, the live login has no reading time, so this comparison is omitted; the other checks still apply;
  • when the target is the ledger's previous login, the reading time is strictly later than swapped_at, whether or not that login was exhausted;
  • when the target has a retained swapped_away entry, the reading time is strictly later than that entry. This applies even when the target is no longer previous.

Otherwise the reading is stale.

When both recorded swap times apply, the later one is used. A reading from the current cycle still has to pass these checks; collecting an older cached result in this cycle does not give it a new reading time. These checks use the existing ledger and its retained damping entries, not a complete history of every login's use.

Freshness and eligibility are separate checks. A fresh exhausted reading cannot authorize a swap to that plan login. A fresh reading showing room remains subject to the existing margin, hold, plan-room and overflow rules; freshness adds no new exhaustion threshold or candidate ordering.

The 300-second limit is fixed; there is no flag or environment variable for it. It equals the default of AMPLIHACK_PROFILE_USAGE_PASSIVE_MAX_AGE_SECS and half the default --interval of 600 seconds, so a passive reading accepted under the default setting is never too old on age alone. Raising the passive setting above 300 lets older passive readings rank candidates, but a target chosen on one is still read again.

Every proposed swap confirms its selected target directly, regardless of whether measurement used a direct or passive reading. A changed selection waits for a subsequent cycle. See Re-reads.

Re-reads

The selected swap target is read directly the way AMPLIHACK_PROFILE_USAGE_PROBE says, as the cycle's own measurement reads it, except that passive readings are not used, even when the stored reading is fresh.

AMPLIHACK_PROFILE_USAGE_PROBE Re-read
unset A direct read; when it fails, the claude fallback, with /usage text when the direct read failed with usage credits on.
direct A direct read only. A failed one makes the target unknown.
auto, text The claude fallback only, as named. No direct read is made, as the mode promises.

A profile marked as overflow is read with /usage in every mode but direct, as in the measurement. So setting text because direct reads fail or are unwanted keeps them off for re-reads too, and a login whose direct read fails because usage credits are on is still read by /usage under the default order rather than made unknown.

The target confirmation uses the existing probe deadline. It takes no rotate lock; a direct request may take the existing token-refresh lock outside a dry run. Its figures replace the previous ones for the rest of the cycle, and selection runs again. Only the same successfully confirmed target may be swapped to. A changed choice waits for the next cycle.

There is one target confirmation per decision. A failed or still-stale result becomes unknown rather than exhausted; it cannot authorise a swap. The optional live re-read runs before target confirmation and retains its separate existing probe deadline. No new schedule or retry is introduced. A stop received before confirmation makes no further read and no swap.

Older versions could swap off a blocked live login without confirming the target. Their swap lines could include unconfirmed (time limit), read <N>m ago and ; live <from> has no room: <kind> until <UTC minute>. These suffixes describe the older behaviour. A failed confirmation now leaves the live login unchanged for that cycle.

--dry-run makes the same re-reads, since they write no rotate state, and prints their reread: lines and any damp: <name> swapped away exhausted; no later reading shows room line. It never prints damp: <name> later reading shows room; swap-back allowed, because that line is written when the ledger is updated, and it never changes swapped_away or any other part of the ledger. Dry runs use direct reads only, never refresh tokens and never start claude. Outside a dry run, a stored target's direct re-read may refresh its token under the existing token-refresh rules. A live usage re-read never refreshes a token. Usage revalidation under the lock never measures usage. A stale target there counts as unknown. The unchanged-state check applies the target-change gate to every usage-based swap, using the current clock and ledger. Any replacement target must pass the same freshness, identity and eligibility checks without an external usage re-read under the lock.

For example, live work reaches 100% session use and the rotator swaps from work to spare, which reads 90%. On a later cycle the stored reading for work is s=0%,w=0%, taken before the swap. That reading cannot authorize a swap back to work: it is not strictly later than swapped_at, so the gate reads work again first. If the re-read reports exhaustion, work is not eligible. If it fails or is still stale, work is unknown for this cycle, and is not chosen while spare still has room. Only a reading taken after the swap away can make work a target again, under the existing decision rules. A different target waits for a subsequent cycle to be confirmed.

For example, live rrowan is past --week-at, and login-ag has a stored reading from before it was last live:

2026-11-02T13:09:09Z cycle live=rrowan rrowan:s=0%,w=97% login-ag:s=11%,w=85% login-ah:unknown, still running
2026-11-02T13:09:10Z reread: login-ag reading stale s=11% w=85%; fresh s=43% w=100%
2026-11-02T13:09:10Z reject: login-ag no room on a fresh reading
2026-11-02T13:09:10Z ALERT: no capacity known live=rrowan s=0% w=97% (candidates: 1 unknown (still running), 1 exhausted)

On the stored reading login-ag has room 15 against the live login's 3, so it qualifies. Without the gate this cycle would swap to login-ag, read it at w=100% on the next cycle, and swap away again. The fresh reading rejects login-ag for no room, so it is no longer eligible, and login-ah has no last good reading. No login is eligible, so the cycle writes the no-target line and not the no candidate confirmed stay note, which is for a rejected login that is still eligible.

Swap-back damping

After a swap completes, the rotator records the login it left in the ledger's swapped_away map, with the swap time in epoch seconds, when that login's reading at decision time was exhausted, or showed session use at or above --session-at or week use at or above --week-at. This applies whatever the swap's reason. Nothing is recorded when the live probe failed, in --dry-run, or when the swap was refused or skipped.

A login in swapped_away is damped: its reading counts as stale unless it was taken strictly after the recorded time, so the gate reads it again before any swap back to it.

  • When a reading taken after the recorded time shows room (not exhausted, and below both --session-at and --week-at), the entry is removed with damp: <name> later reading shows room; swap-back allowed. That reading may come from a re-read or from an ordinary probe in a later cycle, of the login as a candidate or as the live login.
  • When the re-read shows no room, the entry stays, the log says damp: <name> swapped away exhausted; no later reading shows room, and the login is not chosen on its new figures.

A reading does not lift damping when it is below the login's highest reading for the same window. A login left at 91% of its session and then reported at 70% in the same window keeps its entry, because use does not fall within one window and the lower figure is stale. The same applies to the week figure. A reading taken at or before the swap away does not lift damping either. A reading taken before the start of the previous cycle's measurement is rejected earlier, by the freshness gate, and never reaches the damping check.

A damped login remains a plan login: it counts towards the plan pool and the rules that keep the rotator off overflow as before.

For example, in a separate case where login-ag and login-ah are the only plan logins and the rotator runs with --hold 0, the rotator leaves login-ag past --session-at. Sessions started while login-ag was live keep using its login, so its use goes on rising:

2026-11-02T15:40:10Z swap login-ag->login-ah live s=86% w=70% target s=70% w=62% reason=threshold

On the next cycle, login-ag's stored reading is the one taken at 15:40:09, before the swap, and on those figures it has room 14 against the live login's 8, so it qualifies by --margin. That reading is not later than the swapped_away entry, so it is read again:

2026-11-02T15:42:21Z cycle live=login-ah login-ah:s=92%,w=63% login-ag:s=86%,w=70%
2026-11-02T15:42:22Z reread: login-ag reading stale s=86% w=70%; fresh s=93% w=71%
2026-11-02T15:42:22Z damp: login-ag swapped away exhausted; no later reading shows room
2026-11-02T15:42:22Z stay: live room 8, best other login has room 7, a move needs 13

With the default --hold, the hold would have kept the rotator on login-ah before the gate was reached, because login-ag's session is at or above --session-at.

The ledger then holds:

"swapped_away": { "login-ag": 1793634010 }

The entry is kept between one-shot runs and across restarts. It holds only profile names and whole epoch seconds, never an e-mail address, account ID or token. An entry is removed when it is lifted, or when it is more than 7 days old, the length of the weekly window. The map holds at most 16 entries; when a new one would exceed that, the oldest is dropped. On load, an entry whose name fails the name rules, or whose time is not above 0 or is more than 300 seconds in the future, is dropped, and the rest of the ledger is used. A bad entry is dropped rather than reported as RotateInconsistent so that it cannot stop rotation.

Highest reading in a window

The ledger keeps, for each login, the highest session figure and the highest week figure the rotator has seen, each with the reset time of its window, in the optional high_water field:

"high_water": { "work": { "session": { "used": 91.0, "resets_at": 1793642400 } } }

A reading is below the stored figure when it is lower than it, is in the same window (the same reset time, within the tolerance used for the live series) and the reset has not passed. Such a reading does not rank the login as having room and does not lift damping. The decision uses the highest figure for a measured login, in place of the lower reading, for the live login and for each candidate; the cycle line still shows the reading as read. A login whose reading is exhausted or failed is left as it was read.

The raw readings are not changed. They stay in the probe results the cycle holds, in the usage history and in the capacity file; only the figures used to decide are raised.

  • A reading with a later reset time replaces the stored figure.
  • Once the stored reset time has passed, the entry is dropped and any reading is accepted.
  • A reading with no reset time cannot be placed in a window. It does not raise the stored figure. While the stored figure is live, that is, its reset time has not passed, the reading counts as below it: it cannot lift damping or rank the login as having room, whatever the stored figure is.

profile usage shows each session and week figure at no less than the stored figure for the current window. It reads the ledger and never writes it. The stale field in JSON output and in --summary-json's profiles rows is true when a measured reading, before its figures are raised, is below the stored session or week figure for the same window. The week comparison uses the highest percentage among the all-models week and the individual model windows. For example, a measured reading with a 76% all-models week and every model window below 97% shows 97% in week_all and true in stale when the stored week figure for that window is 97%. A session-exhausted row with those week figures has stale: false. Every exhausted or failed row has stale: false, even when one of its windows is below the stored figure. When the rotate ledger is missing or cannot be read, every row has stale: false and shows its figures as read.

Recording a stale reading, from profile usage or from the rotator, leaves the stored model windows and their observation times unchanged. The same rule applies to the rotator's Claude fallback after an HTTP 429 response from the usage endpoint. The session and all-models week figures of a stale reading are recorded as read, because the display and the rotator apply the stored figures to them separately. Model windows merge by observation time, so a model window from a stale reading would replace a newer one. When the rotate ledger cannot be read, a warning is printed on stderr, the stored model windows stay unchanged, and usable session and all-models week figures are recorded. In both cases, a reading with no usable session or all-models week window is not recorded, and the stored observation time does not change. When there is no rotate ledger, no reading is stale and model windows are recorded as read.

The field holds profile names, percentages and whole epoch seconds, never an e-mail address, account ID or token. The map holds at most 16 entries, the ones with the latest reset times dropped first. On load, an entry that does not parse, whose name fails the name rules, or which holds no figure is dropped, as is a figure that is not a number from 0 to 100 or whose reset time has passed or is more than 8 days ahead. The rest of the ledger is used. When anything is dropped, one warning gives the number dropped for each reason, without names or figures. Older binaries do not read the field: it is left out when the ledger is written for them.

Rotate live reading freshness

The freshness gate checks the swap target. This step checks the live login. A live reading can stop moving while sessions go on using the login: a passive figure that is no longer refreshed, or a reading from several minutes before. A live login that rises by about 10 points a cycle can also go from below --session-at to its limit between two cycles, so a rule that waits for the threshold swaps too late.

The step runs once per cycle, after the measurement and before both the cycle line and the decision, so the cycle line reports the live figures the cycle decided on (see Freshest live reading). It applies only when the live login is a known profile and is not the platform tier. An excluded live login, one in the auto-switch exclude list, is never re-read: the step checks the same exclude rule as every other reader before it reads anything, and the cycle moves off that login as described under Rotate excluded live profile. It writes nothing to the ledger, the capacity file or the usage history, and it holds no lock.

Live reading series

rotate watch keeps, in memory, a short series of the live login's readings: up to 4 points, each a reading time, a session figure and the session window's reset time (none when the reading gave no reset time). A point is added only when its reading time is later than the last point's and not later than now. Accepted evidence is kept separately from the measured cache figures used to count frozen cycles:

  • the frozen count is kept on the measured figures only, never a re-read's. It rises by one on each cycle in which a cached (passive) reading equals the previous cycle's figures, and restarts from 0 on a direct reading, which was read from the usage source in that cycle;
  • while a live re-read has established that the cache is behind, the series takes only the re-read figures. A cached figure below the last point is neither added to the series nor treated as a new session window.

Session use only rises within one session window, so the rotator tells a new window from a stale figure by the session reset time, never by the observation time. The status line rewrites old figures with new observation times, and many sessions write the same cache, so a lower figure with a newer time is expected and proves nothing. Two reset times at most one hour apart are the same window: a direct read prints the reset to the minute or the hour, and the status line stores it to the second. The next window starts no earlier than the current one resets and lasts five hours, so its reset is hours later.

The new reading's session reset A lower session figure A higher or equal one
More than one hour later (a new window) Clears the series, then is added Clears the series, then is added
Within one hour (the same window) Stale: not added; the series is kept Added
More than one hour earlier (an ended window) Stale: not added Stale: not added
Unknown on either side A cached figure is read again first; a direct read clears the series, then is added Added

The series is cleared when:

  • an accepted reading is from a later session window by its reset time, or, with no reset time to compare, a direct read gives a lower session figure (a new session window). A cached figure cannot establish that reset by its observation time;
  • a different login becomes live, or a swap completes;
  • the live login cannot be identified.

The series is not read from or written to disk. Restarting the rotator starts it empty.

Stale live reading

The live reading is stale when any of these holds:

  • Frozen. It is a cached (passive) reading, its session and week figures are the same as on the previous two cycles for the same live login, with no swap and no direct reading in between, and its session figure is above 0. The third identical cached reading in a row is stale. A session figure of 0 is never frozen, because a login with no use in its window reads 0 truthfully. A direct reading is never frozen: when the status line is not being written, the cache ages out and each cycle reads the login directly, and identical direct figures mean an idle login. A second direct read seconds later could only return the same figures, or fail and discard the reading just taken, so it is not made, and a direct reading is never substituted (see Failed or stale reading near the threshold).
  • Old. Its reading time is more than one --interval before now.
  • Lagging cache. A live re-read has established that the cache is behind, and the cached observation is older than the accepted direct evidence, or its figure has not caught up with that evidence in the same session window. Changing cached percentages, a newer observation time or resetting the frozen count does not make that figure current.
  • Contradicted cache. A cached (passive) figure is lower than the last point in the same session window, or in a window whose reset time is unknown, or comes from an earlier window. Its observation time does not matter: use never falls within one window.

  • Below the highest reading. The reading is lower than the login's highest reading in the same window. The decision uses the highest figure in its place.

A reading of a target is also stale when it was taken before the start of the previous cycle's measurement or before the last swap. A reading taken during the current cycle's own measurement is never stale on this ground. A stale target reading is read again within the existing limits and cannot rank the login as having room until it is.

A stale live reading is read once more in the same way as a re-read of a target: by the probe method, passive readings off, within its own probe deadline, separate from the target gate's shared deadline. Under auto or text, this uses the configured claude fallback, without a direct read. The log gets:

2026-11-09T14:12:05Z stale live reading; re-read

The direct live re-read loads credentials from the supplied home's .claude directory, even when the named profile's stored credentials are different or absent. It never reads that stored copy as a substitute and never refreshes a token or changes credential bytes. The separate expired-live-login prelude retains its existing behavior. Target re-reads continue to use stored-profile credentials.

The decision is then made on the new figures, with the reading time given by the reading-time rules. The re-read is dated after the measurement, but it does not make the cycle's own target readings stale: the target gate treats a live reading time later than the start of the measurement as that start time. A re-read that confirms the measured figures restarts the frozen count from 0 and clears the lag. A disagreeing re-read marks the cache as behind and leaves the frozen count running, so the distinction between the cache baseline and accepted evidence is kept. A failed re-read, or one that could not be made, changes neither: a failure says nothing about the cache, so a frozen reading stays frozen and is read again on the next identical cycle, as a lagging one is.

Re-read result Frozen count Cache behind Series
Agrees with the cached figures Restarts from 0 Cleared Takes the re-read figure (equal to the cached one)
Disagrees Kept; rises on the next identical cycle Set Takes the re-read figure
Fails Kept; rises on the next identical cycle, which is read again Unchanged Unchanged (no point added)

The count saturates at its maximum value rather than wrapping, so a cache frozen for a very long run cannot return to a count below the frozen limit.

Once lag is established, a cached observation must have a usable reading time, no later than now and no more than one interval old, to clear it. Its time must be at least that of the latest accepted live evidence, and its session figure must have caught up to that evidence within the same session window. A lower session figure can instead establish a new session window only with a session reset time more than one hour later than the last point's. That reset clears the old series. A newer observation time alone is not a reset: a lower figure stamped later in the same window, or in a window whose reset time is unknown, keeps the lag and the series, and is read again. An older observation cannot clear lag, overwrite accepted evidence or establish a reset, even when its percentages change or equal the accepted figures.

For example, the cache reads 63%, 63%, 63%, 64%, 65%, each newly stamped, in the same window as direct re-reads of 66%, 69% and 72%. The third 63% is frozen and is read again at 66%. The 64% is lower than 66% in the same window, so it is read again at 69%, and the series keeps 63, 63, 66 and 69. Over those points the rate projects 71% one interval ahead, so that cycle swaps with reason=projected.

A cycle makes at most one live re-read, separately from the target gate's three-read limit. None is made once rotate stop has arrived, or when the reading is current and neither frozen, lagging nor contradicted. A reading time later than now counts as old.

When the re-read fails, or its reading is itself more than one interval old or later than now, the log gets reread: <name> failed; treated as unknown after the stale live reading line, and the rules in Failed or stale reading near the threshold apply.

Failure does not make a known lagging cache, or a frozen one, trustworthy again. The accepted history remains available for the near-threshold rule, and the next cycle retries while the cache remains behind or the reading stays frozen: at most one live re-read per cycle, each within its own probe deadline. A successful later re-read replaces the failed attempt with current evidence.

Under the recovery rule, a cache can remain at 63% while successive live re-reads return 65%, 68% and 71%. Each successful re-read supplies that cycle's live evidence while the login remains live. The cached 63% cannot replace 65% or 68%, including after a failed re-read; an older cache moving to 64% does not prove recovery either. Projection can trigger a swap before 71%; otherwise 71% reaches --session-at 70. A login change clears this series and lag tracking, so the new login inherits neither.

Cycle by cycle, with --session-at 70 and the cache frozen at 63%:

Cycle Cached session Frozen count Re-read Cache behind Decision input
1 63% 0 none no 63%
2 63% 1 none no 63%
3 63% 2 (frozen) 65% yes 65%
4 63% 3 68% yes 68%
5 63% 4 71% yes 71%: swap, reason=threshold

On cycles 3 to 5 the series never shortens, the decision never uses the cached 63%, and by cycle 4 the rate is positive. Each of those cycles writes one stale live reading; re-read line, three in all.

Projected swap

When the first and last points of the series are at least one --interval apart, the rotator works out the live login's session rate, in points per second, from those two points:

rate      = (last session - first session) / (last time - first time)
projected = session + rate * interval

Two points closer together give no rate. A direct read and a status line written a few seconds after it say little about the rate: one point over five seconds would project 24 points over a 120-second interval. Over at least one interval, rate * interval is never more than the rise the series has seen, so the projection adds no more than that.

interval is --interval. The projection is limited to the range 0 to 100. When projected >= --session-at and the live reading itself is below --session-at, the decision runs again on the projected session figure and the live week figure, under organisation affinity, and a threshold swap it gives is logged with reason=projected. It uses the same --margin as a threshold swap, passes the same freshness gate and revalidation, and is not stopped by --hold. When that decision finds nowhere to go, the cycle writes a stay note, or the no-target line when no login is eligible, so either can follow a live reading still below --session-at.

A projection below --session-at, a rate of 0 or less, fewer than two points, or points less than one interval apart leaves the decision as it would be without this step. Only session use is projected; week use is decided on the reading as before.

The projected figure can add only a threshold swap, a stay note or the ALERT. The swap is decided by the same target rule as a measured one, with the live login's room taken on the projected figures, so a target needs that much more room than the projection leaves. The overflow moves always run on the reading as measured, so a projection never moves work onto credits or onto the API key. Where no login qualifies on the projected figure, the cycle writes a stay note, or the no-target line when no login is eligible. When only a login in another organisation has capacity, the projection adds nothing (see Outlook and organisation affinity). When the measured reading is itself at --session-at or --week-at, or gives a swap on its own, the cycle is decided on it as measured, as without this step.

The projection affects only the decision. The ledger, the cycle line, the swap line's live s=<n>% w=<n>% figures and the usage history all show the reading the cycle decided on before the projection: the reading as measured, or the held reading that replaced a stale one.

Failed or stale reading near the threshold

This rule runs after the freshest reading has been chosen. A stale measured reading is usually replaced by the held reading first, which needs no near test, so what reaches this rule is mostly a failed probe, or a stale reading for which no held reading was available or the held one was lower. When a substitution did happen, the week figure here is the held reading's own.

A failed live re-read keeps the live login for the cycle, except in two cases. When the login has an active spend or limit block in the ledger and is not an overflow profile, the block is known to leave no room whatever the usage read says, so the cycle's decision, made with the block counted as no room, stands. When the readings the rotator already has show high use (see Reading time), the cycle is decided as for a live login at its threshold, and a swap line ends with the high-use evidence.

When the live probe fails, or the live re-read fails, is refused or is itself still more than one interval old, the rotator looks at the last point in the series for the same live login. That point counts only while the session window it was read in can still be open: before its session reset time when it has one, and less than five hours (one session window) after it was read in any case. After that its figure says nothing about the login's use now, and the rule does not apply. The limit is not the 300-second reading age: the default --interval is 600 seconds, so the previous cycle's point would always be too old. The login is near the threshold when either holds:

  • last session >= --session-at - --margin;
  • with a rate: last session + rate * interval >= --session-at.

A rate only widens the margin band; it never narrows it. When the reading is frozen, the series holds the frozen points: identical figures whose observation time keeps moving, as from a status line that keeps rewriting an old figure, give a rate of 0, or dilute an earlier rise. Such a rate says nothing about the login, so a last figure inside the band is near whatever the rate, and the outcome does not depend on whether the cache's timestamp moves.

When it is near, the substituted figure is the larger of --session-at and the last known session use: the last point, and the reading the cycle decided on when there is one. The week figure is the held reading's when one was substituted, and otherwise the last measured one. The substituted figure is never lower than the last known figure.

A stale reading (the re-read failed, was refused or is still old) is decided on the substituted figure. The outcome is a swap, logged with reason=projected, or, when no login qualifies, a stay note, or the no-capacity ALERT when no login is eligible. Where only a login in another organisation has capacity, it is a plain stay (see Outlook and organisation affinity). Without this rule the stale reading, below --session-at, would be a stay, so the rule can only make a swap more likely: a stay note and an ALERT are each a stay with a warning. As with a projection, the plan-room swap and the overflow moves never run on the substituted figure. When the stale reading is itself at --session-at or --week-at, the cycle is decided on it as measured, as without this rule, so a threshold swap on it is logged with reason=threshold.

A failed probe changes only the timing of a swap, never its target. The failed-probe rules count a failed probe as headroom 0, so the first-ranked candidate that organisation affinity permits, when it has --margin of room, is their target, and damping delays that swap for three failures. The rule then asks one thing of that same target: whether it has --margin more headroom than the substituted figure leaves the live login. Another candidate's headroom never counts, since a login that beats the substituted figure says nothing of the target:

The failed-probe rules' target Outcome
At least --margin more headroom than the substituted figure leaves, in the live login's organisation or one not known The failed-probe rules' swap, made now with reason=projected: neither damping nor --hold delays it. With a home key it is a stay, as the failed-probe swap would be
Less than --margin more headroom than that, whatever other candidates have The failed-probe rules as without this rule: a damped stay, then the failed-probe swap after three failures
In another organisation (a confirmed crossing) The same: a substituted figure never makes a crossing sooner
None: no candidate even against headroom 0 Their no-capacity ALERT

So for a failed probe the rule makes the same swap or makes it sooner. It never turns the failed-probe swap into an ALERT, which would keep a dead live login live for as long as its probe fails. An early swap needs a reading of the live login near the threshold since the last swap, because a swap clears the series, so it cannot repeat while the probe keeps failing.

When the login is not near, its last point is too old, or the series is empty, the failed-probe rules apply as before. The series is cleared on a swap, so a failed probe just after a swap is damped as usual.

For example, with --session-at 70 --margin 5, a status line keeps rewriting s=66% with a new observation time on every cycle. The third identical reading is frozen and is read again. When that read fails, the cycle is decided on 70%: a swap to a candidate with at least --margin more headroom, or the ALERT. The failure keeps the frozen count, so the fourth identical reading is read again rather than trusted. The same holds when the cached observation time does not move, where the reading is also old.

With the same settings, live work read 66% on the last cycle and its probe now fails, and spare reads 68%. spare has 32 points of headroom, only 2 more than the substituted 70% leaves work, so it does not beat the substituted figure. The failed-probe rules apply as without this rule: two damped stays, then, on the third failure:

2026-11-09T14:16:05Z swap work->spare live failed target s=68% w=40% reason=failed-probe

With spare at 60% instead (40 points, 10 more than 70% leaves), the first failure swaps with reason=projected. With spare at 68% and another stored login, third, at 0%, the outcome is the 68% one: third beats 70% easily, but the failed-probe rules chose spare, and only spare is tested against the substituted figure.

Freshest live reading

For the live login, each cycle decides on the freshest reading it holds. The reading chosen is the one used throughout the cycle: the decision rule, the plan room test behind last_cycle.live_room, the cycle line, the swap line, the capacity file and the usage history. Readings are ranked by how they were obtained, never by the observation time they carry, because the status line rewrites old figures with new times (see Live reading series).

Rank Reading Used when
1 Taken from the usage source in this cycle: a direct probe, or a successful live re-read Always, over every lower rank
2 The held reading: the last point the series accepted The step judged the cycle's cached reading stale, no reading could be taken in this cycle, and the held reading is not lower than the cached one
3 The cycle's own cached (passive) reading Nothing fresher is available to it

A cached reading therefore decides the cycle only when nothing fresher is available. A newer observation time on a cached reading never promotes it over a held point; the contradicted cache rule already covers that case and is unchanged.

The held reading. It is the last accepted point for the same live login: its session figure, week figure, and session and week reset times. It is offered only while both windows can still be open, by the same rule the near-threshold substitution applies to its last known point: a window is open before its reset time when the reading gave one, and in every case for less than five hours after the reading was taken. So a held week figure is not carried past the end of its week, and a week at 100% that has since reset no longer denies room; a reading with no week reset time is bounded by the five hours alone. The held reading is kept in memory with the series, is cleared with it, and is never offered for a different login, including a new login that takes the same profile slot.

When it replaces the cached reading. All of these hold:

  • the step judged the cached reading stale (frozen, old, lagging or contradicted);
  • the live re-read failed, was refused or could not be made, so no reading was taken in this cycle;
  • the cached reading is a measured one;
  • the held reading is not lower than the cached reading on either the session or the week figure.

A held reading that is lower on either figure is not substituted, and the cached reading, which is the higher and so the more cautious, is used as measured. There is no near condition on this path: unlike the near-threshold rule, the held reading is an actual measurement of the login that is older than this cycle, not an inference, so it is used whether or not it is near --session-at. The near-threshold rule still runs on top of the held reading when it applies, with the held week figure as its week. A failed probe is unchanged: the held reading replaces only a measured reading, and an exhausted cached reading is decided as measured. An exhausted cached reading that decides the cycle still carries the cached=<n>s annotation described below.

The STALE_LIVE and reread: lines are still written, so a substitution never hides an unavailable live source.

The cached=<n>s annotation. The live figures on the cycle and swap lines carry cached=<n>s when, and only when, they were read before this cycle's measurement began. <n> is whole seconds:

  • for a held reading, the age is taken from the held point's own reading time;
  • for a cached reading that decides the cycle, it is taken from that reading's reading time;
  • a direct probe and a successful re-read carry no annotation;
  • the annotation is written for measured and exhausted live readings alike;
  • a negative age is shown as 0, and an unknown reading time omits the annotation rather than guess one.

It is set for the live login only, never for a candidate, and the ALERT lines are not annotated: the cycle line of the same cycle already gives the live figures and their age. Because a passive live reading is the usual case in production, most cycle lines for the live login will carry cached= once this step is in place. Match cycle live= lines by prefix rather than by exact text. The annotation holds fixed text and one whole number, and never a token, path or account identifier.

What is recorded. A held reading is never recorded as one taken in this cycle. The usage history keeps the held reading's own time, so an entry whose reading is more than 300 seconds old is recorded as unknown, as for any other old reading. The capacity file has no per-reading time, so there is nothing in it to misdate; it carries the held figures, which is the point of the change. The target gate reads the live reading time as the earlier of the reading's own time and the start of the measurement, so a held reading can only reduce target re-reads: a target read before the held reading's time is still read again.

For example, with --interval 120 --session-at 70 --margin 5, live work reads s=56% w=100% directly on one cycle. On the next, the cache still holds s=5% w=95% from when work was swapped in, and the re-read fails. The cached figure is below the held point in the same window, so it is contradicted, and the cycle decides on the held s=56% w=100%, so live_room is false. On the next, a direct read gives s=58% w=100%, and on the one after the cache and the failed re-read repeat:

2026-11-21T00:26:02Z cycle live=work work:s=56%,w=100% spare:s=0%,w=30%
2026-11-21T00:28:10Z cycle live=work work:s=56%,w=100%,cached=128s spare:s=0%,w=30%
2026-11-21T00:28:10Z stale live reading; re-read
2026-11-21T00:28:10Z reread: work failed; treated as unknown
2026-11-21T00:29:53Z cycle live=work work:s=58%,w=100% spare:s=0%,w=30%
2026-11-21T00:32:07Z cycle live=work work:s=58%,w=100%,cached=134s spare:s=0%,w=30%
2026-11-21T00:32:07Z stale live reading; re-read
2026-11-21T00:32:07Z reread: work failed; treated as unknown

The live figures no longer return to the stale 5%/95% pair, and the stale pair no longer records room that the fresh reading denies. When the re-read succeeds, the cycle decides on its figures and the line carries no cached=. In the example, the stale live reading and reread: lines follow the cycle line of the same cycle.

Outlook and organisation affinity

A projected or substituted figure is decided under organisation affinity, with the room worked out on the live reading as measured for the crossing test, never on the projection. So a projected or substituted swap never makes a confirmed crossing, nor makes one sooner. A crossing waits for the live login to have no room now, to be an overflow profile, or to have failed its probe three times in a row (the failed-probe swap).

  • A measured reading below both thresholds. The live login has room, and a crossing is never a target. A login in the live login's organisation with --margin more room than the projection leaves is taken first, then one whose organisation is not known. When only a login in another organisation could take the session, the projection adds nothing: no swap, and no no-capacity ALERT, since there is room, across. A measured reading at or above --session-at does not cross either while the live login has room: the cycle stays, with a stay note. The crossing is made, with the crossing warning, in the cycle in which the live login has no room.
  • A failed probe. The failed-probe rules choose the target in the same way, with the live login counted as room 0. Their swap may cross, after three failures in a row, as before. The substituted figure only makes their swap sooner, and never when its target is in another organisation.

For example, with --interval 120 --session-at 70 --margin 5, live work (organisation A) reads 63% and is projected to 76%. spare (A) reads 40% and third (B) reads 0%. The projected swap goes to spare, although third has more room. With spare exhausted, the cycle stays at 63% with no ALERT, and the next cycle, measured at 76%, stays too, because work still has room and a login with room never crosses. When work reaches 100% of its session, the rotator swaps to third:

2026-11-09T14:12:06Z swap work->third live s=100% w=41% target s=0% w=0% reason=threshold
2026-11-09T14:12:06Z affinity: crossing work->third: Cross-organisation swap: earlier thinking becomes unavailable on the next turn. The visible conversation remains and the session can continue.
Example: a login rising 10 points a cycle

With --interval 120 --session-at 70 --margin 5, live work reads one point every two minutes:

Cycle work session Points used Projected Outcome
1 22% 22 none Stay
2 32% 22, 32 42.0 Stay
3 42% 22, 32, 42 52.0 Stay
4 50% 22, 32, 42, 50 59.3 Stay
5 63% 32, 42, 50, 63 73.3 Swap, reason=projected
2026-11-09T14:10:05Z cycle live=work work:s=63%,w=41% spare:s=0%,w=30%
2026-11-09T14:10:06Z swap work->spare live s=63% w=41% target s=0% w=30% reason=projected

Without the projection the rotator would stay at 63% and find work at its limit on the next cycle. With no candidate that qualifies, cycle 5 stays and writes a stay note instead, or the ALERT when no candidate is eligible. If work then reads s=63%,w=41% on two more cycles, the third identical reading is re-read with stale live reading; re-read.

A login rising slowly, from 20% to 22% in one interval, projects to 24% and stays.

One-shot and dry run

The one-shot amplihack profile rotate and --dry-run run the step, but start with an empty series and run one cycle, so neither ever sees a frozen reading or makes a projection. Only the old-reading rule applies. Neither takes --interval, so the limit is AMPLIHACK_ROTATE_INTERVAL when it is set, and 600 seconds otherwise. --dry-run makes the live re-read as it makes target re-reads: direct only, without token refresh, claude fallback or rotate-state writes.

The one-shot command, --dry-run and rotate watch (including a watch started with start) build their cycle with the same two re-read paths: the live re-read, which reads the home's .claude directory with token refresh off, and the target re-read described in Re-reads. Both build their reader through the cycle's own measurement settings, so a dry run stays read-only and direct-only after the re-read paths are added, and no mode has a second way to read usage. These freshness and projection rules need no additional configuration or public API; they use the existing interval, thresholds, margin and probe settings.

Rotate plan-room swap

A plan login costs nothing while it has room below 100%. The plan-room swap moves ~/.claude to a plan login that has room but is past --session-at or --week-at, so that a cycle does not end in ALERT no-capacity while a plan login can still run work. It is not a separate pass. It is the target rule applied to a live login that has no room, or that has room and is past a threshold, and it is logged with reason=plan-room when the target is at or above --session-at or --week-at, and with reason=threshold when it is below both.

A plan login has room when its reading in use gave ok and both its session and week use are below 100%. A failed probe, a login that was not measured, an exhausted reading and every API-key profile have no room. An unknown login has room only through its last good reading.

Three tests use that figure, and they are not the same:

Test Definition Used by
Has room ok reading, session and week below 100% The overflow rules, which spend nothing while a plan login has room, and auto-switch
Session room Has room, and session below --session-at The live_room bit the rotator records for a waiting step, which applies the same test to whichever login is live
Eligible target The target rule: a reading in use, both windows below 100%, week at or below --target-week-max, no recorded block, not failed Every usage swap the rotator makes

A plan-room target is an eligible plan login that qualifies against the live login. A login at or above --session-at can be one: it ranks after every eligible login below --session-at, because tier is the first ranking key, and it needs more room than the live login by the margin, and the hold applies when the live login still has room.

The swap is considered in two cases:

  • the live login has no room now: a window at 100%, a spend limit or an active recorded block, or the live login is an overflow profile. Every eligible plan login qualifies, so the rotator moves to the first in the ranking. No margin applies, and no swap back is possible, because a login with no room is never a candidate;
  • the live login has room, but has reached --session-at or --week-at on a measured reading (a failed live probe is left to the failed-probe rules, and a projected or substituted figure never counts as reaching a threshold here). An eligible login qualifies when its room is at least max(--margin, 1) more than the live login's.

A live login that is below both thresholds is left to the upgrade rule, so the plan-room swap adds no upgrade swaps.

The ranking is the one in Rotate target choice: tier (session below --session-at first), then the most room, then the lowest week use, then the name. Ranking by room puts the login with the most to use now first; the tier key keeps a login whose session is nearly spent behind every login whose session is not, so the rotator does not trade one login at the edge of its session for another. The live login is not ranked with the targets. Two things stop two logins from swapping back and forth: a live login with room is left only for one with at least max(--margin, 1) more room, and the hold stops a move onto a login at or above --session-at for --hold seconds after the last swap.

The chosen plan login is confirmed by a fresh reading like any other target. A login whose stored reading shows room but whose fresh reading shows it full is rejected, and the decision runs again on the new figures:

2026-11-02T19:52:37Z reread: login-ah reading stale s=74% w=73%; fresh s=100% w=73%
2026-11-02T19:52:37Z reject: login-ah no room on a fresh reading

login-ah is then session-exhausted and is not chosen.

When no login is eligible, the cycle writes the no-target line, once and not every cycle. When logins are eligible but none qualifies, it writes a stay note. A plan login that has room but is not a target still counts as room for the overflow rules, so credits and the API key stay unused while it exists.

Example: a live login with no room. Live login-aa has used its session. login-ab has room on paper but a week above the default ceiling of 95%, so it is not eligible. login-ag has no room. Of the other three, ddrake is below both thresholds and has the most room:

2026-10-30T19:42:56Z cycle live=login-aa login-aa:s=100%,w=60% ddrake:s=0%,w=88% login-ab:s=50%,w=97% above ceiling 95% login-ac:s=11%,w=92% login-ae:s=98%,w=17% login-ag:s=100%,w=100%
2026-10-30T19:42:56Z swap login-aa->ddrake live s=100% w=60% target s=0% w=88% reason=threshold

login-ac and ddrake are both below --session-at, so both are in the first tier. ddrake has room 12 against login-ac's 8. login-ae has the most weekly room but its session is at 98%, so it ranks in the second tier, behind both.

Example: a target past the week threshold. A login with a fresh session and a week that is nearly spent is still a target, up to the ceiling. With the live login-aa at s=100%,w=60% and login-ac at s=20%,w=93%, login-ac is past the default --week-at 90 but at most 95, so the rotator moves to it:

2026-10-31T08:20:05Z swap login-aa->login-ac live s=100% w=60% target s=20% w=93% reason=plan-room

Example: a live login that keeps its place. Live login-aa at s=90%,w=80% has room 10. login-ab at s=95%,w=60% has room 5, which is below 10 + 5, so it does not qualify:

2026-10-31T08:10:05Z cycle live=login-aa login-aa:s=90%,w=80% login-ab:s=95%,w=60%
2026-10-31T08:10:05Z stay: live room 10, best other login has room 5, a move needs 15

The cycle stays on login-aa and writes the stay note once. Because the live login is below 100% on both windows, the note is advisory, and the cycle records stayed. Later cycles with the same readings write no second line. Credits and the API key stay unused, because both logins have room.

Unmeasured plan logins. A plan login skipped as session running, leased, hosting, parked or directory refused, or whose probe failed, has no reading, so it cannot be chosen for room. It is unknown rather than empty. A login skipped as no account is counted as unknown (identity unavailable), and a login with a probe label such as HTTP 429 is unknown with a last good reading to fall back on; see Rotate unknown readings. The per-token rules below name what each does with such a login. Excluded, login-less and not oauth profiles do not count, nor do overflow or API-key profiles.

After a move to a login at or above --session-at. The ledger records live_room as false after such a move. The ledger's room bit requires session use below --session-at (Plan room in the ledger), which is stricter than the room the target rule asks of a target, so a recipe step that is waiting on a usage limit is not woken by the move. It wakes on the next cycle that records room, which for that login may be after its session window resets, hours later, or on a profile switch. Such a move happens only when no login below --session-at qualifies in the first organisation group that holds a qualifying login, because the ranking puts the first tier first. The bit is kept strict because a step woken onto a login at or above --session-at would meet its limit on its first call, which is what issue #2857 stopped. Whether the bit should follow the target rule for the login the rotator chose is open as issue #3067.

At --session-at 95 --week-at 98, every login below 95% of its session is in the first tier, so on readings like those of 22 November the rotator moves to a login below --session-at (login-ar, 88% and 20%) and records room.

Rotate decision order

While the live login is a plan profile, one cycle decides in this order. The first step that gives a swap ends the decision:

  1. The target rule, through the decision rule above: a threshold, projected, upgrade, plan-room or failed-probe swap onto a plan candidate, or a stay. The live reading used here is the one the live freshness step left: a fresh re-read where one was made, and the projected session use where a projection applies. A swap onto a plan login below --session-at that qualifies, or a stay, stands. A swap onto a login at or above it gives way to step 2 when the credit move there can be made; see Plan logins near their session limit. There is no second plan-room pass: the target rule has already considered every eligible plan login, so a login with room that is past a threshold is chosen in this step, or is not a target.
  2. Only when step 1 gives no target below --session-at, no measured plan login, the live one included, is room, and the overflow gate allows it: the first usable marked per-token profile in tier order. That is a credit overflow profile in tiers 1 to 9, then the marked API-key profile at tier 10, which must also pass its login check. reason=overflow-in. Credit tiers do not wait for a skipped plan login or one whose probe read a state such as not_logged_in: they have a spend limit, and the per-token line gives the count as N not measured. Neither tier is used while any plan candidate's probe is unknown, whatever its last good reading shows, or a plan profile is skipped as directory refused. A plan candidate whose newest stored reading shows a window with no room until a reset still ahead is not unknown: it is counted full. The API key waits for every unmeasured plan login, and for any plan login at or above --session-at with room.
  3. Otherwise the no-target line or a stay note, or, when only unmeasured plan logins kept the API key out, ALERT: API key not used live=<name>: no measured plan login has room, but these were not measured and may have: <names>.

The reading used for the room test in step 2 is the reading in use: a plan login that is unknown but has room on its last good reading counts as a plan login with room. That is a second reason for credits and the API key to stay out: an unknown plan login keeps them out whether or not a last good reading exists. A login whose week is above --target-week-max is not room for this test: it is not a target, and it keeps nothing unused.

While the live login is a per-token profile (credit or API key), the order is:

  1. a plan login below --session-at chosen by the target rule, reason=overflow-out. The live login counts as having no room, so every such login qualifies, and the first in the ranking is taken: the most room, then the lowest week use, then the name;
  2. a usable marked per-token profile in tier order, under the same gate, when either of these holds:
  3. the live profile is the API key and no plan login is room: the first usable credit profile, reason=overflow-out, because credits cost less than the API key;
  4. the live profile is blocked by a spend limit or an API-key block: the next usable one after it;
  5. off the API key, or off a blocked credit profile when no other credit profile can be used, the first-ranked eligible plan login at or above --session-at, reason=overflow-out: it costs nothing;
  6. otherwise a stay, or the ALERTs described under Overflow decision and Moving off the API key.

Credit profiles are billed too, so they wait for plan logins that are room: below 100% on both windows, the week at or below --target-week-max and the session below --session-at. The API key also waits for a plan login at or above --session-at with room. A credit tier is never used ahead of a plan login that is room, whatever its tier.

In both orders, a step that chooses a target by its reading (threshold, projected, upgrade, failed-probe, plan-room or overflow-out) ends the decision only once that target is confirmed by a fresh reading and passes the freshness gate. When the gate reads it again, the whole order runs again from step 1 on the new figures. An overflow-in target is chosen by tier, not by a reading, and is not gated.

Rotate overflow

An overflow profile is one whose account has usage credits turned on at https://claude.ai/settings/usage, so it keeps working after its plan's session or weekly limit and the extra use is billed to the credits. A plan profile is any other profile. Profiles are marked with profile overflow add; with no profile marked, every rule in this section is inactive and the rotator behaves exactly as described above, plan-room swap included. The full order of a cycle is in Rotate decision order.

Credits cost money and plan capacity does not, so the rotator:

  • never moves onto an overflow profile while any measured plan login, the live one included, is room: a usable target under the target rule whose session use is below --session-at. A login above --target-week-max, or with a recorded block, is not room, so it does not keep credits unused. A login at or above --session-at is not room for a credit profile either, though it still keeps the API key unused; see Plan logins near their session limit;
  • moves onto one only when the live plan login has reached a threshold, no plan login is room now, no plan candidate's probe in this cycle is unknown, whatever its last good reading shows (it was rate-limited, timed out, or claude could not be started, read or waited for), and the next plan reset is known and more than --overflow-wait seconds away (an unknown reset spends money only with --overflow-unknown-reset 1). A stored reset that has already passed is not a known reset. When a usable credit profile waits on that login, the rotator reads it again in the same cycle and decides on the fresh reading; see A stored reset that has passed;
  • moves back to a plan profile in the first cycle in which a plan login is room. A login at or above --session-at is a way back only off the API key, or off a credit profile that cannot spend.

Reaching --week-at on every plan login is not enough on its own: while a plan login is room, the rotator does not spend. Reaching --session-at on every plan login, the live one included, is enough for a credit profile once the other conditions above hold. When a marked overflow profile stays unused, the ALERT line says overflow marked but held and names each plan login that holds it with its reason: a usable target now, capacity within --overflow-wait, or not measured. A login whose stored reset has passed, and which could not be read again, is named as not measured, never as capacity within the wait. It uses the plan-room swap when that login is eligible and qualifies, and otherwise stays and writes the no-target line or a stay note.

Auto-switch follows the same rule with the running rotator's gate: the wait, the unknown-reset choice, and the plan-capacity test below (--session-at, --week-at). It does not apply the rule about unknown plan probes: it decides from recorded readings, and an unknown probe is never recorded. It keeps its own room test, both windows below 100%, so a plan login at or above --session-at with room keeps auto-switch off credits, though not the rotator.

Plan pool

The plan pool is the live login, when it is not an overflow profile, plus every candidate that is not marked overflow. Excluded, leased, hosting, parked, session-running and login-less profiles are not candidates, so they neither offer capacity nor shorten the wait.

A plan candidate has capacity when all of these hold:

  • its probe this cycle gave ok;
  • its session use is below --session-at;
  • its week use is below --week-at.

--margin, --hold and --upgrade-margin play no part in this test. A plan login that has capacity is one the rotator would not swap away from for reaching a threshold. A plan login without capacity can still be a plan-room target: with --week-at 85, a plan login at s=20%,w=88% has no capacity but has room and is eligible, so the rotator moves off credits onto it. It does not move back onto credits from there while that login, or any other, still has room. A plan login at or above --session-at is a target too, ranked after every login below it, but it is not room for a credit profile: with --session-at 80, a login at s=85%,w=40% does not keep a usable credit profile unused, and a rotator on credits does not move onto it. A login whose week is above --target-week-max is never a target and keeps nothing unused.

Plan logins near their session limit

A plan login whose session use is at or above --session-at has little room left, and a move onto it is soon followed by another: a move from a login at 100% session onto one at 98% finds that login full at the next cycle, while a credit login stands unused. Such a login is therefore not room for a credit profile:

  • It does not keep a credit profile unused, and neither does the live login when it is at or above --session-at. When the live plan login has reached a threshold, and no plan login has its session below --session-at, room in both windows and its week at or below --target-week-max, the rotator moves onto the credit profile under the same conditions as when every plan login reads 100%: no unknown plan probe, no directory refused skip, and the next plan reset beyond --overflow-wait.
  • A threshold or plan-room swap the target rule would make onto such a login gives way to that credit move. When the credit move cannot be made, because no credit profile is usable, a plan probe is unknown or a plan reset is within --overflow-wait, the swap onto the login still stands: some room is better than none. A plan login whose stored reset has passed does not stop the credit move by itself: the cycle reads it again first, and only a read that fails leaves it unknown; see A stored reset that has passed.
  • Organisations do not change this. While the credit move can be made, plan logins at or above --session-at in the live login's organisation do not keep a credit profile the rotator may reach under the organisation order out of it. When the live login may cross organisations, that includes a credit profile in another organisation, which the rotator moves onto by a confirmed crossing with the affinity: warning. They still keep the API key unused. When no credit profile can be reached, for example one in another organisation while the live login still has room, the swap onto the plan login stands.
  • On a credit profile, such a login is not a way back, so the rotator does not leave credits for a login it would leave again a cycle later. It is the way off a credit profile that cannot spend, when no other credit profile can take the work.
  • It still keeps the API key unused, as any plan login with room does, and it is a way off the API key when no credit profile is usable.
  • A plan login whose probe failed is counted full when its newest stored reading shows its session at or above --session-at with the stated reset still ahead. Like any login counted full, it then keeps neither a credit profile nor the API key unused.

The per-token line of such a move, and the overflow: on or overflow: staying on line, then read no measured plan login below --session-at (<names> at or above it) in place of no measured plan login below 100%.

For example, with the default --session-at 85, the live login at s=100%, plan logins at s=94%, 97% and 98% with their weeks under the ceiling, the other plan logins with their weeks at 98 to 100%, and a usable credit login, the rotator moves onto the credit login and not onto the login at 98%. With one plan login at s=30%,w=40% among them, it moves onto that login. With no credit login marked, it moves onto the login at 94%, as before.

Auto-switch keeps its own room test, so for a Claude session it does not move onto credits while such a login has room.

Overflow candidates

An overflow profile can be moved to when all of these hold:

  • it is a candidate: the exclude list and every other skip reason apply to it as to any profile, so an excluded overflow profile is never used;
  • it has no active spend block;
  • its probe this cycle gave ok, session_exhausted or weekly_exhausted. Its session and week numbers are its plan limits and do not stop it being used. Any other state, including timeout, unparsed and not_logged_in, means it is not used this cycle.

The first eligible profile by tier, then by overflow list order within a tier, is chosen.

Earliest plan reset

For each profile in the plan pool, the time it regains capacity is:

Live or candidate reading Regains capacity at
Only the session window is at --session-at or exhausted the session reset
Only the week window is at --week-at or exhausted the week reset
Both are the later of the two resets
Neither is now
Probe failed, or a needed reset time is missing unknown
The reset it gives is at or before now unknown, and the login is read again

The earliest plan reset is the earliest of the known times; unknown ones are left out, so a plan login whose probe failed never shortens the wait. When no time is known, for example every plan login reads exhausted with no resets_at, the earliest plan reset is unknown, and by default the rotator does not move onto an overflow profile: it writes the no-capacity ALERT and stays, because a move onto overflow costs money and the plan login might be back in minutes. --overflow-unknown-reset 1 (AMPLIHACK_ROTATE_OVERFLOW_UNKNOWN_RESET=1) makes an unknown reset count as far away instead: work then moves onto an overflow profile and is billed at once, and the overflow: on line reads next plan reset unknown. Turn it on only if you would rather pay than wait for a reset nobody reported.

One known reset is enough. A plan candidate whose probe timed out or could not run, or a plan profile skipped as directory refused, blocks the move anyway (see Overflow decision), but one that read not_logged_in, unparsed or spend_limit does not. With an expired login, for example, another login's known reset decides, and the rotator can move onto overflow even though the expired login would have had capacity again within --overflow-wait. Reset times are the resets_at values that profile usage reads, kept for exhausted readings too. A reset more than 8 days away in a usage request answer is unknown, so it cannot make the wait look long.

A stored reset that has passed

A reading can show a window at its threshold with a reset that is already past, for example a stored reading taken shortly before the window reset. That reading was taken in a window that has ended, so it says nothing about the login's room now. Its reset is never capacity regained within --overflow-wait, whatever the wait, 0 included: it is left out of the earliest plan reset, and the login counts as unknown, so it holds a move onto credits or the API key as an unknown probe does.

The cycle reads such a login again before it settles a decision that the login could change: an ALERT, a move onto credits, or a move onto a plan login at or above --session-at. The same applies off a live plan login with no plan login below --session-at, and off a credit profile that cannot spend. It applies whether or not a credit profile is usable, when the live probe failed, and when the ALERT comes from the live login's outlook rather than its reading. The read is the one the rotator makes to confirm a target: the user's probe method with passive readings off, within the same time limit. The cycle then decides on the fresh reading, in the same cycle:

Fresh reading Outcome
Room below --session-at The login is a target, as any login with room is. The rotator moves onto it in that cycle, and this reading confirms it as the target, so it is not read twice.
Room, but a model's week at or above --week-at The login is rejected as a target, as a target whose confirming read shows that is, with the same reject: line. It is not read twice.
Still at a threshold, with a reset ahead That reset counts. The login holds the credit move only when the reset is within --overflow-wait; otherwise the move onto credits goes ahead.
The read fails, or still shows a reset that has passed The login stays unknown and holds the move, as a failed probe does.

Each such login is read at most once a cycle, and these reads are not counted in the limit of three confirmation reads. They do share its time limit: a slow read leaves less time to confirm the target, and a read that uses all of it can leave the target unconfirmed for that cycle. The fresh reading replaces the stored one, so a later cycle that reuses it reads the login again only if its new reset has passed too. No read is made under the lock, after rotate stop, once that time limit is spent, or when a plan login below --session-at decides the move. A login whose read fails stays unknown for that cycle and keeps the API key unused, as an unknown login does; it is not read again in that cycle. A move that a failed live probe gives still waits for the failed-probe rules: the count of failed probes, the hold after a swap and the home-key rule. The live login is not read by this step: a live reading whose reset has passed stops the move onto credits for that cycle.

Overflow decision

While the live login is a plan profile, the rotator first applies the decision rule and the failed-probe rules to the plan pool alone. A threshold, plan-room or upgrade swap onto a plan login below --session-at that the target rule chooses always stands. One onto a login at or above --session-at gives way to a credit move that can be made; see Plan logins near their session limit. Only when that gives no such target on a measured live reading, and no measured plan login, the live one included, is room on the reading in use, does it consider overflow:

Condition Outcome
Live probe failed As without overflow. A failed live probe never moves work onto credits.
A plan login, the live one included, has room below 100% on both windows and its session below --session-at No overflow. The plan-room swap moves to the first-ranked target, or the cycle stays with a stay note or the no-target line when no login qualifies or the only candidates are above --target-week-max. Neither credits nor the API key are used while such a login exists.
Every plan login with room, the live one included, is at or above --session-at A credit profile is used by the rows below, as when no plan login has room. The API key is not. When no credit move can be made, the plan-room or threshold swap onto the first-ranked login stands, or the cycle stays as above. See Plan logins near their session limit.
A plan candidate's probe in this cycle was unknown (rate-limited, failed in transport, identity unavailable, timed out, still running, or claude could not be started, written to, read or waited for, or the profile directory was refused just before the spawn), whatever its last good reading shows As without overflow: the ALERT, or the swap onto the plan candidate that qualifies. That login might have capacity, so such a probe never moves work onto credits or the API key, with or without a last good reading. It is probed again on the next cycle. The plan-room swap is not held when the live login has no room: it costs nothing.
A plan candidate's probe was unknown, and its last good reading shows room The same as the row above, with a second reason: the login counts as a plan login with room. The plan-room swap can rank it, but swaps to it only after a fresh reading confirms it.
A plan candidate's probe failed or was unknown, it has no active block, and its newest stored reading shows its session at or above --session-at, or its all-models week at 100% or more or above --target-week-max, with a stated reset still ahead The login counts as measured and full: it does not hold a credit tier or the API-key tier, and its stated reset counts towards the earliest plan reset. The per-token line, and an API key not used or overflow marked but held ALERT, end with ; counted full from a stored reading: <names>.
A plan profile is skipped as directory refused As without overflow. Its login cannot be checked and might have capacity. The skip, and so the hold, comes back on every cycle until the directory is fixed.
An unmeasured plan login, and the only usable overflow profile is the API key No move onto the key. ALERT: API key not used names the logins.
No plan login has room, earliest plan reset - now > overflow-wait, and an overflow candidate is eligible Swap to the first eligible one by tier, reason=overflow-in: credit tiers 1 to 9, then the marked API-key profile at tier 10 if its login check passes. The --hold does not apply.
A plan login's stored reset has passed That login is unknown until the cycle reads it again, and the rows above and below apply to the fresh reading.
earliest plan reset - now <= overflow-wait, for a reset still ahead As without overflow: the ALERT, or the threshold swap onto the plan candidate without capacity, which costs nothing.
Earliest plan reset unknown As without overflow. With --overflow-unknown-reset 1, as for a reset beyond the wait.
No overflow candidate is eligible As without overflow: ALERT no-capacity.

For example, with the live login at s=100%,w=60% and a plan candidate at s=20%,w=93%, the live login has no room and the candidate is eligible, so the rotator makes the free swap onto it whatever the plan reset, and no credits are spent. With the live login at s=95%,w=60% (room 5) and the candidate at s=87%,w=50% (room 13), both are at or above --session-at: with a usable credit profile and the plan reset beyond the wait, the rotator moves onto credits. Without a usable credit profile, the candidate qualifies against 5 + 5 with the default margin, so the rotator moves onto it, behind the hold because its session is at or above --session-at; with the candidate at s=92%,w=50% (room 8) it does not qualify, so the cycle makes no swap and writes a stay note. Auto-switch spends only once every plan login reads 100% on one of its windows and the reset is beyond the wait. The target rule changes the rotator's plan-room swap only; the moves auto-switch makes for a Claude session are unchanged.

The comparison is strict: a reset exactly --overflow-wait seconds away stays. With --overflow-wait 0 the rotator moves onto overflow as soon as no plan login has room and the earliest reset is known and in the future. A reset at or before now is not in the comparison at all: that login is read again first.

A plan candidate that reads not_logged_in, unparsed or spend_limit, or ok with no week figure, does not block the move, so a login that has expired cannot keep the rotator off credits for good. A plan profile whose directory fails the ownership and mode check is different: its login cannot be checked at all. The candidate list skips it as directory refused before any probe, so it is never chosen, and the skip blocks the move on every cycle until the directory is fixed. A directory that changes between that check and the spawn reads error (profile directory refused) in the cycle and blocks the move in the same way. amplihack profile usage <name> shows the error row whenever the directory is refused. An overflow profile skipped as directory refused blocks nothing, and an excluded profile is skipped as excluded whatever its directory.

A rejected plan login counted full

A plan login whose probe failed or was rejected, for example with HTTP 429, might have capacity, so it holds the move onto credits. It does not when its newest stored reading shows that it has none. The stored readings are the ones the rotator already keeps: the reading this watch last took of the login, the login's newest point in the usage history, and its entry in usage.json, which Claude's status line and profile usage record. Only the newest of them counts, by when it was observed. It counts the login full when the reset it states for a window is later than the cycle's clock and that window leaves no room: the session at or above --session-at, or the all-models week at 100% or more or above --target-week-max. The usage history states no session reset, so only its week can count, and in a usage-limit failure only the week counts, because its five-hour window was set from a step's message. A model's own week does not count. No age limit applies: use only rises within a window until it resets, so the stated reset bounds the reading.

A login counted full is decided on as one with no room, with the stored windows, so its reset still enters the overflow gate. Nothing is written back to the history, the capacity file or the ledger, and the next cycle probes the login again. A login with no stored reading, one whose newest stored reading shows both windows below 100%, and one whose full window's reset has passed or is not stated stay unknown and hold the move. So does one whose newest stored reading shows its session below --session-at and its week at or below the ceiling.

An unknown plan probe stops only a move from a plan login onto an overflow profile. It does not stop these moves:

Move Why it is not stopped
From a live overflow profile with a spend block to the next eligible overflow profile The blocked login cannot spend, so staying on it would only stop work.
From a live API-key profile to an eligible credit profile Credits cost less than the API key.
overflow-out back to a plan login Its target is always a plan login with a reading in use, fresh or last good; an unknown probe with no last good reading is never a target.

While the live login is an overflow profile, these rules apply in order:

Condition Outcome
A plan candidate is eligible under the target rule and its session is below --session-at Swap to the plan login the ranking puts first, reason=overflow-out: the most room, then the lowest week use, then the name. The live login counts as having no room, so every such login qualifies. --margin, --hold and --upgrade-margin do not apply. A login above --target-week-max, with a recorded block, or at or above --session-at is not chosen here.
The live reading is spend_limit, the live profile has an active block, or its session window reads 100% or more before its stated reset Block the live profile, then swap to the next eligible credit candidate if the wait rule above still holds, else to the first-ranked eligible plan login, which is at or above --session-at, else to the API key under the wait rule when no plan login is eligible, else to the plan login that regains capacity first (the earliest known reset of the window that keeps it full; a tie goes to the first candidate), else ALERT no-capacity. A plan login with no known reset, or with a recorded block, is not chosen by that last step. The API-key profile keeps its own rules.
Live probe failed Failed-probe rules, with plan candidates as the only targets; otherwise stay on credits.
Otherwise Stay on credits.

--session-at and --week-at are never applied to a live overflow profile. A full session window is: a credit login that has used its whole session window meets its individual spend limit there, which the probe cannot see, so it is blocked as above. A full weekly window alone does not block it. An overflow profile is never swapped for another overflow profile except after a spend limit or a full session window, and never for a lower tier that becomes usable again.

The rules do not flap. Off a credit profile that can spend, overflow-out moves only to a plan login below --session-at, and the rotator moves back onto credits only once no plan login, that one included, is room and every rule above holds again.

If an overflow profile's login is live in ~/.claude while an eligible plan profile below --session-at exists, for example after you put it there by hand, the next cycle moves it out with reason=overflow-out. A plan login above --target-week-max, or with a recorded block, is not eligible, and one at or above --session-at is not a way off a credit profile that can spend, so the rotator leaves the overflow profile where it is. To keep running on it, remove the mark, stop the rotator, or put it there with amplihack profile switch <name>, which pins it.

Removing the mark from the live overflow profile does not by itself stop credit spending. From the next cycle the login is a plan profile at or past its limits, so the ordinary decision rule applies: it is swapped out only when a candidate qualifies under the target rule, and otherwise the cycle writes a stay note or the no-target line and leaves the login in ~/.claude, where Claude keeps billing work to the credits. See Stopping credit use.

The default pointer is outside this policy. A launch that resolves to a profile through .default uses that profile directly, whether it is a plan profile or an overflow profile, so leave the pointer unset (amplihack profile switch --none) when using overflow.

Pin and overflow

A rotation pin from profile switch <name> wins over every overflow rule, in both directions. The pin is checked before the cycle measures, so the overflow decision never runs while a pin is in force:

Pinned login Readings Outcome
An overflow profile A plan login has capacity held. The login stays on the overflow profile and keeps spending credits. Switching onto an overflow profile is a choice to spend. status shows on overflow: yes (<name>, held by switch).
An overflow profile Its credits run out held, and still watched for the spend limit (see below). The login does not move, but the profile is blocked with one ALERT that names profile switch --none.
A plan profile Every plan login is out of capacity and an overflow profile is eligible held. The cycle never moves onto credits, so nothing is spent.

amplihack profile switch --none removes the pin; the next cycle applies the overflow rules above, so it moves off a pinned overflow profile at once if a plan login has capacity. The rotator's own moves onto or off overflow never write a pin.

The pin stops moves, not the spend-limit check. While the pin holds the live login on an overflow profile that has no active block, each held cycle probes the live login only, without the lock, and measures no candidate. If the probe reads spend_limit, the cycle takes the lock again, checks that nothing changed while it probed (with the rules for a stay in Rotate revalidation), and blocks the profile as in Overflow spend-limit block, with this ALERT in place of the usual one:

ALERT: overflow profile <name> hit its spend limit; blocked until <time>; rotation is held on it by `profile switch`, so run `amplihack profile switch --none` to move off it

The login stays where it is, since the pin still holds. Once the block is recorded the held cycles stop probing until it ends or is cleared. A pinned plan login is never probed. A pinned profile in the auto-switch exclude list is never probed either: each held cycle logs skip: pinned profile <name> is excluded; spend not probed and the pin holds as before. profile switch refuses an overflow profile that already has an active block (see Rotate switch).

The --hold that overflow-in and overflow-out ignore is the minimum time after a rotator swap. It is not the pin.

Overflow spend-limit block

Claude's You've hit your org's monthly spend limit … message, and the older Your organization has reached its monthly spend limit wording, mean the account's credits are used up or not turned on. The usage probe matches both, without regard to case, and classifies the profile as spend_limit. The probe is the only detector of the organisation's limit: the rotator probes the live overflow profile on every cycle, including a cycle held by a pin on it, so a block is recorded within one cycle. (A held cycle probes only the live login, and only while it has no active block.) The probe cannot see an individual spend limit on a plan login, so for that case a failed agent step writes the block itself; see A spend limit blocks the login the step ran under. The recipe-run classifier writes none. A probe that reads spend_limit for an overflow profile, live or candidate, blocks that profile:

  1. Under the lock taken in step 6, the rotator adds {"at": <now>, "until": <reset>, "reason": "spend_limit"} to overflow_blocked in the ledger. <reset> is 00:00 UTC on the first day of the next month. The probe text, including any reset Claude states, is not stored.
  2. It writes ALERT: overflow profile <name> hit its spend limit; blocked until <time> once for that block. The block record, not the ledger's alert key, prevents a repeat, so the ALERT does not stop the usage-limit wait from seeing capacity when the cycle moves somewhere else.
  3. A blocked profile is not an overflow candidate. If it was live, the cycle moves away as in the table above.

The individual spend limit on a credit login is seen in one other way. A live credit-backed overflow profile whose session window reads 100% or more, while no plan login is eligible, is blocked by the cycle that reads it, in the same ledger, with the same spend_limit reason, and moved away in that cycle. A failed agent step that meets a usage limit (the weekly limit included) on the live credit login also blocks it, and the next cycle moves away by the same rule; a step writes no block on a credit login that is not live. See A spend limit blocks the login the step ran under. The session-window block ends at the session window's stated reset, or five hours after it is recorded if that comes first or no reset is stated, and its ALERT is ALERT: overflow profile <name> is at 100% of its session window; blocked until <time>. profile overflow list shows it, and profile overflow clear removes it. A spend limit that an interactive session meets below 100% of the session window writes no record, so the rotator does not see it.

A block ends at its until time or with profile overflow clear <name>. Expired blocks are removed from the ledger the next time the rotator records a cycle. The reset time Claude prints in the spend-limit message is not read; a spend limit raised or credits added before the 1st need overflow clear.

A block has a kind, written as its reason. The kinds are spend_limit, session_limit, week_limit and credit_limit, and a ledger may hold any other kind of 1 to 32 characters from a-z, 0-9 and _. The rotator treats every kind alike when it chooses a target: a login with a block whose until time is in the future is not eligible, whatever the kind, and it is eligible again from that time on, if it is otherwise the best. A block of a kind this release does not know therefore still excludes the login, and a ledger that holds one still loads. The target rule reads blocks for plan logins too: a login recorded as having hit its spend, session or weekly limit is not moved to before its reset. The cycle line shows the block as blocked until <time> (<kind>), where <kind> is a fixed label for the limit kind (spend limit, session limit, week limit, credit limit, or a recorded limit for any other kind a ledger holds), never the stored text.

Every block, whatever its kind, also counts towards the earliest reset the rotator wakes at, so a watching rotator runs a cycle when the block ends rather than at its next --interval. The other bounds on a block are unchanged (a valid profile name, a span of at most 62 days, at most 256 records). A binary from before the reader accepted every kind refuses a ledger holding any reason other than spend_limit. Widening the reader is not a schema change, so the ledger version stays 1 and this refusal is a stated compatibility trade-off: stop the rotator and upgrade every binary that uses the root before a limit of another kind can be recorded.

A spend_limit reading on a plan profile is a failed probe, as it always was. A spend_limit reading on a live overflow profile does not count towards the three failed live probes.

The block depends on the spend-limit text appearing in the output of claude -p /usage for that login. The usage request has no spend-limit field, so profiles marked as overflow are probed with /usage only, never with the usage request, live or candidate, in a held cycle too. An overflow profile needs its usage credits turned on: an account with them off has no spend limit for /usage to show, and it stops at its plan limit like a plan login. If the text does not appear, the rotator cannot see that credits have run out, and sessions on that login keep failing. The two ways out behave differently:

  • profile overflow remove <name> makes the login a plan profile. A spend_limit reading on it is then a failed live probe, so the failed-probe rules swap it out only after three consecutive failed cycles, and only to a plan candidate. Any other reading is judged by the ordinary decision rule, as described above.
  • profile rotate stop stops all swapping and leaves the login in ~/.claude. Nothing moves it until you start the rotator again.

A spend limit blocks the login the step ran under

The usage probe cannot see an individual spend limit on a plan login, so the rotator would read such a login as having room while every step on it fails. The step that meets the limit therefore records it. The same record is written for every limit a step meets (session, weekly, spend and credits), by one function, note_limit_block; see Usage-limit waits. Two limits write no record:

  • A limit met on a credit login, a profile in the overflow order that is not an API-key profile, that the rotate ledger does not record as the live login. A full window is a credit login's normal state while it serves overflow, and the rotator has no login to leave, so whether that login can serve is for its own probe and the accepted-call check to decide. A limit met on the live credit login is recorded as on a plan login: that login declines calls, and the rotator moves away from it. The step reads the ledger's live before it resolves the reset and again under the lock. An API-key profile keeps its block, even when overflow= marks it. When the settings or the profile kinds cannot be read, the block is written.
  • A limit on one model: a message about the Fable, Opus or Sonnet limit, such as You've hit your org's monthly spend limit … your Fable limit resets Dec 6, 5pm (UTC). The login can still serve every other model. A login whose own week for one model is full is still read as such by the cycle's figures. The reason is spend_limit for every kind, because a rotator from an older binary refuses a whole ledger whose entry has another reason. The kind of limit is stated in a separate kind field (session_limit, week_limit, spend_limit or credit_limit), which every reader of a block ignores when it does not know it, as well as in the ALERT line and on stderr. When an agent step fails with a Claude limit message that states a reset the usage-limit wait can parse (You've hit your individual spend limit … your weekly limit resets Nov 24, 2pm (America/Los_Angeles)), it adds {"at": <now>, "until": <reset>, "reason": "spend_limit", "kind": "spend_limit"} to overflow_blocked in the ledger, keyed on the login whose credentials were rejected: the profile of a named-profile step, or, for a step on ~/.claude, the profile in ~/.claude when the attempt ended. The rotator can swap ~/.claude while a step runs, and the running session then sends the new login's credentials. The step reads the live login before the attempt and again at its end, and reads the rotator's swap record:

  • A swap that finished within one second of the attempt's end: the login cannot be told, and no block is written.

  • A swap that finished after the attempt started: the login that swap made live.
  • Otherwise, when both readings came from the same file, the login read at the end.
  • Anything else: the login cannot be told, and no block is written.

This is the record described above, so nothing else reads or expires it differently. The record is made once per message, before the wait is planned.

Situation What the step does
The login is a credit login that the rotate ledger does not record as live Writes nothing and prints note: login <name> <kind> not blocked (credit login; its own probe decides) on stderr and in the rotate log. This is asked before the reset, so a message with no stated reset gives this line too. The live credit login follows the rows below, as a plan login does.
The message is about one model's limit Writes nothing and prints note: login <name> <model> limit not blocked (one model's limit), where <model> is Fable, Opus or Sonnet.
The message states a reset ahead of now and no more than 62 days away Writes the block, prints ALERT: login <name> hit its <kind>; blocked until <time> on stderr and in the rotate log once, and plans the wait. <kind> is session limit, weekly limit, spend limit or credit limit; the spend-limit line is the one 1.2.193 wrote.
The login already has an active block Writes nothing and prints no second ALERT; the existing until is not extended.
The message states no reset A spend limit is recorded until the rotator's own spend reset (00:00 UTC on the 1st of the next month). A session, weekly or credits limit writes nothing and prints one line with the fixed reason no stated reset. The wait is a login-change wait for a spend limit and a capacity wait for the others.
The stated reset has already passed Writes nothing and prints ALERT: login <name> <kind> not blocked (stated reset already passed).
The stated reset is more than 62 days away Writes nothing and prints ALERT: login <name> <kind> not blocked (stated reset out of range).
The rotator holds the ledger lock for more than 10 seconds Hands the block to the rotator: writes it, already checked and held to its kind's window, as one file in .auto-switch.d/rotate/handoff/, prints one line on stderr and nothing in the rotate log. The rotator applies it under the lock at its next cycle, or at once when it is waiting, by the rules in this table, and logs ALERT: login <name> hit its <kind>; blocked until <time> (handed on by a step) once. A hand-off that cannot be written is reported as below with the reason rotator busy.
A step on ~/.claude cannot tell which login was live when its attempt ended Writes nothing and prints ALERT: login <name> <kind> not blocked (live login unknown), where <name> is the login the attempt was launched on.
The ledger cannot be read or written, or it already holds 256 blocks, or a hand-off cannot be written Writes nothing and prints ALERT: login <name> <kind> not blocked (<reason>), where <reason> is rotator busy, ledger unreadable, ledger not written or too many blocks. The login is then not recorded, so the wake condition of the wait is unchanged.
There is no rotate ledger Writes nothing, and does not create one.

No row ends, delays or refuses the run: the step takes the lock once, never retries, and plans its wait in every case.

A rotate cycle applies each waiting hand-off after the ledger has loaded and before it reads the logins, so the same cycle reads the login as blocked. It prunes expired blocks at the cycle's time, keeps an active block as it is, and drops a hand-off whose end has passed, whose span is outside the rule or that would exceed 256 blocks, with the not blocked line. A hand-off for a credit login that the ledger does not record as live when the hand-off is applied is removed with the credit-login line and never applied. A file in the folder that is not a readable hand-off of this user's is removed, without following a symlink. While the ledger cannot be read, hand-offs stay in the folder. profile switch does not apply them. The ALERT lines carry the profile name, the fixed words for the kind and a time only, never text from the limit message. Only a failed step is read, and only a message in a harness's own limit shape (Claude's, or Codex's credits line).

While the block is recorded:

  • The rotator treats the login as having no room, whatever its own probe reading says. If it is live, the next cycle swaps to the login with the most room by the ordinary rules; if no login has room, the usual no-capacity ALERT follows.
  • profile switch, auto-switch and the wake condition of a capacity wait do not choose it, so a waiting step resumes on another login. Auto-switch reads a plan login's step block as ended once the login's stored reading shows room, as described below.
  • rotate status and profile usage show it as blocked until <time>, in one line of the existing output.

The block is data only. It ends at the reset the message stated, when the rotator drops it as it drops any expired block, or earlier with profile overflow clear <name>. A message that quotes a reset the account does not have blocks the login until that time, bounded by the 62-day span.

A block whose kind is session_limit or week_limit also ends as soon as a reading of that login, taken after the block's at, shows that the window the block was written for has reset. The reading shows that when its window of that kind resets more than one window length (five hours for a session, seven days for a week) after at, and both the window and the reading's figure for it are below 100%. The window that was open when the limit was met began at or before at, so only a later window resets that late. The cycle that holds such a reading treats the login by the ordinary rules at once: it can be the target of that cycle. Under the lock, the cycle moves the block's until back to the reading's time, the ledger's pruning removes the entry before any swap, and the rotate log gets one line:

2026-11-30T03:20:05Z unblock: held session limit block ended; a later reading shows its window has reset

A reading that does not count: one taken at or before at, a failed or unknown probe, a last good reading standing in for one, and a reading that shows the old window or a full new one. A spend_limit or credit_limit block is not ended by this rule, which reads one window's reset; the two rules below end it. A block with no kind (every block written before this field, and every block the rotator writes itself) and a block of a kind the binary does not know are never ended by a reading. A session block ends whatever the week reading shows; the ordinary week rules then decide whether the login is a target. No timer or retry is involved: the block ends on the cycle that reads the evidence.

A spend_limit or credit_limit block that a step wrote on an overflow profile ends as soon as a reading of that profile, taken after the block's at, shows both its session and its week below 100%, in the window figures and in the reading's own figures, the probe saw no spend limit, and the profile was not live when the block was written: the ledger's live names another login, live since the block's at or before. An overflow profile spends credits only once one of its windows is full, so while both have room no spend or credit limit can have rejected it: the block was written against the wrong login. No reset time is compared, because overflow profiles of one organisation can share a reset. An overflow profile with a full window keeps its block. So does one that was live when the block was written, or that may have been because the live login changed after it: that profile may be the one that was rejected, and the rotator would otherwise move back onto a profile it has just left. The cycle ends the block and logs it as for a session or week block above, with this line:

2026-11-30T14:15:37Z unblock: block on login-c ended; a later reading of it shows room

A block a step wrote on a plan login, of any of the four kinds, ends as soon as a reading of that login, taken after the block's at, shows both its session and its week below 100%, in the window figures and in the reading's own figures, and the probe saw no spend limit. A plan login spends credit only once one of its windows is full, so while both have room no spend limit can reject it. A reading taken at or before at, a failed or unknown probe, a last good reading standing in for one, a reading with either window at 100% and a probe that saw a spend limit keep the block. No live-login condition applies, so the block can end while that login is live. The rules run in the order above, and a block one rule has ended is not read by the next, so each block ended gets one line:

2026-12-01T05:20:11Z unblock: step block on plan login login-b ended; a later reading shows both windows below 100%

Auto-switch applies the same test where it reads blocks: the takeover check, the selection's list of blocked profiles, and the earliest block end that times a step's wait. It reads the login's entry in usage.json, which Claude's status line and profile usage record. The entry ends the block for auto-switch's own decision when its source is the status line or a direct read (a usage-limit failure never counts), it was observed after the block's at and not after the present time, and both its five-hour and its seven-day windows are present and below 100%. The week is the larger of the seven-day window and any model's week whose reset is still ahead, as the cycle reads a week. Auto-switch writes nothing: it does not change the ledger and logs no line. Where a rotator runs, its next cycle removes the block with the line above. On a host with no running rotator, the block stays in the ledger, and in profile status and profile overflow list, until its until, while auto-switch, its selection and the step's wait planning already treat it as ended. A settings file, ledger or usage.json that cannot be read leaves every block standing.

Limitations: the no-capacity ALERT's list of logins does not name a login that only a step has blocked. A rotator from an older amplihack binary that saves the ledger drops kind, and the block then stands until its until, as it did before. A step block that an older binary wrote on a credit login is left to the overflow-profile rule above, to its until, and to profile overflow clear.

The accepted-call check

A credit login's probe reads its windows and its spend state only. It cannot tell a login that accepts calls from one that declines every call, so it cannot end a step's block on a credit login before the stated reset, which for a weekly limit can be days away. The cycle therefore makes one short call on each credit login that has a block a step wrote, of any of the four kinds, while it measures and without the ledger lock. The call is claude -p with a fixed one-word prompt, one turn, no tools and no session log, under that login, through the probe's own process start and within the probe deadline (AMPLIHACK_PROFILE_USAGE_TIMEOUT_SECS). It passes no --model, so it uses the model that the login's own settings select. A session started with another model can still be declined while this call is accepted.

The call is accepted when it exits with status 0, its answer is not empty and its output holds no limit message. The block then ends in the same cycle: the login can be chosen again by the ordinary rules, and the rotate log gets one line:

2026-12-02T05:10:42Z unblock: block on credit login login-c ended; a call on it was accepted

Anything else (a limit message, an error, a refused profile directory, a missing claude, a start failure or the deadline) leaves the block standing. The check runs at most once per login and cycle, only while such a block stands, and never in a --dry-run cycle. There is no timer, interval or retry beyond the cycle the rotator already runs. Each cycle while the block stands costs one process start and one request. Cycles also start on events, such as a step's limit notice, so a burst of events while the block stands makes one call for each cycle it starts. A declined request is not expected to be billed; an accepted one is billed once, a few tokens and the cached system prompt, and ends the block, so no further call is made. A block the rotator wrote itself (a spend_limit reading or a full session window) is not read by this check.

Stopping credit use

No amplihack command puts a plan login into ~/.claude when no plan login has room, so neither overflow remove nor rotate stop stops spending on its own. To stop spending at once, turn off usage credits or lower the spend limit at https://claude.ai/settings/usage. Claude then refuses work on that login, the next probe reads spend_limit, and the rotator blocks the profile and moves away from it as described above. Ending the Claude sessions that run on the login also stops spending, but a new launch uses it again.

Rotation login identity

Automatic rotation and manual profile switch share credential-bound ownership checks. The checks cover live identification, candidate identity, duplicate claims, adoption, measurement snapshots, locked revalidation, swap completion and interrupted-swap recovery.

Evidence Role
OAuth account returned by the existing bounded credential identity reader Identifies the login used for that reading, including its organization.
Positively identified platform login Uses the existing API-key rules; an unreadable OAuth login does not become a platform login.
Expected-account record States which account a profile is meant to own. See Recorded account.
Rotate ledger and swap journal Track placement and transaction state, with sanitized full-account provenance from authorized trusted readings. A legacy account key or an inode alone cannot prove ownership.
.claude.json and its oauthAccount Display state. Cannot establish ownership, authorize movement, backfill a record or choose the ledger account.

Trusted readings are bound to validated non-secret metadata for the login file and its directory. The reader rejects symlinks and unsafe files, and validates the binding before and after the read. It does not hash credential contents or use access times. Replacement or refresh invalidates an earlier binding. Continuation requires fresh evidence that identifies the current login and satisfies the same full-account comparison; a legitimate token refresh alone is not an account change.

Account comparisons preserve account identity, including organization, and the existing legacy expected-record rules. Comparing the account key alone is insufficient. Missing fields make evidence insufficient only when the applicable ownership check needs them; supported legacy email identities do not acquire a UUID requirement.

Ownership scans distinguish claimed, unclaimed and uncertain logins. No request is sent for an excluded folder during a scan: with a record, the record alone makes it claimed; without one, it is unclaimed. The duplicate-login check still uses its local oauthAccount, read from disk. Excluded folders are never swap sources or targets, so an unclaimed one authorises nothing. An unclaimed result requires a complete scan of the relevant logins and records. A failed duplicate read, unusable record, changed dependency or exhausted budget cannot prove absence. Missing records may follow the existing adoption/backfill rules only with trusted evidence. Existing unusable records block the affected authorization.

Immediately before exchange, both logins must still identify the full accounts in the accepted measurement snapshot. Logins and material ownership dependencies are validated under the state and refresh locks. Required missing, insufficient, stale or contradictory evidence causes an actionable refusal on each manual attempt and an ALERT on each affected rotation cycle, with no login movement or ledger relabeling. Reasons are redacted and name validated profiles only. Unrelated alert deduplication is unchanged.

Refresh-lock ownership is journalled in the checking preflight phase before final identity requests. Recovery of that phase releases only the recorded locks and moves no login. Before exchange, the journal retains the authorized incoming and outgoing full identities. Recovery compares fresh credential evidence with them, including after S4 replaced the ledger. A different unrecorded incoming account cannot replace the authorized one. Legacy journals without sufficient expected-account evidence refuse conservatively.

The ledger's optional login_identity is written only by authorized swap completion or confirmed credential-based recovery. A block that fails the load-time rule in the ledger fields stops the rotator; it is never repaired silently. Missing-record backfill and cycle seeding require that full provenance; backfill also accepts the full outgoing authorization in a pending journal. A UUID-only legacy ledger cannot establish an organization. A normal observation does not upgrade it into ownership proof. Only a definite filesystem NotFound proves that another login is absent; permission and other metadata errors make scans and revalidation uncertain.

The reader reuses the existing OAuth profile endpoint, endpoint validation, response limits, redirect prohibition and five-second timeout. Reads share one bounded identity-work budget, excluding time spent measuring usage; identity checks do not refresh tokens, start Claude, use usage/reset-time guesses or add another service. There are no new flags, configuration files or identity databases. The existing AMPLIHACK_PROFILE_USAGE_API_BASE endpoint setting and its safety checks apply. Usage measurement keeps its existing refresh behavior.

A successful swap writes ledger.account from the validated incoming account and repairs display fields from trusted identity while preserving unrelated JSON keys and file modes. A later session rewrite cannot change ownership or ledger identity, during or after recovery grace.

These rules apply to the rotation/switch paths listed above. Standalone profile login, general display warnings and other auto-switch callers retain their separately documented behavior.

Login directory rule

An identity read and a token refresh use a login only when its directory is a real directory owned by you that no other user can write. The one rule governs every identity read, through stamp() in rotate/login_identity.rs (the rotate cycle and its swap, recovery and revalidation, the dry run, profile seed-record and profile usage), and every refresh made by a direct usage read, through dir_private() in usage_direct.rs (rotate measurement and profile usage). Issue #1962 widened it for all of these callers, not only for seeding: before, any group write bit was refused. This is a change to which credential directories are trusted. The reason is the cause on host-a.

Directory Result
No group or other write bit, such as mode 700 or 755 Accepted
World-writable Refused
Group-writable, in your own private group (your primary group, named like your user, with no listed members), with no POSIX access ACL. This is the mode 775 that a umask of 002 leaves Accepted
Group-writable, in a shared group, or the group lookup failed Refused
Group-writable with an access ACL, or the ACL cannot be checked Refused

The ACL is checked only when the group write bit is set: an ACL mask that lets anyone write always sets that bit. A filesystem with no ACL support counts as having no ACL.

A refused directory gives an identity read the cause directory not private, and a refresh the reason refresh refused. Changing the directory's group or mode after a reading invalidates that reading.

The private-group check sees only a group's listed members. It does not notice another user whose primary group is the same group. If your system has one, run chmod 700 ~/.claude.

This rule applies to the directory only. A login file stays refused when group or others can write it, whatever its group. The swap's ~/.claude check and the shared session checks do not read ACLs.

Cause on host-a (issue #1962)

1.2.99 refused every rotate cycle on host-a with ~/.claude could not be read and the identity alert. The cause was the directory mode, not an expired token, a 401 or a 429.

  • On host-a the umask is 002. ~/.claude is mode 775, owned by you:you, where you is the user's own private group (gid 1000, no listed members) and the directory has no access ACL.
  • 1.2.99 refused any login directory with mode & 0o022 != 0. The identity read stopped in stamp() before any request was sent. A live refresh would have been refused by dir_private() in the same way.
  • That matches the host-a log: the refusal and the alert, with no refresh, 401, 429 or expiry line. With an expired token, 1.2.99 also logs refresh: expired login in ~/.claude not refreshed (refresh refused). Host-a's log has no such line, so the token was still valid and the directory check alone explains the refusal. profile verify and 1.2.97 do not apply this check, which is why they read the same login.

The reproduction is crates/amplihack-cli/tests/issue_1962_host_a_cause.rs. It uses fake logins and a loopback endpoint, with ~/.claude set to host-a's mode. Run against the 1.2.99 release binary (AMPLIHACK_TEST_BINARY), the two 775 tests fail with host-a's lines, and the fake endpoint sees requests for the other profiles only, none for the live login. The 700 control passes. Against this build all three pass.

The fix is the private-group case of the rule above. chmod 700 ~/.claude also clears the refusal on 1.2.99.

The acceptance dry run on host-a (#1962 item 5) is tracked in issue #1988. Host-a stays on 1.2.97 until that run names the live login with no identity alert.

Rotate live profile

The live profile is the one whose login is in ~/.claude. The ledger may name it, but authorization to return that login to a profile requires trusted identity and the applicable ownership checks. ~/.claude.json cannot confirm or contradict the owner.

Evidence Result
The live login is missing or unsafe No swap; report the login/file-safety failure. Never fill an empty ~/.claude.
A pending journal or hand-change suspicion is unresolved Finish authorized recovery or report the refusal; no new swap.
A usable ledger names a live profile Retain that placement label and validate the login against applicable expected ownership evidence before movement.
No usable ledger; trusted evidence establishes a unique login-less owner Use that profile, subject to the same ownership and structural checks.
No usable ledger; a prototype ledger names a profile Accept only with the existing prototype trust/placement checks and trusted ownership evidence. Its name alone cannot establish identity.
More than one owner, or required evidence is uncertain or conflicting Alert and move nothing; do not relabel the ledger.
A complete trusted scan establishes no owner Adopt only as part of an authorized swap.

Adoption creates default-original, default-original-2 and so on under the existing lock. Its display data and ownership record come from the trusted outgoing identity; a session block cannot claim an empty profile. No credentials are copied. Failure before exchange leaves the login in place. An unfinished empty adoption is not evidence of ownership; retry must establish ownership again. Existing profile creation, journal and cleanup rules still apply.

Rotate excluded live profile

When the login in ~/.claude belongs to a profile in the auto-switch exclude list, the rotator moves off it without probing or refreshing it. An excluded login is often shared with another host, and a token refresh from this host would rotate its refresh token and sign that host out (#2218).

The exclude list is read once per cycle, under the rotate lock and before any recovery, refresh or identity read. A cycle that cannot read the list treats every profile as excluded and pauses; see Unreadable exclude list. Call the excluded live profile C. The rotator identifies C from local files only, as described under Local proof of an excluded live login. In every cycle that finds C live, the rotator:

  • sends no request of any kind with C's token: no usage request, no token refresh and no GET /api/oauth/profile identity read, on the first cycle and every later one;
  • starts no claude for C;
  • skips the one refresh of an expired live login, and, when C's token has expired, logs refresh: live profile C is excluded; token not refreshed;
  • writes nothing to C's credential files, except the write-back of a move off C;
  • records no reading for C in the usage history, usage.json, the capacity file, the ledger's swapped_away list or the no-room record.

The swap protections of #1845 and #1886 still need a trusted reading of the login in ~/.claude before any move. For an excluded live login that reading comes from local files instead of the server. The incoming target is still read over the network, as for any swap.

Local proof of an excluded live login

Once per cycle, after the rotate lock is taken and auto-switch recovery has run, and before swap recovery, the expired-login refresh, hand-change recovery and the snapshot, the rotator decides from local files alone which logins it must never send to the server. It reads no token and sends no request to decide.

The login in ~/.claude is taken to be the excluded profile C by the first of these rules that matches:

Rule Condition Match
1 The rotate ledger's live field names C, and C is in the exclude list. This rule is enough on its own. ledger
2 The oauthAccount in ~/.claude.json matches C's recorded account by full account identity, organisation included. local account
3 ~/.claude/.credentials.json is byte for byte the same as <root>/C/.credentials.json. same bytes

Rules 2 and 3 apply whatever profile the ledger names, because a claude login or a copy made by hand leaves the ledger naming the profile that was live before it. There is one exception to rule 2. After a swap off C, sessions still running on C keep writing C's account into ~/.claude.json. Rule 2 is therefore skipped while all of these hold:

  • the ledger's live names a profile that is not excluded;
  • the ledger has no hand_suspect;
  • the change time of ~/.claude/.credentials.json, read by lstat, is no later than the ledger's live_login_at — when the swap put that login there, read by lstat right after the exchange in s1, while the swap still holds Claude's refresh locks — and that time is not in the future. A ledger without live_login_at falls back to swapped_at. That is a ledger written before the field existed, or by an older rotator, or by a swap that recovery finished. swapped_at is the swap's start time and the move that installs the login lands after it, so on its own it reads the swap's own login as written since the swap whenever the swap crossed a second boundary, and the exception would almost never apply.

Recovery records no live_login_at, and clears one an earlier swap left. It runs some time after the exchange. An outgoing move that failed releases the refresh locks with the incoming login already in ~/.claude, and a crash leaves the time since the exchange unknown. A token refresh or a claude login may therefore already have written the file, and a change time read during recovery would take that write for the install. After a recovered swap rule 2 applies as it did before live_login_at existed: whenever the login's change time is later than the swap's start.

Any write to the login file after the swap, by a token refresh or a claude login, ends the exception, and rule 2 applies again. Change times are compared in whole seconds. A write in the same second as the exchange has a change time no later than live_login_at, so the exception still reads that file as untouched. A process that ignores Claude's refresh lock and writes the file between the exchange and the lstat is missed in the same way. Claude's own refresh takes the lock and cannot write until the swap has recorded the time and released it. swapped_at has the same one-second limit. Rule 3 is never skipped. Outside the exception, a stale ~/.claude.json that still names C also marks ~/.claude: its identity is then taken from local files and the check fails closed. A match by rule 2 alone is never proof enough to write ~/.claude back into C's folder, so nothing is moved and the cycle raises the ALERT shown under Write-back into an excluded folder until the file is corrected or the ledger names C.

An e-mail or a prefix alone never matches in rule 2. ~/.claude.json is read without following a symlink, up to the usual size limit, and must be owned by you and not writable by group or other users. A file that fails any of these checks counts as missing. Any read error makes that rule give no match; it never sends a request in its place.

Every profile folder named in the exclude list is also marked, for the whole cycle, so that no identity read is sent for it. When a rule matches, ~/.claude is marked as well. For a marked folder the identity of the login is taken from its local account (.claude.json) in place of GET /api/oauth/profile. When no local account is found, the identity read fails with unavailable and no request is sent. The other checks a trusted reading needs still apply: the shared identity-work budget, the login directory rule, the login kind, and the metadata of .credentials.json before and after the read. A /login, or any other change to that file between the proof and its use, gives login changed during read and nothing is moved.

Paths are compared both as given and after resolving symlinks, so a profile root reached through a symlinked parent folder is still marked. profile seed-record and the swap recovery run when the rotator starts use the same marked set. Swap recovery also marks the folder that holds the outgoing login of an interrupted swap when the outgoing profile is excluded, wherever the swap left it.

The marked set is rebuilt at the start of every cycle from parsed profile names and ~/.claude only. A change to exclude made while a cycle runs takes effect on the next cycle.

rotate status uses the same rules to name the live profile. When the ledger has no live field and a rule names C, the status shows C as live and sends no request.

Moving off an excluded live profile

The decision treats C as a live login that must be left in this cycle:

Case Outcome
A candidate is eligible Swap to the first-ranked eligible candidate by the target rule, reason=threshold or plan-room, on the first cycle. C counts as having no room, as an exhausted live login does, so every eligible candidate qualifies. Failed-probe damping, --hold, the trusted-identity stop and the home-key stay do not apply.
No candidate is eligible The overflow rules choose a target as they do for an exhausted live login.
No move is possible ALERT excluded-live. C stays in ~/.claude, unprobed and unrefreshed. The cycle records alerted, which is not capacity by the rotator capacity rule, and the ALERT is never advisory. No retry, wait or loop is added: the next normal cycle decides again. ~/.claude is never left empty.

C's reading is never counted as room: it is not capacity for a stay, for the capacity file or for the usage-limit wait. After the swap, C is a profile in its own folder again and is skipped as excluded by every later cycle, so the rotator never swaps it back in, however much room C may have.

A swap off C writes:

2026-11-10T08:00:05Z cycle live=shared shared:excluded (not probed) review:s=5%,w=10% work:s=20%,w=30%
2026-11-10T08:00:06Z note: live profile shared is excluded; moving off it
2026-11-10T08:00:06Z swap shared->review live excluded (not probed) target s=5% w=10% reason=threshold

With no eligible candidate:

2026-11-10T08:00:05Z cycle live=shared shared:excluded (not probed)
2026-11-10T08:00:05Z ALERT: live profile shared is excluded; no eligible candidate

The ALERT is written once per key, like any other.

Write-back into an excluded folder

A normal swap moves the outgoing login from ~/.claude back into its profile folder. For C this move is the only write the rotator ever makes to C's credentials. It is the existing journalled exchange of login files, with no refresh and no request. Without it, a token that a session on this host refreshed would be lost and C's stored copy would go stale.

The move into <root>/C/ is made only when one of these holds:

  • the match came from rule 1 (ledger), no hand change is suspected, and ~/.claude.json agrees with C's record;
  • ~/.claude/.credentials.json is already byte for byte the same as <root>/C/.credentials.json (rule 3, or rule 1 with identical files).

In every other case, for example a match from rule 2 alone or any match while a hand change is suspected, nothing is moved and C's folder is left as it is. The cycle writes, once per key:

ALERT: live profile C is excluded; not moved, as only ~/.claude.json names it

Such a match is not written to the ledger as the live profile, so a later cycle cannot take it for a rule 1 match. While ~/.claude is marked, hand-change recovery and the seeding of a recorded account do not run either: both would act on the local account alone. This stops a stale ~/.claude.json after a manual /login from moving another account's login into C's folder, the slot mix-up that #1845 and #1886 fixed. The ALERT clears once the ledger names the live login again, for example after profile switch or a fresh profile login.

Limits of the rule

  • An expired access token does not stop the move. No identity read is sent for C, so the login is moved back to C's folder unrefreshed. The rotator never refreshes the token to get the login moved.
  • The local proof trusts the ledger, ~/.claude.json and the stored record. A login file copied by hand into ~/.claude, with a ledger that names C, is taken to be C's. The write-back rule above stops it being copied into C's folder unless ~/.claude.json also agrees. Run profile verify after any hand copy.
  • When ~/.claude.json gives no account and the login matches no excluded folder byte for byte, and the ledger does not name C, the rotator cannot tell that the login is excluded. It is treated as any other live login. Knowing which host owns a login without these files is the job of the lease design in #1019.
  • When the ledger names a live profile that is not excluded, no hand change is suspected, and only ~/.claude.json points at the excluded profile C, no rule matches. Rule 1 does not name C, and rules 2 and 3 apply only when the ledger has no live field or a hand change is suspected. The login is treated as the profile the ledger names, and may be probed or refreshed as that profile. Once a hand change is suspected, rule 2 or 3 applies on the next cycle.
  • When <root>/.auto-switch cannot be read or is unsafe, the cycle pauses and sends nothing; see Unreadable exclude list.
  • A pin that holds rotation on C, set before C was excluded, still holds. The held cycles do not probe its spend: see Pin and overflow.

--dry-run prints the same decision as would swap: or would alert:. Like a real cycle, it sends no request with C's token and writes nothing. When <root>/.auto-switch cannot be read or is unsafe it stops where a real cycle pauses, before measuring, and prints would alert: auto-switch config unreadable or unsafe; rotation paused, no profile probed.

Unreadable exclude list

An exclude list is only as trustworthy as whoever can write it, and a writer can remove an entry as easily as add one. Rewriting exclude=shared to exclude= would get shared probed and refreshed, and that refresh signs out the other hosts that share the login. So the list is read from <root>/.auto-switch only when it is a regular file owned by you and not writable by group or others (group write by your own private group is allowed, as elsewhere). A private file of yours that parses but is invalid for its other settings, such as an unknown kind, still has its list applied, since only you could have written it; those other settings, such as overflow profiles, are ignored, and the cycle logs once:

warning: auto-switch config invalid; exclude list applied, other settings ignored

When the file exists but cannot be read, does not parse, or is unsafe (owned by another user, or writable by group or others), the rotator cannot tell which logins are excluded, so the cycle fails closed: every profile is treated as excluded, so recovery, the live refresh and the identity checks send nothing, and the cycle stops before measuring. It logs:

warning: auto-switch config unreadable or unsafe; every profile treated as excluded, none probed or refreshed
ALERT: auto-switch config unreadable or unsafe; rotation paused, no profile probed

Rotation resumes from the first cycle that reads the file. To fix the file:

  • When it is a private file of yours that parses but is invalid for its other settings, run amplihack profile auto-switch on or off. They rewrite it with mode 0600 and the defaults for every other setting, and keep its exclude list, so the logins it excluded stay excluded.
  • When it is owned by another user (for example one left by sudo amplihack profile auto-switch …), is a symlink, or is not a regular file, no command replaces it, and every command that writes it refuses with AutoSwitchExcludeAtRisk, --exclude or not. While it is there every profile counts as excluded. Do not delete it, which leaves no exclusions. Make it a regular file of yours holding the exclude= line you intend instead (check the line: another user could have edited it): sudo chown "$USER" <root>/.auto-switch for a foreign owner, or, for a symlink, copy its target over it (cp --remove-destination "$(readlink -f <root>/.auto-switch)" <root>/.auto-switch). Then run on --exclude … or off --exclude … as below.
  • When it does not parse, or it is your file but writable by group or others, its exclude list is unknown: whoever else can write it could have removed an entry. on, off, threshold, exclude, overflow add and overflow remove refuse it with AutoSwitchExcludeAtRisk:
error: auto-switch settings: auto-switch config does not parse or others can write it, so its exclude list is unknown; not changed. Run `amplihack profile auto-switch on --exclude NAME,...` or `off --exclude NAME,...` naming the logins that must stay excluded (`--exclude ''` for none)
hint: do not remove <root>/.auto-switch: that drops its exclude list, and the rotator would probe and refresh the logins it excluded; see "Unreadable exclude list" in docs/reference/profile-command.md

Run amplihack profile auto-switch on --exclude NAME,... to turn rotation on, or amplihack profile auto-switch off --exclude NAME,... to leave it off, with the logins that must stay excluded (--exclude '' names an empty list on purpose). Do not remove the file and run a bare on or off: that writes an empty list just the same. Writing an empty list by mistake would let the next cycle probe and refresh those logins, which signs out the other hosts that share them.

profile usage and profile verify print the same warning on stderr and read no profile, as described in their sections.

Every other reader of the exclude list follows the same rule: in-session auto-switch swaps, its re-run and takeover checks, the capacity figures and profile auto-switch status, whose exclude: line shows the list in force. For a corrupt or unsafe file their other settings are still the defaults, but the exclude list is the file's when it is a private file of yours that parses, and every profile otherwise. With AMPLIHACK_CLAUDE_AUTO_SWITCH=1 and a file that does not parse or is unsafe, auto-switch is on but every profile is excluded, so it swaps nothing. If the list is unknown and the profile root cannot be listed either, "every profile" is unknown, and it is never treated as an empty list: profile usage, profile verify and the rotate cycle fail with the error, the live refresh is skipped, and in-session auto-switch counts as off.

Treating an unsafe file as unreadable is a trade-off. Whoever can write it cannot un-exclude a login, because nothing they write is applied, but they can stop rotation by making the file unsafe or unparseable: every profile is then excluded, a denial of service. That is the only power they get. Treat the unreadable or unsafe warning as a sign that the file needs fixing, and possibly that someone else can write it.

Rotate candidates

A profile is a candidate unless any of these holds, checked in this order. Every reason but live is logged as a skip: line: by watch only when the set of skipped profiles changes, and by the one-shot command on every run.

Skip reason Condition
live It is the live profile. A live profile in the exclude list is handled as in Rotate excluded live profile.
directory refused The profile directory fails the ownership and mode check: it is a symlink, not a directory, not owned by you, or open to group or other users. A profile in the auto-switch exclude list is skipped as excluded instead. While a plan profile has this reason, the rotator does not move onto an overflow profile (see Overflow decision).
no login <root>/<name>/.credentials.json is missing, a symlink, not a regular file, not owned by you, readable by other users, or has more than one link.
excluded It is in the auto-switch exclude list. It is not probed and no request is sent with its token. Its .credentials.json is read only for the byte comparison of rule 3, and written only by the write-back. It never reaches the no account check or the unbound set.
session running A running Claude or amplihack executable has CLAUDE_CONFIG_DIR=<root>/<name>, or a process with that setting is named by the profile's sessions/<pid>.json (the same /proc scan auto-switch uses), or an unreadable Claude or amplihack executable names the profile in its arguments (see Leases). Two kinds of process are not sessions and never make a profile session running: a child that amplihack starts for a usage probe, a control request or an accepted-call check, which has AMPLIHACK_PROFILE_PROBE_CHILD=1 in its environment; and an amplihack profile usage, statusline, list or show command, whether or not its environment can be read. A launcher, an unfamiliar command or other non-interactive work with that setting still makes the profile session running. One unreadable process never skips the other profiles. Only if the process table cannot be used at all is every profile skipped, and skip: cannot see running sessions; no candidates is logged once: there is no /proc (every system but Linux), /proc/self/environ or the /proc listing cannot be read, or the profile root cannot be resolved.
leased Its login is on loan to another profile's session in the auto-switch ledger.
hosting Its directory hosts another account's login in the auto-switch ledger.
parked <root>/.auto-switch.d/parked/<name> exists.
no account Its login has no usable trusted account evidence for the required ownership check. Session display data cannot supply it. The cycle also writes ALERT: trusted login identity unavailable for profile <name>: <cause>, with the cause. The login is not a target this cycle and is counted as unknown (identity unavailable) in the no-target line.

Rotate swap

L is ~/.claude/.credentials.json, T is <root>/<to>/.credentials.json and S is <root>/<from>/.credentials.json, where <from> is the live profile (or the adopted one).

Before anything is written, every check below must pass; otherwise the swap fails with RotateRefused and nothing changes:

  • the profile root is private (as for auto-switch state writes); $HOME is absolute, a directory rather than a symlink, and owned by you; ~/.claude is owned by you and not writable by others (group write is accepted only for your own private group, as in the login directory rule); both profile directories pass the usual directory check;
  • L and T are regular files owned by you, with no group or other mode bits and exactly one link (metadata checked with lstat; trusted identity is read separately by the bounded reader);
  • S does not exist;
  • trusted outgoing and incoming identities are bound to the logins being exchanged; their full accounts satisfy applicable expected records, duplicate claims and placement checks;
  • required ownership scans are complete. An unreadable expected record or duplicate login is uncertainty and blocks movement; missing records can follow the existing trusted adoption/backfill rules;
  • the incoming login's organisation, read with the same identity reads, on both reads, is compared with the outgoing login's: a swap between two known and different organisations is made only when the target rule allowed the crossing (the live login has no room now, or is an overflow profile), and is otherwise refused with ALERT: swap refused: the incoming login is in a different organisation from the live login. When either organisation is unknown, the swap goes ahead. A crossing that goes ahead writes the affinity: warning;
  • these bindings and material dependencies are revalidated under the swap locks immediately before exchange. Refresh requires fresh matching evidence; an earlier inode or account key is insufficient;
  • display repairs use the trusted account, preserving unrelated fields and file modes. A display file that cannot be safely updated refuses before login movement. Its existing account never authorizes a move;
  • ~/.claude and the profile root are on the same device;
  • the platform has an atomic exchange. Only Linux (renameat2(RENAME_EXCHANGE)) qualifies. macOS has renamex_np, but Claude keeps macOS logins in the Keychain, so there is no ~/.claude/.credentials.json to exchange and a cycle stops earlier with the no-login ALERT. Any system other than Linux, macOS included if a credentials file is there, is refused with atomic exchange is not supported here.

Then the steps run in order. The step names are the phase values in the journal.

Step Action
j0 Write journal.json with from, to, adopt, the inode numbers of L (live_ino) and T (target_ino), and $HOME. Then take Claude's refresh locks (.oauth_refresh.lock, directories made with mkdir, as auto-switch does) in ~/.claude and <root>/<to>, recording each acquired inode (home_lock_ino, to_lock_ino). A lock held by someone else is never broken. Before s1, validate fresh bound identities and material ownership dependencies under these locks; uncertainty prevents the exchange.
s1 Atomically exchange T and L. ~/.claude now holds the incoming login; <root>/<to> holds the outgoing one.
s2 Rename the outgoing login from <root>/<to> to S, refusing to replace an existing file. Release the refresh locks: each is removed with rmdir only if its inode is the one recorded.
s3 Replace the oauthAccount display block in $HOME/.claude.json from the validated incoming identity, keeping every other key and the file's mode.
s4 Write the ledger: live=<to>, previous=<from>, account from the validated incoming account key, since, swapped_at and live_login_at (the change time of ~/.claude/.credentials.json, read by lstat right after the s1 exchange moved it in; absent when it cannot be stat'd, and absent after recovery, see Local proof of an excluded live login). Clear any ALERT key.
Delete journal.json.
Write the recorded account, if one is due: for an adopted login, the outgoing account for the new default-original[-N] profile, only when no other profile holds that account and organization or has it recorded (otherwise a record left under that name is deleted); for <from> with no record, the trusted outgoing account, only when the existing ledger/provenance and compatibility checks establish ownership and a complete trusted scan finds no other claim. Session JSON cannot supply missing ownership proof. For <from>, the record is read again first, and a usable one is never overwritten. Nothing is recorded for <to>. A failure prints warning: the recorded account for profile '<name>' was not saved: <reason> and the swap still succeeds.

A swap that recovery finishes writes no record.

The identity reader uses the logins for bounded identity requests; movement uses only the exchange and rename, never copy-and-delete. Each parent directory is synced after each rename. At every point each login is in exactly one place, and ~/.claude always has a login.

If the exchange fails with EXDEV, EINVAL or ENOSYS, the swap fails with RotateRefused (atomic exchange is not supported here), the refresh locks are released and the journal is removed; nothing was moved. Any other error from the exchange also fails with RotateRefused, after the same clean-up. The exchange never produces RotateUnsupported. There is no copy-and-delete fallback.

Rotate recovery

Recovery runs under the lock at the start of every non-dry-run rotate, start and cycle, before anything else is decided. --dry-run never runs it. Recovery keeps the existing journal schema and inode-placement rules, and reconstructs fresh login-bound identity and applicable expected-record evidence before any further movement or ledger settlement. It never deletes or overwrites a login.

Recovery selects the transaction action by where the recorded inodes are, found with lstat. Every action that moves a login or settles ledger identity also requires fresh trusted authorization. The journal's phase is a hint for the log and for status; it never decides. This matters most for the commonest crash point, just after the exchange and before the journal is rewritten as s1, where the journal still says j0 but the logins have already moved.

L and T are not tested in ~/.claude. Claude may refresh the token in ~/.claude at any time, which replaces the file there with a new inode, so neither recorded inode can be expected in ~/.claude after the exchange. A regular file alone is insufficient: fresh bound identity must establish the account currently there, including after a token refresh.

Where the logins are (any phase) Action Log line
No journal Nothing.
target_ino is at <root>/<to>/.credentials.json, S does not exist, and ~/.claude/.credentials.json is a regular file The exchange did not happen. Roll back: release the recorded refresh locks, then delete the journal. recovery: rolled back an interrupted swap work->spare
live_ino is at <root>/<to>/.credentials.json, S does not exist, and ~/.claude/.credentials.json is a regular file The exchange happened; s2 did not. Roll forward: run s2, s3 and s4, then delete the journal. recovery: finished an interrupted swap work->spare
live_ino is at S, nothing is at <root>/<to>/.credentials.json, and ~/.claude/.credentials.json is a regular file s2 happened. Roll forward: release the recorded refresh locks, run s3 and s4, then delete the journal. s3 and s4 are safe to repeat. recovery: finished an interrupted swap work->spare
Required trusted evidence is unavailable, insufficient, changed or conflicting Retain the unresolved journal, leave login placement and ledger identity unchanged, and safely release operation-owned refresh locks. Retry requires fresh evidence; report the identity refusal on each affected attempt. Actionable identity ALERT; no swap.
Inconsistent login placement or a failed directory check, with a valid journal for the current $HOME Safely release the recorded operation-owned refresh locks, then mark the journal inconsistent. ALERT: rotate recovery is inconsistent: <reason>; no swap until it is resolved
A home that differs from $HOME Leave the journal, logins and refresh locks untouched for a run with the correct $HOME. ALERT: rotate recovery is inconsistent: <reason>; no swap until it is resolved
An unreadable or invalid journal, including an invalid name or unknown version Refuse recovery without acting on the untrusted journal; leave it and the refresh locks for resolution. Journal error; no swap.

Releasing a refresh lock means removing <dir>/.oauth_refresh.lock with rmdir only when its inode equals the recorded home_lock_ino or to_lock_ino. A lock with another inode belongs to Claude and is left alone. If the process stopped after making a lock but before recording its inode, that lock is not released; see Recovery for the manual step.

inconsistent is sticky. While the journal says so, no swap happens, the one-shot command exits with RotateInconsistent, and watch writes the ALERT (once) and keeps running. A person resolves it as described in Recovery and deletes the journal.

If auto-switch recovery reports an inconsistent state, the cycle writes ALERT: auto-switch recovery is inconsistent; no swap and does not swap.

The journal's home is only compared with $HOME, and its inode numbers are only compared with lstat results; neither is ever used as a path.

Rotate hand-change recovery

A manual /login in ~/.claude replaces whatever login was there; the profile that login belonged to is left with no login. The rotate ledger then names a profile L whose login is no longer the one in ~/.claude.

Hand-change recovery runs under the lock in every non-dry-run rotate, start and cycle, after rotate recovery and before the live profile is identified. profile switch does not run it: a switch refuses while a suspicion is open (see Rotate switch) and leaves recovery to the next cycle.

Recovery identifies a login by what its credential returns, never by .claude.json. Running Claude sessions rewrite ~/.claude.json from the account they hold in memory, so for some minutes after a swap that file can still name the previous account (#1886). No .claude.json file is read for any recovery decision; the ledger's account field and the oauthAccount blocks are used for display only.

Recovery moves at most one login, by rename, and only after two matching readings on separate cycles. It never moves a login that is a profile's only login, and it never opens, copies or deletes a credentials file itself.

Credential identity

A login's identity reading is one GET /api/oauth/profile to Anthropic's OAuth profile endpoint, the endpoint Claude Code's /status reads, made with that login's own OAuth token. The server answers with the account and organization the token belongs to; the rotator keeps account.uuid, account.email (lower-cased) and organization.uuid, each at most 320 bytes and free of control characters. An answer with neither a uuid nor an e-mail cannot be used and gives the cause unparseable.

Two readings are one account when they report the same account uuid in the same organization (by e-mail only when neither reports a uuid): one user in two organizations is two accounts. ~/.claude.json is not compared with the ledger; its account block is display state. The identity of a login is therefore what the server says about its token, not what any local file says.

Recovery does not use any of these to identify a login, as the owner decided on #1886 on 3 November:

  • .claude.json, which running sessions rewrite from memory;
  • claude auth status, which reads the config folder's .claude.json and answers even with the network blocked;
  • usage reset times. Earlier builds of this fix compared the reset times of the usage windows, but accounts created together share them: on 3 November login-ao and login-an both reset at 14:40Z (session) and 2026-11-06T05:00Z (week). Two such accounts read as one, and every swap onto one of them ended in the only-login ALERT.

Identity reads differ from the reads profile usage makes:

  • token refresh is off, so an identity read never writes a credentials file and never takes .oauth_refresh.lock; a token at or past its expiresAt is not sent and gives the cause token expired;
  • each read has a 5-second timeout, and all reads in one cycle share a 30-second identity-work limit, excluding usage measurement; reads not started when the limit runs out are not made. A read started just before the limit may still take its full 5 seconds. A read that fails with transport spends its measured duration up to that 5-second bound. Any excess time is excluded from the allowance. Rotation ownership checks share the existing bounded assessment budget rather than starting unbounded duplicate scans. Final rechecks retain their existing limits (see Checks before the move);
  • the endpoint base comes from the same setting as the direct read (AMPLIHACK_PROFILE_USAGE_API_BASE); an endpoint that fails the direct read's checks means no request is sent;
  • passive readings, the usage endpoint and the claude -p /usage fallback are never used, and no child process is started.

Raw identity responses and file bindings remain in memory. Only sanitized account fields are retained in the existing ledger/journal; no token or raw response is stored. Swap completion uses the validated incoming account for the existing ledger key and sanitized display fields; authorized adoption/backfill uses the trusted outgoing identity for the outgoing profile's ownership record. Routine logs print no account identifiers or e-mails. Only profile verify prints an e-mail, on request. The token goes only in the request's Authorization header.

Identity read causes

A failed identity read has one fixed cause. The rotate log and the dry run print it, and so does profile switch when the read of the login in ~/.claude fails. A cause never holds a token, an account or server text.

Cause When
token expired The token is at or past its expiresAt, and no refresh replaced it.
http 401, http 403, http 429 The endpoint answered with that status.
http 3xx, http 4xx, http 5xx Any other status of that class.
timeout No answer within the 5-second timeout.
transport The connection or TLS failed, the server closed it, or the endpoint setting is unusable, so nothing was sent.
unparseable The body is too large, is not a JSON object, or names no account.
no oauth token The login file says there is no login ({}, or no accessToken).
unreadable credentials The login file is not JSON, is not the expected shape, or holds a token the read rejects.
directory not private The directory fails the login directory rule.
login file not trusted The login file is missing where a login is required, is a symlink or not a regular file, belongs to another owner, can be written by group or others, has more than one link, or is on a different device from its directory. A seeding scan treats a definitely missing login in another profile as no login, not as this cause.
login changed during read The file or directory changed between the checks before and after the read.
identity read budget used up The cycle's 30-second identity limit ran out before this read started.
Identity read budget

Each cycle has one identity-read allowance of 30 seconds. It is a time allowance, not a count of reads: a read attempted after the allowance is spent is declined with identity read budget used up.

  • What spends it. Every bound identity read that the cycle makes with its allowance, wherever in the cycle it falls: the checks of a login's file and account before they are trusted, whether they come from recovery, seeding, the revalidation snapshot or a swap. A read checks the allowance before it starts, so one that has started is not cut short by it. A read that fails with transport spends the lesser of its measured duration and its existing 5-second bound. Earlier work remains charged, and later profiles can be read while allowance remains. The hand-change assessment applies this same charge to its own time allowance, so excess transport time cannot stop its later profile reads.
  • What does not spend it. The usage measurement and its re-reads, including stale live reading; re-read and reread: <name>. The time they take is taken out of the allowance, so a cycle that logs re-reads has the same allowance as one that does not. For logins read through the identity endpoint, a missing OAuth token is detected locally before an identity read is admitted, even when the allowance is spent. It makes no identity request. Excluded logins retain their local-only account checks: an empty OAuth block does not prevent moving off an excluded live login with valid local identity evidence. Token presence is observed separately for transition reporting.
  • What refills it. The start of the next cycle. Nothing else does: there is no timer, retry or background refill. A dry run starts with a full allowance in the same way.
  • Who else can spend it. Nothing outside the cycle. The allowance belongs to the rotator process, so profile usage run by another session cannot spend it, and reading the usage table cannot stop a swap.
  • Swaps the live login needs. A swap away from the live login whose reason is threshold, failed-probe, projected, overflow-in or overflow-out is not subject to the allowance. The overflow moves are included because a blocked overflow login cannot spend, and staying on credit while a plan login has room spends credit for nothing. Once the cycle has decided on such a swap, the revalidation snapshot and the reads of the swap are not refused with identity read budget used up. There is no reserve to draw on and no count: the allowance is set aside for that swap until the next cycle begins. Each read keeps its 5-second timeout, and every other check still applies, including the bound-identity checks, swap authorization and the scan of other profiles. A swap for any other reason (upgrade, plan-room) is rejected when the allowance is spent, as before, and the ledger records the rejection.

For example, the live login is at 91% with --session-at 90, and the allowance is spent by the reads at the start of the cycle. The swap goes ahead:

2026-11-24T20:03:17Z cycle live=work work:s=91%,w=14% spare:s=71%,w=25%
2026-11-24T20:03:18Z swap work->spare live s=91% w=14% target s=71% w=25% reason=threshold

An optional swap (upgrade or plan-room) declined for this allowance writes a note with its selected reason and target:

note: swap declined reason=<reason> target=<profile>: swap refused: trusted login identity unavailable: identity read budget used up

The cycle stays, and the ledger still records the declined swap.

The ALERT for the live login is:

ALERT: trusted login identity unavailable: <cause>

These identity ALERTs repeat on every affected cycle, with that cycle's cause, except for no oauth token. The candidate form is ALERT: trusted login identity unavailable for profile <name>: <cause>, and the missing-token form is the same for live and candidate profiles. The missing-token state produces one ALERT when first observed. A trusted, unchanged credentials file with a token then produces one note: OAuth token present for profile <name> line. Stable cycles write neither transition again. Removing a candidate, or finding missing, unreadable or malformed credentials, does not establish recovery. These transitions are retained for the running rotator's lifetime. The unreadable-ledger ALERT and the same-account ALERT still repeat on each affected cycle.

profile switch refuses with the same text when the read of the login in ~/.claude fails. Swap authorization does too, in profile switch and after ALERT: swap refused: in a cycle, when a read of either login or a read in its scan of other profiles fails. Other identity refusals have no cause and keep their fixed text. These are a profile root that cannot be listed, a login or record that changed before the exchange, and a refresh lock that recovery does not recognize:

trusted login identity unavailable or changed; retry after checking profile verify

Swap authorization's specific refusals also stay as they are, except that trusted login identity: outgoing ownership is not established; run: amplihack profile seed-record <name> now names the command.

An expired live login

Because an identity read never refreshes, a login in ~/.claude whose token is at or past its expiresAt could not otherwise be identified, and with no running Claude session to refresh it every cycle would raise the trusted-identity ALERT and move nothing. So each rotate cycle and profile switch NAME, after swap recovery and before hand-change recovery or any identity read, refreshes that login once when its token has expired, as the direct read refreshes a profile's login, under ~/.claude/.oauth_refresh.lock.

The refresh does not depend on the rotate ledger or the lease view, so an unreadable ledger or a lease view that bars the live profile does not stop it. That exception covers ~/.claude only: a profile folder the lease view bars is never refreshed. These still refuse the refresh:

Refusal Reason in the log
A rule under Local proof of an excluded live login names an excluded profile as the live login none: the line is refresh: live profile <name> is excluded; token not refreshed. See Rotate excluded live profile.
A swap journal exists refresh busy
Another process holds the refresh lock refresh busy
The directory fails the login directory rule refresh refused

A token that has not expired is left alone, and nothing is logged for it; Claude refreshes it. The log says refresh: expired login in ~/.claude refreshed; identity read again, or refresh: expired login in ~/.claude not refreshed (<reason>) with one of the direct read's reasons.

The refresh is not identity evidence. The cycle reads the identity of the refreshed credential afresh, and only that reading can let a login move. A refresh that fails, or a refreshed login whose identity cannot be read or conflicts with its record, still gives the ALERT and moves nothing.

--dry-run never refreshes. For an expired live login it prints would refresh: expired login in ~/.claude and then reports the cause token expired, which a real cycle's refresh might have cleared.

A refresh replaces the login's token on disk. A running session may still hold the old refresh token in memory.

Unreadable-ledger stop

When the rotate ledger exists but cannot be read, the cycle still refreshes an expired live login and reads its identity, then stops:

ALERT: rotate ledger unreadable[ (<field>)]; live identity: <readable|cause>; nothing moved, no record written

(<field>) appears when the ledger was read and parsed but a field was refused. It is one of these fixed texts, and never a value from the file: unknown version, invalid profile name, invalid account or alert, invalid overflow field, invalid no_room, invalid hand-change field or invalid login_identity. A ledger that cannot be read, is not a private file or is not valid JSON gives the line without it.

The cycle ends as alerted, seeds no record, moves no login and leaves the ledger file unchanged. With no ledger to hold an ALERT key, the line is written on every cycle while the ledger stays unreadable. --dry-run prints the same text after would alert:, and profile switch refuses with it.

A ledger whose login_identity fails the load-time rule under Account identity is one case of this stop, written as rotate ledger unreadable (invalid login_identity); live identity: ....

When recovery reads

Let L be the profile the ledger names as live. Recovery returns at once, makes no request and writes no line, unless all of these hold:

  1. the ledger names a live profile L;
  2. no swap journal is pending;
  3. the last swap is at least SWAP_GRACE (600 seconds) old, measured from the ledger's swapped_at, or the ledger has no swapped_at;
  4. ~/.claude/.credentials.json is a regular file holding an OAuth login.

SWAP_GRACE covers the minutes after a swap during which running sessions can still write the previous account into ~/.claude.json and refresh the token they hold. With the recommended --interval 120, it spans five cycles. A swapped_at more than SWAP_GRACE later than the cycle's time (the clock went back) also turns recovery off; the cycle writes the the last swap time is later than now note described under Notes.

When it reads, recovery reads ~/.claude first. When that account is the one recorded for L, the finding is Clear and no profile is read. Otherwise it reads the profiles: each profile that passes the usual directory check and has its own OAuth .credentials.json, in name order. L is read too when its directory still holds a copy. A cycle therefore makes one request when ~/.claude cannot be read or holds L's recorded account, and at most one more for each profile with its own login.

Findings

The ~/.claude account is compared with L's recorded account and with each profile's reading. The first row that holds decides:

Readings Finding What happens
The ~/.claude read failed Cannot tell A note with the cause. Nothing moves; the ledger is not relabelled.
The account recorded for L Clear Nothing. No line. No profile is read.
Same account as more than one profile Cannot tell A note naming those profiles.
Same account as L's own copy Clear Nothing. No line.
Same account as exactly one other profile M, and M has a record naming another account Cannot tell A note: M's own folder holds a login that is not M's; run profile verify.
Same account as exactly one other profile M Suspect M See Two readings.
Same as none, and one or more profile reads failed, or the limit ran out Cannot tell A note naming those profiles and each one's cause.
Same as none, and L has a record naming another account Cannot tell A note pointing at profile verify.
Same as none, and L has no record Clear No recovery action. This proves no duplicate was found, not that L owns the live login. A later swap still requires trusted authorization, and seeding decides whether L gets a record.

A profile with no login of its own is never compared, so recovery never records a login-less profile as live. Such a profile's login can only be in ~/.claude, and nothing the credential returns says whose it is. The cycle keeps the ledger's L. Earlier releases recorded that profile from ~/.claude.json, or kept L because its recorded account matched; neither happens now.

A Clear finding that no profile holds a duplicate does not establish the live login's owner. Any later swap still requires trusted identity and applicable ownership checks. A recorded-account conflict refuses movement regardless of session JSON; missing records use the existing trusted adoption/backfill rules or seeding. An uncertain scan cannot authorize movement or ledger relabeling. See Rotation login identity.

Two readings

The first "Suspect M" writes the ledger's hand_suspect (M and the cycle's time as first_seen) and the suspicion note. It never moves a login or relabels the ledger. A later cycle confirms the suspicion only when all of these hold:

  • its finding is "Suspect M" for the same M;
  • at least one rotation interval (--interval, at least 1 second) has passed since first_seen;
  • first_seen is not earlier than swapped_at and not later than the cycle's time.

A finding of "Suspect" for a different profile replaces the record and starts again. Any other finding clears it. A first_seen later than the cycle's time resets the record to the cycle's time.

While a suspicion is open, the live login counts as hand-changed: the cycle writes the note, then the hand-change ALERT from Rotate live profile, measures nothing, does not swap, and ends as alerted. profile switch refuses in the same way. A rotator that has stopped leaves the suspicion in the ledger, and switching stays refused until a cycle runs; amplihack profile rotate with no subcommand runs one.

Only-login rule

A confirmed suspicion means the server reported the same account, twice, for ~/.claude and for <root>/<M>/.credentials.json: they are two logins of one account. Recovery may move M's copy aside and record M as live only if every profile that had a login before the cycle still has one after it. L had the login in ~/.claude; once M is live, L keeps a login only if <root>/<L>/.credentials.json holds one: a regular file owned by you, opened without following a symlink, not writable by group or others, and holding a JSON object (an OAuth login or an API-key profile's file). A symlink, another file type, another owner, or an empty, unparsable or unreadable file counts as no login.

L after the move Action
Has its own login The checks below run. If they pass, M's copy is moved and M is recorded as live.
Would have no login anywhere Refused. The only-login ALERT is written; both logins stay where they are, the ledger still names L, and the suspicion stays open, so the cycle does not swap.

A manual /login in ~/.claude over a login the rotator swapped in therefore ends in the only-login ALERT, not in an automatic recovery: the /login already replaced L's only login, and recording M would hide that.

Because identity is the server's account, two different accounts never reach this rule, however their usage windows line up. A swap onto one of a pair of accounts that reset at the same times goes ahead with no note and no ALERT. The rule is reached only when ~/.claude and M hold one account: a /login over L's login, or L and M set up as two profiles of one account with no record for L.

Checks before the move

Checks before recording, with the <reason> each gives when it fails: the profile root is private, no swap journal is pending or inconsistent, and HOME and ~/.claude pass the swap's home checks. Then:

Check <reason> when it fails
No running process has CLAUDE_CONFIG_DIR=<root>/<M>. A host where running sessions cannot be seen fails this check. a claude session is running on <M> / cannot see running sessions
Neither ~/.claude/.oauth_refresh.lock nor <root>/<M>/.oauth_refresh.lock exists. Claude holds its refresh lock
M's login is not leased and M does not host another login in the auto-switch ledger; an unreadable auto-switch ledger fails this check. <M>'s login is lent out or it hosts another login
<root>/<M>/.credentials.json is a private regular file with one link, owned by you. a login file is not a private regular file with one link
~/.claude, <root>/<M> and the root are on one device. ~/.claude and the profile root are on different devices
~/.claude and M are read again and the server reports one account for both, and <root>/<M> passes the directory check again. The two re-reads have their own limit of 10 seconds. ~/.claude changed during recovery
.rejected-logins/ and the backup directory can be created. cannot create the backup directory: <error>
.rejected-logins/ and the backup directory are real directories owned by you with no group or other bits. backup directory is not private: <path>
A free backup name exists. no free backup name
After the backup directory is created, just before the rename: the device, inode and change time of both login files are those seen at the start of the cycle. The new, empty backup directory is removed again when this check or the rename fails. ~/.claude changed during recovery

The backup is <root>/.rejected-logins/rotate-<M>-<YYYYMMDDTHHMMSSZ>/, where the time is the cycle's start in UTC. If that name exists, -2 to -99 is added. .rejected-logins/ is created 0700 if it is missing; one that exists must be a real directory owned by you with no group or other bits, as profile login requires. The backup directory is created fresh, 0700, never through a symlink, and must then be a directory owned by you with no group or other bits; one that is not is removed again (it is new and empty) and the move is refused. Its parent is synced. The login is moved into it with renameat2(RENAME_NOREPLACE). Nothing else is moved, and <root>/<M>/.claude.json is not changed.

On success the log line is:

recovered: ~/.claude and <M> held the same account; kept ~/.claude, moved <M>'s copy to <backup>/.credentials.json; recorded <M> as live

Recording M sets the ledger's live to M and since to the cycle's time, records the trusted credential account, and clears alert, guidance and hand_suspect, in one atomic write. The cycle then carries on with the new ledger and may swap in the same cycle. When M is an overflow profile, the same cycle measures and applies the overflow policy as for any cycle that starts on credits.

The steps run in this order: checks, re-read and re-check the directory, create the backup directory, check the inodes, move the login, write the ledger. A refusal therefore leaves no new directory under .rejected-logins/. There is no journal. Every interrupted state is safe:

Stopped after State Next cycle
Creating the backup directory An empty rotate-<M>-<time>/. Uses the next free name. The empty directory is left.
Moving the login M has no login; the ledger still names L and holds the suspicion. M is no longer compared, so the finding is Clear and the suspicion is cleared. The ledger keeps L. Because <root>/<L>/.credentials.json exists, a swap away from L is refused, so no login is saved under the wrong profile. Remove <ledger> to set it right; the next cycle then finds the live profile afresh.

If a session on M writes a new login there after the move, later cycles compare it again from the start.

Hand-change notes

A note says that recovery could not tell, or has one reading and waits for a second. It never moves anything. At most one note is written per cycle, and a note identical to the previous cycle's is not written again, so an expired token in ~/.claude writes one line, not one per cycle. The note is kept in the ledger's guidance until the finding changes, and rotate status prints it as a note: line. The one-shot command prints it on every run.

Suspicion, first reading or before the interval has passed:

note: ~/.claude holds the same account as profile <M> (ledger names <L>); nothing moved, the next cycle reads again

Cannot tell:

note: cannot tell whose login is in ~/.claude (live=<L>): <why>; nothing moved
Cause <why>
The ~/.claude read failed ~/.claude identity read failed: <cause>, with its cause, such as http 429 or token expired
Same account as more than one profile it holds the same account as more than one profile (<M1>, <M2>)
One or more profile reads failed profile <P1> not read (<cause>), <P2> not read (<cause>)
The profile root could not be listed the profile root could not be listed
The 30-second limit ran out the reads ran out of time
swapped_at is more than SWAP_GRACE later than the cycle's time the last swap time is later than now
Same account as one profile M whose record names another account it holds the same account as profile <M>, which is not the account recorded for <M>; run amplihack profile verify
Same as none, and L's record names another account it holds an account other than the one recorded for <L>; run amplihack profile verify

Profile lists are sorted by name and joined with ,. Notes hold profile names and fixed text only. A note longer than the ledger's 1024-byte guidance limit is cut at a character boundary before it is saved, so a long list of profiles cannot make the ledger unreadable.

Only-login ALERT

ALERT: ~/.claude holds the same account as profile <M> on two readings (ledger names <L>), but <L> has no login of its own, so recording <M> would leave <L> with no login anywhere; nothing moved, no swap
fix 1: if a /login in ~/.claude replaced <L>'s login: close every claude session that uses ~/.claude, then run: mkdir -m 700 <dir> && mv -n <root>/<M>/.credentials.json <dir>/ && rm <ledger>; then run: amplihack profile login <L>
fix 2: if <L> and <M> are profiles of one account, run amplihack profile verify to see the account each folder holds, then remove one of the two profiles

The ALERT and its fix lines are written on every cycle while the suspicion stays confirmed, and kept in the ledger's guidance. fix 1 sets M's copy aside, so the login in ~/.claude is M's only login, and removes the ledger; with no ledger, the next cycle finds the live profile as Rotate live profile describes.

profile login <L> can run at once; there is no need to run a rotate cycle first. Standalone profile login keeps its existing account match: with no ledger, it treats L as live only when L has no login and its .claude.json names the account in ~/.claude.json. If stale session data still names L, that standalone check can refuse with profile '<L>' is the rotator's live profile. After closing the sessions, run plain claude with no CLAUDE_CONFIG_DIR and without /login, then quit so it updates its display account before retrying profile login <L>.

Rotation and profile switch use trusted login-bound evidence instead. With no ledger, a cycle can identify M as live only through the trusted ownership checks; it cannot identify L or write a new ledger from stale session JSON. Missing, uncertain or conflicting required evidence prevents movement and ledger relabeling.

profile verify

amplihack profile verify [--fix] audits which account each folder holds, by the same identity reading recovery uses: one GET /api/oauth/profile per login with its own token, no refresh, no .claude.json, no reset times. It was added for #1886, to be run once after the fix to find and undo profile names crossed by the 3 November misfires, and can be run at any time.

It prints one line for ~/.claude, then one for each profile in name order:

~/.claude (live login-af) -> user-af@example.com: ok
login-af -> no login
login-an -> no login
login-ao -> user-an@example.com: MISMATCH, recorded for login-an

The account is the e-mail the server reports, or its uuid when it reports no e-mail. ~/.claude is compared with the record of the profile the rotate ledger names as live. The statuses are:

Status Meaning
ok The folder holds the account recorded for it.
MISMATCH, recorded for <names> The folder holds another account, recorded for those profiles (recorded for no profile when none).
no record, recorded for <names> The profile has no record. profile seed-record can add one.
no live profile, recorded for <names> ~/.claude when the ledger names no live profile.
no login No .credentials.json; for the live profile this is normal after a swap.
not an OAuth login An API-key file, or a file that is not private or cannot be parsed.
not read (<reason>) The server did not answer for the token: one of the fixed direct-read reasons, such as token expired or http 401, or folder refused for a folder that fails the directory check.
excluded (not probed) The profile is in the auto-switch exclude list. Its folder and login are not read and no request is made. Having no e-mail, the line is <P>: excluded (not probed).

Excluded profiles are not read at all. verify has no swap to protect, so it makes no request for them, writes nothing to their credentials and never refreshes their logins. The ~/.claude line is not read either when local files show that the live login belongs to an excluded profile, by the rules under Local proof of an excluded live login. That line is then ~/.claude: excluded (not probed), live profile <P>.

~/.claude: excluded (not probed), live profile shared
review -> review@example.com: ok
shared: excluded (not probed)

Excluded lines do not change the exit status: the user chose to exclude those profiles. --fix leaves them out of its plan and never touches their folders.

The exclude list is read from <root>/.auto-switch once per run. When that file cannot be read, does not parse or is unsafe, verify prints the auto-switch config unreadable or unsafe warning on stderr and treats every profile as excluded; see Unreadable exclude list.

Without --fix nothing is written. The command exits non-zero when any folder holds an account other than its recorded one and is still there at the end.

Do not run --fix until #1960 is closed. It writes no records, so it never fixes no record; use profile seed-record for that. The rest of this section describes what the flag does.

With --fix, under the rotate lock (refused when another process holds it for 2 seconds) and never while a swap journal exists, it moves a profile folder's own login P into the folder of profile T only when all of these hold:

  • P's record names another account, and exactly one other profile T has a record naming the account P holds;
  • T is not the profile the ledger names as live (its login is in ~/.claude);
  • T's folder holds no .credentials.json at all. A target that holds a different account, the same account, or a login that could not be read is refused: two copies of one login share a refresh token, so one of them must be chosen by hand;
  • no other move in the same run goes to T.

Each other mismatch prints <P>: not moved: <why>. An excluded profile is never a source or a target of a move; a move that would target one prints <P>: not moved: <T> is excluded; --fix does not touch it. ~/.claude is never moved; a mismatch there prints ~/.claude: not moved by --fix; use amplihack profile switch. A move goes from one folder to an empty one, so a pair of folders that hold each other's accounts is reported, not swapped; fix such a pair by hand.

Before the first move, --fix writes <root>/.rejected-logins/verify-<YYYYMMDDTHHMMSSZ>/moves (directory 0700, file 0600, created fresh, never through a symlink). It lists each move as a # <P> -> <T> comment followed by the mv -n command that undoes it. This list is the backup. No login is copied, because a copy of a login is a second holder of its refresh token. Just before each move, P is read again and must still report the account surveyed, and T must still hold no login file. The move itself is renameat2(RENAME_NOREPLACE), so it never replaces a file. The ledger and the records are not changed. The command prints moved <P>'s login to <T> for each move.

Nothing printed holds a token. The e-mail addresses are printed because the command is asked to show them; the rotator itself never prints or logs an account.

Seeding a record

Swapping away from a profile needs a record or other ownership evidence. A live profile with no record gets one in one of two ways. Both use one fresh identity reading per profile. Neither moves a login or writes a credentials file, and neither goes through profile verify --fix.

Path Requires Outcome
A rotate cycle, live profile only The ledger's login_identity matches the reading in full, plus the shared rules below Records the account and logs seeded: recorded account for live profile <L>. Rotation goes on.
A rotate cycle whose ledger has no login_identity Cannot seed: an older key alone does not prove ownership No record and no swap. Measuring goes on, and the note below names the command.
profile seed-record <name> The operator names the profile, plus the shared rules below Shows the account. Writes the record only with --write.

profile switch never seeds. Run profile seed-record first if a switch is refused because the live profile has no record.

The shared rules are:

  • The reading is trusted and has both an account uuid and an organization. An account with no organization is never seeded.
  • The account and organization are printable values. A value with control characters or terminal escape sequences stops the seed.
  • No swap journal exists, whether the rotate or the auto-switch one, and no hand-change suspicion is open. A journal that cannot be read counts as present.
  • The profile has no record. A usable record is never overwritten, and an unusable one stops the seed until you repair it.
  • A complete scan finds no other profile claiming that uuid and organization.
  • ~/.claude is compared too. For the live profile it is the reading itself. For any other profile it is read once and must hold a different account; the seed stops if it holds the same uuid and organization or if that read fails. A definitely missing login or an API-key login in ~/.claude holds no account to compare.
  • Just before the write, under the lock, the reading still matches the login and the scan's claims still hold. A preview made before the lock cannot justify a write.

How the scan counts each other profile. Seeding does not refresh tokens, so one expired spare login must not block every seed. Swap authorization keeps its stricter scan, which refuses on any failed read.

Other profile Seeding counts it as
Has a usable record A claim on its recorded account, whatever the rows below find.
Has an unusable record Blocks the seed, naming the profile.
Its login file is definitely missing No read and no claim from the login. Any other failure to check the file, such as permission denied, is not proof that it is missing and blocks the seed as login file not trusted.
Holds an API-key login No read and no claim from the login.
Read succeeds A claim on the account it holds.
Has a usable record, and the read failed with token expired, http 401, http 429, timeout, transport or identity read budget used up Its record stands in for the read.
Has a usable record, and the read failed with any other cause, including no oauth token, any other http status and unparseable Blocks the seed, naming the profile and cause.
Has no record, and the read failed with any cause Blocks the seed, naming the profile and cause.

Two profiles with one e-mail. Accounts are compared by uuid and organization, never e-mail alone. login-ax and login-aw can share you@example.com and still be told apart when their organizations differ. When they cannot be told apart, the cycle alerts and names them all, sorted:

ALERT: cannot tell profiles <L>, <M> apart: both claim the account in ~/.claude; no record written, nothing moved

This line is written on every cycle it applies to. It describes the live profile, so only a cycle writes it; profile seed-record has its own refusal text.

When a cycle cannot seed. It logs this line once per process, and a real cycle goes on to measure. A swap away from the profile is then refused with ALERT: swap refused: trusted login identity: outgoing ownership is not established; run: amplihack profile seed-record <L>. The note says why the seed stopped:

note: no record for live profile <L>: <reason>; nothing moved; run: amplihack profile seed-record <L>
<reason> Meaning
the ledger has no login identity The ledger is from before login identities were kept, so it cannot prove ownership.
identity read failed: <cause> The live login's identity read failed.
the reading has no account uuid or organization The server's answer cannot identify one account in one organization.
the account cannot be printed safely A value holds control characters or terminal escape sequences.
a swap journal is pending or unreadable Finish recovery first.
a hand-change suspicion is open Only profile seed-record reports this; a cycle writes the hand-change ALERT instead. See Two readings.
profile <P> not read (<cause>) The scan is blocked by that profile's failed read.
profile <P> has an unusable record; repair it first That profile's record, or the live profile's own, stops the seed.
the profile root could not be listed The scan cannot be complete.
the ledger does not match the reading The ledger's identity names another account.

--dry-run prints would seed: record for live profile <L> from a fresh reading when a real cycle would seed, and otherwise the same note after would note:. A dry-run live=<L> token comes from the ledger. It names the login for reporting and authorizes nothing, so read the would line beside it to see whether the rotator can swap away from <L>.

A record is a trust anchor: with one, swap authorization skips the strict outgoing scan. That is why every doubt above stops the seed.

profile seed-record

amplihack profile seed-record <name> [--write]

<name> must be a valid profile name; the command takes no folder argument. It reads ~/.claude for the profile the ledger names as live, and <root>/<name>/.credentials.json for any other profile. It never refreshes a token, starts claude, moves a login or writes a credentials file.

Without --write it writes nothing:

$ amplihack profile seed-record login-ax
login-ax -> you@example.com, organization 00000000-0000-0000-0000-000000000000: no record; nothing written; run with --write to record it

$ amplihack profile seed-record login-ax --write
login-ax -> you@example.com, organization 00000000-0000-0000-0000-000000000000: recorded

With --write it takes the rotate lock first and makes every check under it. A busy lock fails with rotate: lock busy, and the log gets seed-record: recorded account for profile <name>, with no account in it.

The shared rules apply, together with these:

Situation Result
A usable record exists <name>: a usable record exists; nothing written, exit 0. Also the result when another process writes one first.
<name>'s record is unusable Refused: profile <name> has an unusable record; repair it first
The ledger exists but cannot be read Refused, with or without --write: the rotate ledger is unreadable
<name> is not the ledger's live profile, or there is no ledger, and ~/.claude holds the account the reading shows Refused: ~/.claude holds this account, so the login may be live under another name
The same, and the read of ~/.claude failed Refused: ~/.claude identity read failed: <cause>
Another profile claims the account Refused, with names sorted: another profile claims this account: <P1>, <P2>
<name> is the ledger's live profile, the ledger has a full login_identity, and the reading differs Refused: the ledger does not match the reading
<name> is the ledger's live profile, the ledger has only an older key, and it is not the reading's uuid Refused: the ledger's older key does not match the reading
<name> is the ledger's live profile, and the older key is an e-mail Refused: the ledger's older key is an e-mail, which cannot prove ownership
<name> is not the ledger's live profile, and no rule refuses Allowed. The folder name is the only evidence tying the profile to its login, so read the account shown before using --write.
An account value is unsafe to print: empty, over 320 bytes, or holding a control or bidirectional-override character (U+202A–U+202E, U+2066–U+2069) It prints <unprintable>, and --write is refused: the account cannot be printed safely
The token has expired Refused: identity read failed: token expired. Run profile usage <name> to refresh a non-live profile. The next rotator cycle refreshes the live login.

A refusal prints seed-record <name>: refused: <reason>; nothing written and exits 1. It writes no ALERT. Other <reason> values, such as a pending journal or a blocked scan, are those in the cycle's table, except the ledger has no login identity, which only a cycle reports.

The e-mail and organization go to stdout only, never to the rotate log, the ledger or an alert.

The record is created without replacing anything: a private temporary file (0600, no symlink followed) is linked to the final name, so a record that already exists stays as it was. A filesystem that refuses hard links gives a named error and no record; the command does not fall back to a rename.

Once the record is linked, it counts as written. If removing the temporary name or syncing the directory then fails, that is logged as a warning. If the audit line cannot be written, stderr gets seed-record <name>: recorded, but the audit log could not be written: <error>, and the command still reports the record and exits 0.

A wrong record. Seeding a non-live profile whose folder holds another account's login, when nothing else claims that account, records the wrong account. To remove it, run rm <root>/.auto-switch.d/expected/<name>.json. An accepted profile login <name> also replaces it.

Guidance

When a confirmed move fails a check, nothing moves, the cycle writes an ALERT line and one fix line, ends as alerted and does not swap:

ALERT: the account in ~/.claude is not the one the ledger names (live=<L>); profile <M> holds the same account and has its own login; recovery refused: <reason>; no swap

The fix line for each <reason>:

<reason> fix line
an earlier swap stopped half way see the Recovery section of docs/howto/claude-profile-rotation.md
HOME is not a directory owned by you make <home> owned by you and run: chmod go-w <home>
~/.claude is not a private directory owned by you make <home>/.claude owned by you and run: chmod 700 <home>/.claude
profile root is owned by another user, profile root is writable by other users make <root> owned by you and run: chmod 700 <root>
a claude session is running on <M> close the claude sessions that use <M>; the next cycle retries
cannot see running sessions close the claude sessions that use <M>, then run: mkdir -m 700 <dir> && mv -n <root>/<M>/.credentials.json <dir>/
Claude holds its refresh lock wait; the next cycle retries
<M>'s login is lent out or it hosts another login wait for the auto-switch session to end; the next cycle retries
a login file is not a private regular file with one link, ~/.claude and the profile root are on different devices, cannot create the backup directory: <error>, backup directory is not private: <path>, no free backup name move <M>'s copy by hand: mkdir -m 700 <dir> && mv -n <root>/<M>/.credentials.json <dir>/
~/.claude changed during recovery none needed; the next cycle retries

<ledger> is <root>/.auto-switch.d/rotate/ledger.json, <home> is the real HOME path (never ~), <root> is the profile root, and <dir> is <root>/.rejected-logins/manual-<time>, where <time> is the cycle's time as YYYYMMDDTHHMMSSZ. A path made only of A-Z a-z 0-9 / . _ + - is printed bare; any other path is single-quoted, with each ' written as '\''. If any path a line needs has a control or bidirectional-override character, or the whole line would be longer than 1024 bytes, the line is move <what> by hand; its path cannot be printed safely instead, where <what> is the login in ~/.claude or <M>'s copy. A line that names a path is never cut, since a cut path names another file; only lines without a path are cut to 1024 bytes.

Stuck ~/.claude.json

oauthAccount is display state. A missing, incomplete or stale account block does not authorize movement, invalidate trusted identity or start hand-change recovery. The swap builds display details from trusted identity and preserves unrelated JSON fields and file modes.

Safe file handling still applies. A symlink, unsafe permissions, unreadable or malformed JSON, or a non-object can prevent a safe display update and refuse the swap before movement. Resolve that reported file problem; do not move a login or run /login merely because the display account is stale. The serialized ledger remains compatible with existing home_unreadable_since fields; such a timestamp is not ownership evidence.

Some recovery diagnostics retain their earlier display-file wording. These messages describe file safety or older retained guidance; they never make session account values proof of login ownership. A stale or missing oauthAccount alone does not trigger recovery. Resolve the actual reported file problem and trusted-identity refusal before following recovery guidance. The retained message grammar is:

ALERT: the account in ~/.claude.json cannot be read (live=<L>); no swap this cycle, the next cycle reads it again; do not /login in ~/.claude, it would replace <L>'s login
ALERT: ~/.claude.json has had no account that can be read for 5 minutes or more (live=<L>): <problem>; no swap until it is fixed; do not /login in ~/.claude before the login there is set aside, it would replace <L>'s login
fix 1: run claude with no CLAUDE_CONFIG_DIR and without /login, then quit it; if <home>/.claude.json then holds an account, the next cycle goes on
fix 2: or give <L> its login back and start over: close every claude session that uses ~/.claude, then run: test ! -e <root>/<L>/.credentials.json && mv -n <home>/.claude/.credentials.json <root>/<L>/ && rm <ledger>; then run claude with no CLAUDE_CONFIG_DIR and /login

Older guidance can include it has no oauthAccount block. That display condition cannot establish which account the moving credential belongs to.

The retained file-problem labels are it does not exist, it cannot be read (a symlink, not a regular file, over 32 MiB or not readable), it is not valid JSON (empty or cut short), it is not a JSON object, and its oauthAccount block has no usable accountUuid or emailAddress. These labels describe display metadata and never replace trusted identity.

Separately, every cycle writes, for each profile in the ledger's lost_login:

ALERT: profile <L> has no login anywhere: a manual /login in ~/.claude replaced it. Run: amplihack profile login <L>

Recovery no longer adds profiles to lost_login: the only-login rule refuses any move that would leave a profile with no login. Entries written by an earlier release are still reported. A profile leaves lost_login when <root>/<L>/.credentials.json exists again or <root>/<L> is no longer a real directory (it was removed, or replaced by a symlink). lost_login holds at most 64 profiles; the line

ALERT: profile <L> has no login anywhere, and the list of such profiles is full, so this is not repeated. Run: amplihack profile login <L>

is written once for a profile an earlier release could not add.

ALERT, fix and lost-login lines are written on every cycle while their condition holds, at most once each per cycle, without the ALERT key. Notes are written once until they change. The one-shot command prints all of them on every run. The ledger's guidance holds the current note or ALERT and fix lines and is cleared when the finding is Clear; status prints them.

--dry-run makes the same identity reads, without the lock and without refreshing, and applies the same rules to the ledger's hand_suspect as it stands. It writes nothing, so it never starts or confirms a suspicion:

Ledger and readings Dry-run line
hand_suspect names M, its interval has passed, the reading is "Suspect M", and the checks pass would recover: <recovered line>; then it stops before measuring
The same, but the only-login rule or a check refuses would alert: <ALERT line>, followed by its fix lines; then it stops with outcome alerted
A suspicion or cannot-tell finding would note: <note>, without the note: prefix; a suspicion then stops with outcome alerted, a cannot-tell finding goes on to measure
Within SWAP_GRACE, or any other gate in When recovery reads Nothing; no request is made
The live login has expired would refresh: expired login in ~/.claude, before any other line of this table
The live profile has no record would seed: ... or would note: no record for live profile ...; see Seeding a record
The ledger exists but cannot be read would alert: rotate ledger unreadable; ...; see Unreadable-ledger stop

<recovered line> and <ALERT line> are the log text without its recovered: or ALERT: prefix. A dry run does not go on to the live profile table after a would alert: line, so it never prints a second would alert: line for the same finding. These recovery identity reads send each login's token to the OAuth profile endpoint (GET /api/oauth/profile), as the real cycle does. Usage measurement is a separate read.

Rotate switch

amplihack profile switch <name> moves a profile's login into ~/.claude by hand. It uses the rotator's lock, recovery, candidate check, swap and ledger entry, so it refuses every profile the rotator would refuse, and the result is exactly what a rotate swap to <name> would leave. Switching moves that profile's login file away from sessions started with --profile <name>, so those sessions lose their login while the pin stands. Then it pins rotation to <name> (see Rotate pin) and makes <name> the default for new launches. No rotator needs to be running.

The steps run in this order. A step that refuses ends the command with status 1 and writes no pin, no ledger ALERT and no new swap. Moving the live login and setting the default for new launches are separate: a refusal at steps 6-8, which is about the live login or <name> itself, still writes <root>/.default (see Default only); a refusal at steps 1-5 writes nothing, .default included. Step 5 may already have finished or rolled back an interrupted swap, which changes the ledger, the journal and ~/.claude; each such recovery is logged as a recovery: ... line and stays done even if a later step refuses. When no recovery ran, a refusal changes nothing but .default.

  1. Check the name with the name rules and find the profile. An unknown profile is refused here, before any lock is taken.
  2. On a platform without Unix file semantics, write <root>/.default, print the two default-only lines (rotation not held), and fail with RotateUnsupported.
  3. Run the prototype check and check that the profile root is private.
  4. Take <root>/.auto-switch.d/lock, waiting up to 2 seconds. A busy lock is refused with RotateRefused (state lock busy).
  5. Run auto-switch recovery, then rotate recovery. Either one finding an inconsistent state is refused. Then, when <name> is an API-key profile and the API-key block is active, the switch is refused with PlatformBlocked. A ledger that cannot be read fails the switch.
  6. Identify the live login:
Live login Action
<name> Nothing moves. Step 7 is skipped.
Another profile Swap from that profile to <name>.
No profile owns it Adopt it as default-original (or the next free name), then swap, as the rotator does.
no-login, hand-change, home-unreadable or ambiguous Refused with the matching ALERT text, without the ALERT: prefix: default only. No ALERT is written to the ledger.

Then, whether or not <name> is already live: when <name> is an overflow profile with an active spend-limit block, the switch is refused, default only, with overflow profile <name> is blocked for its spend limit until <time>; clear the block with `amplihack profile overflow clear <name>` once credits are added. A pin stops every rotator move, so pinning a profile whose credits are known to be spent would hold the login where it cannot work. A ledger that cannot be read fails the switch, since its blocks are then unknown.

  1. Unless <name> is already the live profile, check <name> against Rotate candidates, using the list built under the lock in step 6. A profile with any skip reason is refused, the same profiles the rotator never swaps to, so a switch never moves a login out from under a running session, an auto-switch lease or a hosted login. The refusal is default only: <name> still becomes the default for new launches. The refusal is profile <name> is not a rotate candidate (<reason>): <detail>, where <reason> is the skip reason the rotator logs:
Reason Detail
directory refused its directory is a symlink, not owned by you, or open to group or other users
no login, file missing The whole message is profile <name> has no stored login; run `amplihack profile login <name>` first.
no login, file present a login file is not a private regular file with one link
excluded it is in the auto-switch exclude list; set the list without it with `amplihack profile auto-switch exclude` first
session running a running process has CLAUDE_CONFIG_DIR set to it; end that session first
session running, /proc cannot be scanned running sessions cannot be seen here, so its login may be in use. Every profile but the live one is refused, as every profile is skipped by the rotator. This is every system but Linux, macOS included: there switch only sets the default for new launches.
leased auto-switch has lent its login to another profile's session
hosting its directory holds another account's login for auto-switch
parked auto-switch has parked its own login
no account Its login has no usable trusted identity for the required ownership check. The message includes the cause.

excluded and parked refuse too. The exclude list keeps a profile out of rotation, and a switch is a rotation done by hand; to switch to an excluded profile, take it off the list first. A parked profile's own login sits in <root>/.auto-switch.d/parked/ while its directory holds another account, so there is nothing of its own to move. 8. Run the swap unchanged: the same pre-swap checks, journal, refresh locks and ledger entry. A refusal from the swap moves nothing and is passed through unchanged, default only. The log gets switch <from>-><name>. 9. Still under the lock, write the pin, then the default pointer <root>/.default, then the ledger's last_cycle: outcome switched, with at and measured_at both the current time, and clear the ledger's ALERT key. The record carries no live_room, because switch takes no reading; a waiting step reads switched without it as room. This record is what lets the usage-limit wait rerun steps that stopped on a usage limit before the switch; see Sessions stopped by a limit. No swap record is written. 10. Release the lock, then check the shared session links of <name> and of the profile swapped out. Problems there are warnings on stderr only.

switch reads none of the AMPLIHACK_ROTATE_* settings and never runs claude. It makes no usage measurement, but it does make the bounded credential identity reads needed by the shared swap guards. It does not look for a claude binary either, so it works with no claude on PATH. A login with no capacity left is still moved: switch does what you asked, and the usage checks that stop a rotate swap do not apply to it.

On success it prints three lines and exits 0:

Live login moved: work -> spare
Default for new launches: spare
Rotation held on spare until `amplihack profile switch --none`.

When switch adopts a ~/.claude that no profile owned, the first line names the adopted profile, for example Live login moved: default-original -> spare, and the log gets switch default-original->spare.

When <name> is already the live login, the first line is spare is already the live login; nothing moved. and the log gets skip: spare is already the live login; nothing moved.

Result Output Exit
Swapped, pin and pointer written The three lines above 0
Already live, pin and pointer written The three lines, first line <name> is already the live login; nothing moved. 0
Refused at steps 1-5 (lock busy, prototype, private root, inconsistent recovery) error: ... and hint: ...; no pin, pointer, ALERT or swap written (any step-5 recovery stays done) 1
Refused at steps 6-8, or step 2 off Unix The two default-only lines, then error: ... and hint: ...; .default written, no pin, ALERT or swap 1
The swap ran, then writing the pin, the pointer or the ledger failed error: the live login moved to <name>, but writing the <rotation hold\|default pointer\|rotate ledger> failed: <error>; run `amplihack profile switch <name>` again 1
A name and --none together, or neither clap usage error 2

After a partial failure, ~/.claude already holds <name>'s login, so running the same switch again takes the already-live path and writes the pin, the pointer and the ledger record. It is safe to repeat.

A refused switch writes no ledger ALERT. If step 5 ran no recovery, it also changes no byte of the ledger, the journal, the pin, ~/.claude or ~/.claude.json, and of .default only what a default-only refusal writes. If a recovery ran, only that recovery's changes are made, and its recovery: ... line says what it did.

Default only

When the live login cannot be moved for a reason about the live login or <name> (step 6, 7 or 8, or a platform without Unix file semantics), switch still sets the default for launches outside recipes. It writes <root>/.default under the rotate lock, prints two lines on stdout, and exits 1 with the refusal on stderr:

Default for new launches: spare
Live login not moved; rotation not held.

It writes no pin and no ledger record, so the usage-limit wait does not treat it as capacity, and the rotator keeps rotating. A pin left by an earlier switch is not changed; the second line then names it: Live login not moved; rotation still held on work until `amplihack profile switch --none`. The pin holds a login in ~/.claude. The .default pointer applies outside recipe runs when no flag or inherited profile selects one. After a default-only refusal, the live login and the default pointer can name different profiles. switch --none removes the pin and the default pointer.

This is how switch sets the default on macOS, where /proc cannot be scanned and every profile counts as having a running session, and for a profile that is open in a session of its own (CLAUDE_CONFIG_DIR set to its directory).

If switch is stopped partway through a swap, the journal is left behind as for any swap. The next switch, rotate or rotator cycle runs recovery first, and no pin or pointer has been written.

A second switch <other> while a pin is in force swaps again and moves the pin to <other>.

Sessions stopped by a limit

A switch counts as capacity for the usage-limit wait: you chose that login, so the switch stands in for a measurement taken at the moment of the switch, and a recipe step waiting on a limit in ~/.claude reruns. This holds for every held cycle that follows, because a held cycle keeps the switched record (see Rotate pin).

A switch does not resume interactive sessions. It writes no swap record, so the limit-resume hook keeps waiting, and the held cycles that follow swap nothing, so they write none either. Continue such a session yourself (Esc, Ctrl+U, continue, Enter), or run switch --none and let the rotator's next swap to a login with room resume it.

Warning about an older rotator

After the success lines, switch checks whether a running rotator was started from another amplihack binary, the same check amplihack install and one-shot rotate make (see Rotator capacity rule). Such a rotator does not read the pin and may swap away on its next cycle. switch then prints one more line on stderr and still exits 0, because the login has moved:

amplihack: the Claude login rotator (pid 48211) runs another amplihack binary and ignores the switch hold; restart it: amplihack profile rotate stop && amplihack profile rotate start

With no rotator running, or one started from this binary, nothing more is printed.

Rotate pin

The pin is <root>/.auto-switch.d/rotate/pin. While it names an existing profile, no rotate cycle swaps: not the one-shot rotate, not rotate watch and not the background rotator. profile switch <name> writes it; profile switch --none removes it. Nothing else writes or removes it.

The file holds one profile name and a newline. It is written atomically (temporary file, then rename) with mode 0600. It is read like the other rotate state files: never through a symlink, at most 256 bytes, and only when it is a regular file owned by you that group and others cannot write.

Pin file Cycle Log line
Missing Runs normally.
Names an existing profile Held: after recovery and identify, before measuring. No swap and no measurement. The one probe a held cycle makes is the spend-limit check of a pinned live overflow profile with no active block (see Pin and overflow). Recorded as held, unless the last cycle is a switched record, which is kept. skip: held by switch to <name>; run `amplihack profile switch --none` to release
Names a profile that no longer exists Runs normally; the file is left for switch --none to remove. skip: pin names missing profile <name>; ignored
Not a valid name, too long, a symlink, a directory, not owned by you, writable by group or others, or unreadable Held. Rotation fails closed rather than move a login you did not expect. Recorded as held, unless the last cycle is a switched record, which is kept. skip: pin unreadable; run `amplihack profile switch --none`

The pin wins over every decision in the decision rule, including a threshold reached or an exhausted live login, and over a live login that has changed: an ALERT about the live login is still written, but nothing is swapped. watch writes the skip: pin names missing profile line only when it changes.

A held cycle clears the stored ALERT key (alert and advisory_alert), as a stayed cycle does, so the same ALERT is written again if it is still true after the pin is released. A stayed-unread cycle does not clear it.

A held cycle measures nothing. When the last cycle is the switched record that profile switch writes, a held cycle leaves it in place: it still counts as capacity measured at the switch, so sessions stopped before the switch are resumed (see Sessions stopped by a limit) and sessions stopped after it are not. Otherwise, for example under a pin written by hand or by an older amplihack, the held cycle records outcome held with no measured_at, and held is never capacity.

The pin is checked before the cycle measures or picks a target, so it wins over every rule that picks one, including any rule that prefers some profiles over others, such as the credit overflow proposed in #1694. The pin is a file of its own, not .default: switch --none removes both, which leaves .default unset as such rules expect.

The pin's contents are never printed. A pin that cannot be read gives the fixed pin unreadable text.

switch --none takes the state lock (waiting up to 2 seconds), even when there is no pin, and under it checks for and removes the pin and then .default. A switch writes both under the same lock, so the two commands cannot interleave: whichever takes the lock second wins, and the pin and .default never name different profiles. It checks the path with lstat and never follows a symlink: a file or a symlink is removed (a symlink's target is left alone), an empty directory is removed, and anything else is refused with pin path <path> is not a file; remove it by hand. If the lock is busy, switch --none fails with RotateRefused and changes neither file.

A rotator started before the pin existed does not read it. switch warns when one is running (see Warning about an older rotator). Restart rotate watch (amplihack profile rotate stop, then start) after upgrading. The ledger format did not change, so an older rotator can still read the ledger a switch writes; it reads switched as an outcome it does not count as capacity.

Rotate state directory

Everything is under <root>/.auto-switch.d/rotate/ (directory 0700, files 0600). Ledger and journal are written atomically, never through a symlink, and are capped at 64 KiB. Both have "version": 1, reject unknown fields, and omit optional fields that are unset. Every profile name read from them is checked with the name rules before it is used. A file that fails to parse is left unchanged and reported as RotateInconsistent.

Path Contents
ledger.json live, account, since (epoch seconds when live last changed), swapped_at, previous, alert (the de-duplication key, <kind>:<live profile or ->, of a hard ALERT), advisory_alert (the same key for an advisory ALERT; never set together with alert), last_cycle (at, when the cycle was recorded; measured_at, when the usage it relied on was read, which for stayed is when the live reading was taken (see Stays and capacity) and for every other rotate outcome is when the cycle started measuring, absent for a cycle that measured nothing; outcome; for an overflow cycle, overflow; and, for a cycle that measured the login live afterwards, live_room, see Plan room in the ledger), and overflow_blocked (the blocks, kept in the older-rotator form as well, see below; each with a reason that is a block kind such as spend_limit, session_limit or week_limit; any kind of 1 to 32 characters from a-z, 0-9 and _ loads). account is the validated incoming account key after a swap. It is display only for recovery: no recovery decision treats that key alone as identity proof, and a hand-change recovery records its independently verified account. Optionally hand_suspect, an open hand-change suspicion: profile (a valid profile name) and first_seen (epoch seconds, greater than 0). It holds no account data, is omitted when there is none, and a ledger without it loads as before; one that breaks these rules is RotateInconsistent. Optionally guidance, the current hand-change note, or ALERT and fix lines (at most 16, each at most 1024 bytes, with no control or bidirectional-override characters), and lost_login, the profiles that lost their login to a manual /login (at most 64 distinct valid names). Both are omitted when empty, and a ledger that breaks these limits is RotateInconsistent. Optionally the legacy home_unreadable_since timestamp; retained for format compatibility, never as ownership evidence (see Stuck ~/.claude.json). Optionally swapped_away, the logins the rotator left while they were full, each mapped to the epoch seconds of that swap; see Swap-back damping. Optionally live_login_at, the epoch seconds at which the last swap put the live login in ~/.claude, read by lstat right after its exchange (a swap that recovery finished records none); only local proof of an excluded live login reads it, and a ledger without it falls back to swapped_at there. While a rotator from an older amplihack binary runs, measured_at, live_room, overflow, guidance, lost_login, home_unreadable_since, hand_suspect, swapped_away, live_login_at and advisory_alert are left out so that rotator can read the file. overflow_blocked is not left out (#3105, which reverses the #2890 trade-off): a block the step records for a plan login cannot be derived again, and losing it let the rotator swap to a login that was spend-blocked. The cost falls on older rotators only, and only while a block is held (an empty map is not written): one built before #1659 refuses the ledger, one built from #1695 to before #2890 refuses any kind other than a spend limit, and both refuse loudly until restarted. One built between #1659 and #1695 ignores the field and drops it when it saves. A ledger whose alert or advisory_alert is not a valid key, or that sets both, is RotateInconsistent. The no-capacity/known, no-capacity/stay, no-capacity/held and no-capacity/unconfirmed keys are valid keys, none longer than 89 printable bytes. The ledger has no field for last good readings, rejections or the confirmation state: they are worked out again each cycle and never stored.
journal.json The swap in progress: from, to, adopt, phase (checking, j0, s1, s2, s3, s4 or inconsistent), home, live_ino, target_ino, home_lock_ino and to_lock_ino (each present once that refresh lock is taken), started_at, pid, and optional identity containing sanitized full incoming/outgoing accounts authorized before exchange.
rotate.pid The background process's pid, as ASCII decimal.
gate.json Written by rotate watch when it starts: version, pid, and the overflow gate it resolved from its flags (overflow_wait, overflow_unknown_reset, session_at, week_at). Auto-switch uses it only while the rotator with that pid runs. If it cannot be written, the log says overflow: gate not recorded, auto-switch will not use overflow (<error>) and auto-switch uses no overflow profile.
rotate.log The log.
rotate.log.1 The previous log, after rotation.
rotate.err The background process's own stdout and stderr, and one line from each launch that started a rotator or failed to. Not rotated.
autostart The autostart setting: on or off and a newline. Missing means on.
swap.json The swap record: seq, live_login, from_login, swapped_at, reading (session, week, measured_at) and, for a marked overflow profile, overflow (tier, spend_block). Written atomically, mode 0600, under the rotate lock, only after a successful swap in a rotate cycle. Read by the limit-resume hook. Not part of the ledger; deleting it is safe, and the next swap writes seq 1.
pin The rotation pin: one profile name and a newline. Written by profile switch <name>, removed by profile switch --none. Not part of the ledger.
sessions-archive.last When the daily session archive last started: epoch seconds and a newline. Written atomically before each run; removed when a run stops early after archiving something, so the next pass carries on.
owner The owner marker: unit=, pid= and since= lines. Written by a supervised rotate watch, removed only by rotate owner clear. Not part of the ledger.

The auto-switch ledger.json and journal.json one level up are separate files and are not changed by rotation.

Hand-change recovery also writes outside this directory:

Path Contents
<root>/.rejected-logins/rotate-<name>-<YYYYMMDDTHHMMSSZ>[-<n>]/ 0700. The .credentials.json moved out of profile <name> because ~/.claude and <name> answered as the same account on two readings. Never deleted by amplihack. An empty one is left by a recovery that stopped before the move.

Example ledger, with the account value replaced:

{
  "version": 1,
  "live": "spare",
  "account": "<accountUuid>",
  "since": 1760791205,
  "swapped_at": 1760791205,
  "previous": "work",
  "last_cycle": { "at": 1760791805, "measured_at": 1760791774, "outcome": "stayed" }
}

Overflow fields:

Field Values Written
last_cycle.overflow in (the cycle swapped onto an overflow profile), out (it swapped off one onto a plan profile) or on (it stayed on one) Only for those cycles; absent otherwise.
overflow_blocked Object keyed by profile name; each value is {"at": <epoch>, "until": <epoch>, "reason": "spend_limit"}. The record has this one shape for every kind of limit a step blocks a login for Only while at least one block exists; absent otherwise.

A ledger with no overflow activity is byte-identical to one written before these fields existed. The rotator rejects the ledger as RotateInconsistent, with the message rotate ledger: invalid overflow field and without echoing the value, when a block key fails the name rules, reason is not a limit-kind token, at is not above 0, until is not later than at, until is more than 62 days after at (a sum that would overflow counts as more), there are more than 256 blocks, or last_cycle.overflow is not in, out or on. The rotator writes until as 00:00 UTC on the 1st of the month after at, which always meets this rule; the wider window lets a later reader keep a block whose end came from elsewhere. An unknown key inside a block record is ignored, so a newer writer's extra block fields do not make the ledger invalid. last_cycle and the top level of the ledger still reject unknown keys.

Ledger on credits, with one block on another overflow profile:

{
  "version": 1,
  "live": "login-aw",
  "account": "<accountUuid>",
  "since": 1792832405,
  "swapped_at": 1792832405,
  "previous": "work",
  "last_cycle": { "at": 1792833005, "outcome": "stayed", "overflow": "on" },
  "overflow_blocked": {
    "team-credits": { "at": 1792826100, "until": 1793491200, "reason": "spend_limit" }
  }
}

An amplihack binary older than these fields rejects a ledger that has them, because it rejects unknown fields everywhere in the ledger. This binary relaxes that rule only inside a block record; last_cycle and the top level stay strict, so a future field there is rejected in the same way. The rejection fails safe: the older binary leaves the ledger unchanged, reports RotateInconsistent and makes no swap, so rotation stops instead of acting on a ledger it cannot read. A version gate that names the newer writer instead of failing on the field is a follow-up in #1687. Upgrade every binary that uses the root before the first overflow add, then restart the rotator (rotate stop, rotate start). To go back to an older binary, follow Upgrading and rolling back.

Plan room in the ledger

last_cycle.live_room answers one question for a waiting step: after this cycle, does the login live in ~/.claude have room to run a step? It is true when the rotator holds a measured reading of that login from the cycle and the reading passes the session-room test: session use below --session-at and week use below 100%. The test is applied to the reading of whichever login is live after the cycle, whatever its kind. For the live login that is the freshest reading the cycle holds, so a stale cached figure never records room that a fresher reading of the same login denies. There is no exclusion for a credit-backed overflow profile or the API-key profile, so a cycle that moves onto either can record true. The rotator decides this, from the measurement it already holds, so a reader never applies a threshold of its own. The field holds no percentage and no other reading.

{
  "version": 1,
  "live": "spare",
  "last_cycle": { "at": 1793701445, "measured_at": 1793701325, "outcome": "swapped", "live_room": true }
}
Cycle live_room
A swap, or a stay, after which the login in ~/.claude has a measured reading from this cycle: a plan login, a credit-backed overflow profile, or the API-key profile, whose reading is the fixed 0% and 0% true when session use is below --session-at and week use is below 100%, else false
A swap or stay after which that login's reading is failed, exhausted or carried from an earlier cycle false
A cycle that measured nothing (idle, held, skipped, or a guided recovery), and one that holds no reading for the login now live absent
An alerted cycle raised outside the decision, which ends before the live login is read: a refused swap, a paused exclude list absent
An alerted or stayed-unread cycle that went through the decision, because the live login could not be read, or read at 100% or at a spend limit not defined: the field may hold either value. Neither outcome is capacity, so no reader treats it as room whatever the field holds
A profile switch, which records the outcome switched and takes no reading absent
Any record written by a rotator from before this field absent

The swap case reads the reading of the login swapped to. A swap onto a login at s=98% writes "outcome": "swapped" with "live_room": false. The outcome still counts as capacity under the rotator capacity rule, which the limit-resume hook also reads, so that rule keeps its meaning and the new field sits beside it. A stay on a login at s=90% is capacity too, because the login can still be used, and records false for the same reason.

Only a JSON boolean inside last_cycle is read; null, a string, a number, an array and a live_room key at the top level of the ledger all read as absent. While a rotator older than the field runs, this binary leaves the field out, as it does measured_at, so that rotator can still read the file.

The record alone decides, by one rule. The room rule and the waiting step both apply it, so they cannot disagree:

Outcome live_room is true live_room is false live_room is absent
swapped, stayed room no room no room
switched room no room room
any other outcome, or an outcome this binary does not know no room no room no room

switched is the one outcome that reads as room without a true. It is what amplihack profile switch records, and a person who moves the login by hand to unstick a waiting step is saying the login is fit to use, which the rotator's own swap does not say. A switched record that states false overrules that.

Rotate log

The cycle line's w= is the weekly maximum used by selection. A model maximum includes its label, for example w=100%(Fable). An all-models maximum has no model suffix. Equal maxima prefer all-models, then models in label order. This presentation does not replace the all-models reset window with the deciding model's reset. Individual retained model ages are available as week_models[].observed_at in usage JSON.

Each line is YYYY-MM-DDTHH:MM:SSZ <message>, in UTC. The one-shot command writes to the log and stdout, watch to the log only, and --dry-run to stdout only, without the time. --dry-run makes the same re-reads as a real run and prints their reread: lines; see Re-reads for the damp: lines it prints.

Message Meaning
cycle live=<name\|-> <name>:s=<n>%,w=<n>% ... One per cycle: every measured profile, live first, then by name. Percentages are rounded down and come from the windows read. The line is written after the live reading freshness step, so the live entry shows the figures the cycle decided on, and carries ,cached=<n>s (whole seconds) when those figures were read before this cycle's measurement began, for example work:s=5%,w=95%,cached=612s. Candidate entries show their figures as measured when the probe succeeds. An exhausted profile (session_exhausted or weekly_exhausted) shows the figures read, with the window that ran out never below 100%, for example team:s=100%,w=55% or team:s=30%,w=100%; see Exhausted figures. w=? means no weekly window was read. A profile whose probe did not read it shows <name>:unknown, <label> when the cause is one of the labelled kinds (HTTP 429, transport, timeout, still running, probe error; a login whose identity could not be read is not probed, so it is not on this line and is counted in the no-target line), and <name>:failed for every other cause, never a percentage: its usage is unknown, and it is probed again on the next cycle. For a labelled failure, a last good reading up to 300 seconds old adds its figures and age, for example login-al:unknown, HTTP 429, last s=78%,w=92%,cached=41s. A profile whose read had not finished when the cycle stopped waiting shows <name>:unknown, still running; its result is used by the next cycle. spend_limit, not_logged_in and unparsed without a failure label also show <name>:failed. A measured profile that the target rule leaves out carries its reason after its figures: above ceiling <n>% when its week is above --target-week-max, or blocked until <YYYY-MM-DDTHH:MMZ> (<kind>) while it has a recorded block, where <kind> is the block's fixed label (spend limit, session limit, week limit, credit limit, API key exhausted, API key revoked, API key rate limited, or a recorded limit for any other recorded kind), for example y:s=10%,w=40% blocked until 2026-11-26T00:00Z (week limit). A profile with no session limit shows s=0%. A skipped profile is not listed. A live profile in the auto-switch exclude list shows <name>:excluded (not probed); see Rotate excluded live profile. A login no profile owns is shown as -. An API-key profile is never probed. A marked one shows as <name>:per-token, live or not. An unmarked one is listed, as <name>:per-token, only while it is live; otherwise it is not listed.
swap <from>-><to> live s=<n>% w=<n>% target s=<n>% w=<n>% reason=threshold\|projected\|upgrade\|failed-probe\|plan-room\|overflow-in\|overflow-out A completed swap. The readings are formatted as in the cycle line, with a space in place of the comma, so an exhausted target can show target s=100% w=55%. The live figures carry cached=<n>s under the same rule as the cycle line, for example live s=5% w=95% cached=612s; the target figures never do. For an adopted login, <from> is the new profile's name. A failed live probe shows live failed, one still running shows live unknown, still running, and an excluded live profile shows live excluded (not probed). reason=failed-probe is a swap made after three consecutive failed live probes; see Failed live probes. reason=projected is a swap made because the live login's projected session use reached --session-at, or because its last known reading was near --session-at when the live read failed or was stale and the stale reading would not itself have needed a swap (see Failed or stale reading near the threshold); the live figures are those the cycle decided on, as described in Freshest live reading. A cycle that decides on a held reading at or above --session-at needs a swap on the reading itself, so it is labelled reason=threshold, not reason=projected. reason=threshold means the target is below both --session-at and --week-at; reason=plan-room is a plan-room swap, onto a target that has room but is at or above one of them. A swap line reports an unconfirmed suffix when blocked-login recovery used a recent reading; see Rotate confirmation. overflow-in and overflow-out are swaps onto and off an overflow profile. A swap onto a plan login at or above --session-at, off a live plan login with an active block or with reason=overflow-out, ends with ; no credit login was usable; plan target at or above --session-at when no credit login was eligible and unblocked. When one was, and an overflow rule such as --overflow-wait kept the rotator off it, the line ends with ; credit move deferred by overflow policy; plan target at or above --session-at. Either ending is followed by ; credit logins unavailable (session running): <profiles> when a session runs on a credit login.
per-token <name>: no measured plan login below 100%, 0 not measured; <gate>; marked overflow tier <N>; <check> Written before the swap line of every move onto a per-token profile, credit or API key, by the rotator or by auto-switch. Auto-switch writes it before it swaps a session's login or starts a launch or a rerun on the profile, also prints it on stderr, and ends the line with ; auto-switch from <profile>; the rotate log is created if no rotator has run. <gate> is earliest reset <time> beyond overflow_wait, with --overflow-unknown-reset 1 reset unknown, or leaving the API key, credits cost less for a move off the API key, which passes no gate. <N> is the profile's tier, 10 for an API-key profile. <check> is login check passed (<detail>) for an API-key profile, with <detail> from API-key login check, or probe ok, no spend limit for a credit profile the rotator probed. Auto-switch runs no probe, so for a credit profile <check> is no spend block. When the rotator counted a plan login full from a stored reading, its line ends with ; counted full from a stored reading: <names>, and so do its API key not used and overflow marked but held ALERTs. When the rotator moved onto credits past eligible plan logins at or above --session-at (Plan logins near their session limit), its line reads no measured plan login below --session-at (<names> at or above it) in place of no measured plan login below 100%. The line never holds a key value.
key_check_refused <name>: <reason> The API-key login check failed for the target <name>; no swap was made.
ALERT: home_key (<detail>): <effect> A key is in ~/.claude.json or ~/.claude/settings.json while a plan login is live, so sessions bill per token. Written once, and again if the setting changes; see API-key login check. The cycle carries on.
auto-switch: profile <name> was passed over: it has no login file and the macOS Keychain could not be read (<cause>) macOS only. This cycle's capacity file write left overflow profile <name> out because its Keychain could not be read. Written once while that lasts, and again when the Keychain is unreadable again after a cycle in which it answered, or after the rotator restarts. An excluded profile gets no line. The cycle goes on.
overflow: on <name>; no measured plan login below 100%, next plan reset <time\|unknown> Written after an overflow-in swap. When eligible plan logins at or above --session-at were passed over, it reads no measured plan login below --session-at (<names> at or above it) in place of no measured plan login below 100%, and so does the overflow: staying on line.
overflow: staying on <name>; no measured plan login below 100%, next plan reset <time\|unknown> A cycle stayed on overflow profile <name> and the previous recorded cycle did not: its last_cycle.overflow was absent or out, or the ledger's live named another profile. So it is written once when the rotator finds itself on credits without having moved there, for example after a login was put in ~/.claude by hand, and not again while it stays. After overflow-in the overflow: on line is written instead.
overflow: off <name>; back on plan profile <name> Written after an overflow-out swap.
ALERT: overflow profile <name> hit its spend limit; blocked until <time> A spend block was recorded. Written once per block.
ALERT: overflow profile <name> hit its spend limit; not blocked (too many blocks\|no end time) A spend-limit reading that could not be stored as a block: the ledger already holds 256 active blocks, or the cycle's time is outside the range for which the next month can be computed. The profile is still not used in that cycle; the ledger is left as it was, so it still loads.
stay: live probe failed (<k>/3) The live probe failed for the kth cycle in a row; no swap yet.
stay: live probe failed; held after last swap (<N>s left) The live probe has failed three or more times in a row, but the last swap was less than --hold seconds ago.
reread: <name> reading stale s=<n>% w=<n>%; fresh s=<n>% w=<n>% The chosen swap target received its required confirmation by the probe method, with passive readings off. The first figures are those the decision used, the second those of the new read, formatted as in the swap line (w=? when no weekly window was read). The decision was then made again on the new figures.
stale live reading; re-read The live login's reading was frozen, old or lagging and was read again by the configured probe method, with passive readings off. A direct read uses the supplied home's live credentials and never refreshes them. Written at most once per cycle, before the decision. The line holds no name or figures.
reread: <name> failed; treated as unknown The read failed or remained stale. A target cannot be swapped to on this confirmation, including when the active login has a standing block. For a failed live re-read, the existing near-threshold rule applies.
reread: <name> limit reached; treated as unknown The cycle has already used its one target confirmation. Selection is reconsidered, but another target waits for a later cycle.
reread: <name> time limit reached; treated as unknown The existing target probe deadline left no time for confirmation. The target remains unconfirmed and no swap is made. The live re-read has a separate existing budget.
damp: <name> swapped away exhausted; no later reading shows room <name> is in the ledger's swapped_away, and its re-read shows it still at or above --session-at or --week-at, or exhausted. It stays damped. See Swap-back damping.
damp: <name> later reading shows room; swap-back allowed A reading of <name> taken after the rotator swapped away from it shows room, so its swapped_away entry was removed. Written in the record step, after the cycle's swap, stay or ALERT line, and never by --dry-run.
ALERT: no profile has capacity live=<name> s=<n>% w=<n>% (candidates: <counts>) / ALERT: no capacity known live=<name> s=<n>% w=<n>% (candidates: <counts>) No login is eligible and the live login is past a threshold or has no room. The first wording is written only when every other plan login is known, by a fresh or last good reading, to have a window at 100%, a spend limit or an active block; a login the cycle skipped before probing it is never read, so it keeps the second wording. The second is written in every other case. <counts> lists, in this order and leaving out any zero count, <N> unknown (<label>) for each label in the order HTTP 429, transport, identity unavailable, timeout, still running, probe error; <N> not read (<reason>) for each plan login skipped before any probe, in the wording of that login's skip: line (written when the set of skipped logins changes, so often in an earlier cycle); <N> failed; <N> blocked until <time>, the earliest block end as UTC to the minute; <N> exhausted; <N> above week ceiling <n>%; and unknown (timeout) when the confirmation deadline left a target unread. With nothing to count it is candidates: none. The line holds no profile names. The ALERT kind stays no-capacity, and the key is no-capacity for the first wording and no-capacity/known for the second, so a change of wording writes a new line and a change in the counts does not. --dry-run prints it as would alert: no profile has capacity live=<name> s=<n>% w=<n>% (candidates: <counts>), or would alert: no capacity known ..., without the ALERT: prefix. See Rotate no target.
ALERT: credit logins unavailable (session running): <profiles>; staying on <name> (candidates: <counts>) Written in place of the two lines above when a session runs on a credit login and no other ALERT applies. <profiles> lists the credit logins with a running session, and <counts> is as above. Such a credit login is not a target: after a swap, the session and the live login would both use the same login, and either could refresh its token. The ALERT kind stays no-capacity, and the key is no-capacity/credit-session. In the same case, the API key not used, overflow marked but held and the API key is blocked ALERTs end with ; credit logins unavailable (session running): <profiles>.
stay: live room <R>, best other login has room <M>, a move needs <N> The live login has room, a login is eligible, and none has the N = R + max(--margin, 1) room that a move needs. When only a login in another organisation has room, best other login has room <M> reads only a login in another organisation has room. When the live probe read nothing usable, <R> is unknown and <N> is --margin. Written once per key no-capacity/stay, advisory when the live reading qualifies (see Rotate advisory alert). It is not an ALERT. --dry-run prints would stay (live room <R>, ...).
stay: held after last swap (<S>s of <H>s): <name> is at s=<n>%, at or above --session-at The hold kept the rotator on the live login, which has room, instead of moving to <name>. Written once per key no-capacity/held, advisory when the live reading qualifies.
stay: no candidate confirmed by a fresh reading Every qualifying login was rejected at confirmation, at least one of them unknown or superseded, whatever room the live login has. When every rejection showed no room, the no-target line is written instead. Written once per key no-capacity/unconfirmed, advisory or hard as the advisory rule says.
reject: <name> <reason> Confirmation rejected the selected target. The reason may be a model week at or above --week-at, no room, a week above the ceiling, a spend limit, unusable figures or an unknown reading. Selection is reconsidered; an alternative needs a later confirmation unless blocked-login recovery accepts its recent reading. There is at most one target confirmation probe per decision. See Rotate confirmation.
reject: <name> blocked until <utc_minute> (<kind>) A plan login with a standing block, ruled out of the target choice. One line per blocked login in each cycle whose decision looks for a target; no read, so it does not use the target confirmation probe. See Block reject lines.
reject: <name> reading <n>s older than one already held A confirming read was older than the newest reading held for the login, so it was not used. No swap is made on this confirmation.
unblock: <name> <kind> block ended; a later reading shows its window has reset A session or weekly block a step wrote ended because a reading taken after it shows that window has reset. Written once, by the cycle that removes the entry. See A spend limit blocks the login the step ran under.
unblock: step block on plan login <name> ended; a later reading shows both windows below 100% A block a step wrote on a plan login, of any kind, ended because a reading taken after it shows both windows below 100%. Written once, by the cycle that removes the entry. Auto-switch writes no line for the same reading. See A spend limit blocks the login the step ran under.
note: login <name> <kind> not blocked (credit login; its own probe decides) A step met a limit on a credit login that the rotate ledger does not record as live, or the rotator found a hand-off for one. No block is written. Also printed on the step's stderr.
unblock: block on credit login <name> ended; a call on it was accepted A block a step wrote on a credit login ended because the accepted-call check found a call on that login accepted. Written once, by the cycle that removes the entry.
note: login <name> <model> limit not blocked (one model's limit) A step met a limit on one model (Fable, Opus or Sonnet). No block is written. Also printed on the step's stderr.
ALERT: live profile <name> is excluded; no eligible candidate ALERT excluded-live: the live profile is in the auto-switch exclude list and no move off it is possible. The login stays in ~/.claude, unprobed and unrefreshed. Written once per key. See Rotate excluded live profile.
note: live profile <name> is excluded; moving off it Written before the swap line of a move off an excluded live profile.
refresh: live profile <name> is excluded; token not refreshed The expired-login refresh was skipped because a rule under Local proof of an excluded live login named <name> as the live profile.
skip: pinned profile <name> is excluded; spend not probed A held cycle did not probe the spend of a pinned excluded profile; see Pin and overflow.
warning: auto-switch config invalid; exclude list applied, other settings ignored <root>/.auto-switch is a private file of yours that parses but is invalid for its other settings (an unknown kind, say); its exclude list still applies. A file others can write never gets this warning. Written once per cycle. See Unreadable exclude list.
warning: auto-switch config unreadable or unsafe; every profile treated as excluded, none probed or refreshed <root>/.auto-switch exists but cannot be read, does not parse, or is owned by another user or writable by group or others. Followed by the rotation paused ALERT. See Unreadable exclude list.
ALERT: auto-switch config unreadable or unsafe; rotation paused, no profile probed The cycle stopped before measuring because the exclude list could not be read or trusted. Written every cycle until the file is fixed.
ALERT: no login in ~/.claude; no swap ~/.claude/.credentials.json is missing or not a regular file.
ALERT: the account in ~/.claude is not the one the ledger names (live=<name>); no swap ALERT hand-change: a hand-change suspicion is open, or recovery refused a confirmed one. Written on each affected cycle while the identity refusal persists.
ALERT: the account in ~/.claude is not the one the ledger names (live=<name>); profile <M> holds the same account and has its own login; recovery refused: <reason>; no swap A confirmed hand change whose move failed a check. Followed by its fix 1: line. Written every cycle.
ALERT: ~/.claude holds the same account as profile <M> on two readings (ledger names <L>), but <L> has no login of its own, so recording <M> would leave <L> with no login anywhere; nothing moved, no swap The only-login ALERT. Followed by its two fix lines. Written every cycle.
fix <n>: <command> A step of the guidance above, in order.
note: ~/.claude holds the same account as profile <M> (ledger names <L>); nothing moved, the next cycle reads again The first of the two readings. Written once until it changes.
note: cannot tell whose login is in ~/.claude (live=<L>): <why>; nothing moved Recovery could not tell; see Hand-change notes for each <why>. Written once until it changes.
recovered: ~/.claude and <M> held the same account; kept ~/.claude, moved <M>'s copy to <path>; recorded <M> as live Hand-change recovery confirmed on two readings that ~/.claude and M are the same account, and moved M's copy to a backup.
ALERT: profile <L> has no login anywhere: a manual /login in ~/.claude replaced it. Run: amplihack profile login <L> L is in the ledger's lost_login. Written every cycle.
ALERT: profile <L> has no login anywhere, and the list of such profiles is full, so this is not repeated. Run: amplihack profile login <L> L lost its login under an earlier release but lost_login already held 64 profiles. Written once.
ALERT: more than one profile matches the account in ~/.claude; no swap Trusted ownership evidence cannot select a unique login-less profile.
ALERT: trusted login identity unavailable: <cause> The live login has no usable identity reading, and the cause says why. Nothing moves.
ALERT: trusted login identity unavailable for profile <name>: <cause> A candidate is skipped as no account, for that cause. Written on every cycle it applies to.
ALERT: rotate ledger unreadable[ (<field>)]; live identity: <readable\|cause>; nothing moved, no record written Written on every cycle it applies to. See Unreadable-ledger stop.
ALERT: cannot tell profiles <L>, <M> apart: both claim the account in ~/.claude; no record written, nothing moved Written on every cycle it applies to. See Seeding a record.
seeded: recorded account for live profile <L> A cycle seeded the live profile's record.
note: no record for live profile <L>: <reason>; nothing moved; run: amplihack profile seed-record <L> A cycle could not seed. Written once per process.
seed-record: recorded account for profile <name> profile seed-record --write wrote a record.
ALERT: swap refused: <reason> A pre-swap check failed. Missing, uncertain or conflicting required trusted identity produces an ALERT on every affected cycle; other refusals are written once per reason. The one-shot command also prints it and exits with RotateRefused.
ALERT: swap refused: the login in ~/.claude is not the account recorded for profile <from> The trusted live login conflicts with <from>'s recorded account. Nothing moves or relabels. Reported on every affected cycle and manual attempt until resolved. The persisted alert key is account_mismatch:<from>. Session JSON cannot cause or clear this refusal. See Recorded account and Rotation login identity.
ALERT: rotate recovery is inconsistent: <reason>; no swap until it is resolved See Rotate recovery.
ALERT: auto-switch recovery is inconsistent; no swap Auto-switch state needs auto-switch repair.
recovery: rolled back an interrupted swap <from>-><to> / recovery: finished an interrupted swap <from>-><to> Recovery acted.
skip: state lock busy / skip: <name> (<reason>) / skip: cannot see running sessions; no candidates The cycle or a candidate was skipped.
skip: <name> (session running) by process <pid> (<exe>) The readable process that makes <name> live: the one with the lowest pid when several do. Written when a profile is first skipped this way and again when another process holds it (issue #3495).
unreadable process <pid> (<exe>) "<command>": <verdict> A process of yours whose environment the liveness scan could not read, and what it counted for: counted as a session on <a>, <b>, not counted (not a Claude executable) or not counted (profile cannot be told). Written once per process; see Unreadable process lines.
unreadable processes: <N> more not listed More than 32 unreadable processes were noted in one cycle; every one was still judged.
skip: state changed during measurement (<labels>) Step 6 found a change that affects the decision; see Rotate revalidation. <labels> lists one or more of journal, live, pin, overflow, target eligibility: <reason> and target identity, separated by ,. The labels are fixed text and skip reasons only. Older readers that match the prefix skip: state changed during measurement still match. The bare form, with no labels, is also written when nothing in the snapshot changed but the target's reading went stale under the lock and no fresh target remains.
revalidate: target <name> no longer eligible (<reason>); reconsidered The swap target became ineligible, or its account changed, while the cycle measured, and the cycle decided again under the lock. <reason> is the target's bare skip reason, such as session running, gone, or account changed, or stale reading when the snapshot is unchanged and the target's reading went stale under the lock; it never begins with target eligibility:. The next line is the new swap line, or ALERT: swap refused: <reason> when a pre-swap check refuses the new target.
revalidate: ~/.claude.json held no account; read again Retained diagnostic wording for the bounded retry of trusted credential identity. Session JSON supplies no identity evidence.
skip: the external rotator is running / skip: <error> watch only: the cycle failed with that error and the rotator carries on.
skip: prototype ledger ignored (<reason>) See Rotate live profile. Written only when the reason changes.
wake: ledger changed / wake: reset due / wake: interval watch only: why the wait after the last cycle ended, written before the next cycle; see Rotate wake. wake: interval is written only when the previous wake had another reason.
wake: read <r> of <t> logins, the others from their last reading watch only: a cycle after a limit event or a reset read <r> of the <t> logins it decides on and took the others' figures from their last reading; written after the cycle line. See Rotate wake.
wake: watch rebuilt / wake: unavailable (<cause>), using --interval / wake: lost (<cause>), using --interval watch only: the ledger watch was lost and rebuilt, could not be made, or stopped working. <cause> is fixed text; see Rotate wake. Each is written at most once per process, and none ends the rotator.
stop: signal received; cycle abandoned watch stopped during measurement or before the swap; nothing was moved.
idle: auto-switch is off watch with auto-switch turned off; written once per change.
ALERT: auto-switch is off while the live login is exhausted (<profile>: <reason>) watch with auto-switch turned off, while the live login has no capacity left; see Exhausted while off. Written on every cycle while the condition holds, and does not change what the cycle does.
skip: alert check failed: <error> watch with auto-switch turned off, when a ledger or usage.json cannot be read, so the exhausted-while-off check cannot run. Written on every paused cycle until the file loads again.
change: <setting> <old> -> <new> by pid=<p> ppid=<pp> parent="<command>"[ recipe_run=<id>][ invocation=<id>] The autostart setting or the auto-switch toggle was changed. See Rotate change log.
skip: owner marker not written (<error>) A supervised watch could not write the owner marker. It carries on without one.
skip: held by switch to <name>; run `amplihack profile switch --none` to release The pin holds rotation; the cycle neither measured nor swapped.
skip: pin unreadable; run `amplihack profile switch --none` The pin file cannot be trusted or parsed; the cycle holds.
skip: pin names missing profile <name>; ignored The pin names a removed profile; the cycle runs normally.
sessions archive: <summary> The daily session archive ran; <summary> is the sessions archive summary line, followed by the reason if the run stopped early (the 60-second limit, rotate stop or a signal).
sessions archive: cannot read sessions.daily_archive (<why>); not run The user config file cannot be used to decide whether the daily run is on, so it does not run; see turning the daily run off.
sessions archive: cannot read <key> (<why>); not run <key> is sessions.archive_days or sessions.archive_dest, and the user config file cannot give it a value, so the run does not fall back to the default; see sessions configuration.
sessions archive: <error> The daily session archive did not run, or stopped; <error> is one of the sessions messages or the lock line.
switch <from>-><to> A swap made by profile switch. It has no usage readings, because switch measures no usage, and it does not start with swap, so a search for rotator swaps does not match it.
skip: <name> is already the live login; nothing moved profile switch found <name> already live.
would refresh: expired login in ~/.claude / would seed: record for live profile <L> from a fresh reading / would note: no record for live profile <L>: <reason>; nothing moved; run: amplihack profile seed-record <L> / would swap ... / would block <name> (spend limit) until <time> / would adopt ~/.claude as <name> / would stay / would stay (live probe failed (1/3)) / would stay (held by switch to <name>) / would stay (pin unreadable) / would alert: ... / would recover an interrupted swap (phase <phase>) / would alert: rotate recovery is inconsistent / would alert: the rotate journal is damaged / would recover: <recovered line> / would_refuse <name>: <reason> --dry-run only. would_refuse is printed in place of would swap when the target is an API-key profile that fails its login check.

Identity refusals write an ALERT on every affected rotation cycle; manual switches report the refusal on every attempt. Other ALERTs are written only when their key (no-capacity, no-capacity/known, no-capacity/stay, no-capacity/held, no-capacity/unconfirmed, no-login, hand-change, home-unreadable, ambiguous, inconsistent, auto-switch or refused <reason> for a swap refused under Swap, plus the live profile) differs from the key stored in the ledger. A key is <kind>:<live profile or ->, so no-capacity/known:work is the key of an ALERT: no capacity known line written while work is live; the five no-capacity keys differ so that a change in what is wrong writes a new line, and none holds a count or a percentage. The key is cleared when a cycle stays without alerting or a swap succeeds, so the same ALERT can be written again later. The one-shot rotate still prints a repeated ALERT to stdout on every run; only the unrelated log line is written once. Hand-change notes have no key either; each is written once until its text changes. The hand-change guidance and lost-login ALERTs have no key: they are written on every cycle while their condition holds, and so has the exhausted-while-off ALERT.

Before each write, a log over 1 MiB is renamed to rotate.log.1, replacing the old one. The log is opened with O_APPEND, O_NOFOLLOW and O_CLOEXEC, mode 0600. A log that is not a regular file, is owned by another user, or is readable or writable by group or others is not written to; a warning goes to stderr and its mode is not changed.

Log lines and stdout contain only profile names (with control characters removed), percentages, times, phases, paths under HOME and the root, and fixed text. They never contain account IDs, e-mail addresses, tokens, environment values or Claude's output. The one exception is the redacted parent command line and the run ids in a change: line.

Rotate change log

Every change to the autostart setting or to the auto-switch toggle appends one line to rotate.log, so that a log shows who turned rotation off and when:

2026-11-01T09:14:02Z change: auto-switch on -> off by pid=51877 ppid=51702 parent="bash /home/you/bin/pause-rotation.sh" recipe_run=3f9c2a1e-6b7d-4c1e-9a52-0d8e7b6f4a21
2026-11-01T09:20:45Z change: rotate-autostart on -> off by pid=52011 ppid=4120 parent="-bash"
Field Value
<setting> rotate-autostart for rotate autostart on\|off; auto-switch for any command that changes enabled in <root>/.auto-switch (auto-switch on, auto-switch off).
<old> on or off; unset when there was no setting; corrupt when the setting could not be trusted.
<new> on or off.
pid, ppid The process that wrote the setting, and its parent.
parent The parent's command line, read from /proc/<ppid>/cmdline, with the arguments joined by spaces. - when it cannot be read.
recipe_run The value of AMPLIHACK_RECIPE_RUN_ID, when set and non-empty.
invocation The value of INVOCATION_ID, when set and non-empty.

Only a write that changes the value is logged. autostart off when the setting is already off writes no line, and off then on writes two. A change from unset or corrupt is always logged. Changes to the auto-switch threshold, exclusions or overflow list are not logged, nor are the AMPLIHACK_ROTATE_AUTOSTART and AMPLIHACK_CLAUDE_AUTO_SWITCH variables, which override the settings without changing them.

The parent command line is redacted before it is written:

  • NAME=value becomes NAME=***.
  • A name counts as secret if it contains key, token, secret, passw, auth or signature, or if one of its parts is exactly pass, pwd or sig. So --pass and --db-pwd are secret, but --bypass is not.
  • The argument after a flag with a secret name becomes ***, and so does the value in --flag=value for such a flag.
  • A Name: value or Name:value argument with a secret name, such as the Authorization: Bearer ... or X-Api-Key: ... header passed to curl -H, becomes Name: ***. Other headers, such as Content-Type: json, are left as they are.
  • user:password given to -u or --user (curl -u user:pw, --user=user:pw, -uuser:pw) becomes ***. A value without :, such as git push -u origin, is kept.
  • The value attached to -p, as in mysql -psecret, becomes -p***. A separate argument after -p is kept.
  • user:password@ is removed from URLs, and a query or fragment parameter with a secret name, such as ?access_token=..., #access_token=..., &sig=... or &X-Amz-Signature=..., becomes name=***.
  • An argument holding whitespace, such as the script after bash -c, is split into words, ' and " are dropped from each word's ends, and the words are redacted by the rules above. A secret header name whose value is in the following words, as in -H 'Authorization: Bearer ...', hides every word after it. So bash -c "export API_TOKEN=t; curl ..." is written as bash -c export API_TOKEN=*** curl ....
  • Not redacted: a separate password after -p, as in sshpass -p secret; credentials after combined short flags, as in curl -su user:pw; and --proxy-user user:pw.

For example, claude --api-key sk-abc TOKEN=xyz https://u:p@h/x is written as claude --api-key *** TOKEN=*** https://h/x. Control, newline and bidirectional-override characters are then removed, " becomes ', and the result is cut to 200 characters. The run ids have control characters removed, spaces replaced by _, and are cut to 64 characters. A value can therefore never start a second log line or forge a field.

The line is written through the same path as other log lines, so the mode, symlink and size rules above apply. Writing it takes no lock. If it cannot be written, the command prints one warning to stderr and still succeeds.

Rotate daemon

start, and a launch that autostarts the rotator, launch amplihack profile rotate watch <resolved flags> --spawned with the same amplihack binary, in a new session (setsid) with SIGHUP ignored, stdin from /dev/null, and stdout and stderr appended to rotate.err (0600) beside the log. The log itself is written only by the cycle, so it keeps its grammar; rotate.err holds only what the process prints outside a cycle, such as start-up notices or a crash. --spawned is hidden; it tells watch that start has already written the pid file. No shell is involved.

The child's environment is the parent's, with every AMPLIHACK_ROTATE* variable, CLAUDE_CONFIG_DIR, AMPLIHACK_CLAUDE_PROFILE and INVOCATION_ID removed and AMPLIHACK_CLAUDE_PROFILE_ROOT set to the absolute root start resolved. Removing the profile variables means a rotator started from a --profile launch still probes and swaps ~/.claude. Removing INVOCATION_ID means a rotator started from a shell inside a systemd unit does not claim to be that unit's owner; a --spawned watch never writes the owner marker in any case. The child validates that value again when it starts, and never reads ~/.amplihack/profile-root. Changing the variable or the saved root, or closing the shell that ran start, does not move a running rotator. To move it to another root, stop it and start it again.

AMPLIHACK_PROFILE_USAGE_PROBE, AMPLIHACK_PROFILE_USAGE_TIMEOUT_SECS and AMPLIHACK_PROFILE_USAGE_PARALLEL are kept, so the rotator probes with the values of the shell or launch that started it until it is restarted; see Probe settings in the rotator.

Rotate root record

After writing the pid file, start writes two files that hold the absolute root it started with, in the saved root file format:

File Purpose
<root>/.auto-switch.d/rotate/root Next to the pid file. Shows which root a rotator's state belongs to.
~/.amplihack/rotate-root Lets status and stop find the rotator from a shell whose root now resolves elsewhere. Only the most recent start is recorded.

If either file cannot be written, start prints a warning to stderr and the rotator keeps running.

rotate status and rotate stop locate the rotator as follows:

  1. If a rotator under the resolved root is running, they use the resolved root.
  2. Otherwise, if ~/.amplihack/rotate-root names a different root and the rotator under that root is running, they use that root.
  3. Otherwise they use the resolved root, and report what they find there as they do without a record (rotate: not running for stop).

A record that cannot be read, is invalid, or names a root whose rotator is stopped, stale or unverifiable is ignored. A stale record is therefore harmless: it can only choose which directory's pid file is read, and stop still makes the verified checks before it signals anything.

stop leaves the record in place; the next start replaces it. Rotators running under several roots at once are not supported; the record names only the latest.

A pid file is valid when it holds at most 32 bytes of ASCII digits for a pid greater than 1 that is not the caller's own. A process is a verified rotator when /proc/<pid> is owned by your effective uid, its command line contains profile, rotate and watch, and its argv[0] has the same file name as the running amplihack.

State Condition stop
running Valid pid file naming a verified rotator. Sends SIGTERM (through a pidfd on Linux), polls for 10 seconds, then removes the pid file. If it is still running, keeps the pid file and fails with RotateDaemon.
stopped No pid file. Prints rotate: not running and exits 0.
stale The pid file is invalid, or names no process, or a process that is not a verified rotator. Removes the pid file, signals nothing, prints rotate: removed a stale pid file.
unverifiable No /proc on this host. Signals nothing and fails with RotateDaemon.

watch removes the pid file on exit only if it still holds its own pid.

Rotate signals

watch acts on SIGTERM and SIGINT at these points:

When the signal arrives What watch does
Between cycles Exits at once.
During measurement Stops its probes as it does at the probe deadline (SIGKILL to each probe's process group), writes stop: signal received; cycle abandoned and exits. Nothing is swapped.
After measurement, before step 6 takes the lock Writes the same line and exits without taking the lock.
While it holds the lock (revalidation and swap) Finishes the swap, writes the log lines, releases the lock, then exits.

The swap holds no probe and waits on nothing but local file operations, so stop's 10-second wait covers it. A stop that times out therefore means the process is not responding, not that a cycle was slow.

Rotate status

status takes no lock and changes nothing. It prints key: value lines:

root: /home/you/.claude-profiles (source: config)
rotate: running
autostart: on (default)
owner: none
pid: 48213
live: spare
last cycle: 2026-10-18T12:50:05Z stayed
capacity: headroom 2.07 login-weeks of 4 (52%), usable 2 of 4 logins, runway ~9 h (as of 2026-10-18T12:50:05Z, 3m ago, rotate cycle: probed profiles only)
overflow: -
on overflow: no
hooks repaired: none in the last 24h
log: /home/you/.claude-profiles/.auto-switch.d/rotate/rotate.log

After a step's spend limit blocked the live login login-bf, the next cycle has swapped to spare, and status lists the block:

live: spare
last cycle: 2026-11-20T00:31:05Z swapped
overflow: -
api key: -
blocked logins: login-bf (blocked until 2026-11-24T14:00:00Z)
on overflow: no

With two profiles whose last reading had no session window:

root: /home/you/.claude-profiles (source: config)
rotate: running
autostart: on (default)
pid: 48213
live: spare
last cycle: 2026-10-18T12:50:05Z stayed
overflow: -
api key: -
on overflow: no
no session window: review, weekly
hooks repaired: none in the last 24h
log: /home/you/.claude-profiles/.auto-switch.d/rotate/rotate.log

On credits, with a second overflow profile blocked:

root: /home/you/.claude-profiles (source: config)
rotate: running
autostart: on (default)
owner: none
pid: 48213
live: login-aw
last cycle: 2026-10-24T09:10:05Z stayed overflow=on
overflow: login-aw, team-credits (blocked until 2026-11-01T00:00:00Z)
on overflow: yes (login-aw)
hooks repaired: none in the last 24h
log: /home/you/.claude-profiles/.auto-switch.d/rotate/rotate.log
Key Value
root Always the first line. <path> (source: env\|config\|default) for the resolved root, or <path> (pinned by running rotator) when the rotator was found through the rotate root record. The lines after it describe that root.
rotate running, stopped, stale or unverifiable.
autostart on or off, then the source in brackets: default, setting, env or corrupt. See Rotate autostart. While an owner marker exists, ends with (deferring to <unit>), or (deferring to an unreadable owner marker). When the root fails the privacy check, ends with (skipped: root is not private) instead, and the marker is not read. Unix only.
owner The rotation owner: none; <unit> pid <n> (running); autostart defers to it; <unit> pid <n> (not running); autostart defers to it; run 'amplihack profile rotate owner clear' to release; unreadable; autostart defers to it; run 'amplihack profile rotate owner clear' to release; or not read (root is not private). Unix only.
pid The pid, or -.
live The ledger's live profile, or -.
last cycle The time and outcome (swapped, stayed, stayed-unread, switched, alerted, skipped, idle or held) of the last cycle, or -. stayed-unread is a stay that is not capacity: the live probe did not give a qualifying reading, and it was not an overflow stay read in that cycle. skipped is recorded when the state changed during measurement; switched by profile switch, and kept by the held cycles after it; held when the pin held rotation with no switch record; a cycle that could not take the lock records nothing. An overflow cycle adds overflow=in, overflow=out or overflow=on.
capacity The capacity summary of the newest usage history entry. See Capacity line.
hold Only while something is at the pin path: hold: <name>, hold: <name> (profile missing; ignored) or hold: unreadable.
overflow The marked overflow profiles in list order, separated by ,, each followed by (blocked until <time>) when it has an active spend block; - when none is marked or .auto-switch is corrupt. When the ledger cannot be read, the list ends with (blocks unknown).
blocked logins Printed after overflow and api key, before on overflow: the logins with an active spend block written by a step that overflow does not already show, in name order, separated by ,, each as <name> (blocked until <time>); - when there are none. Read from the same ledger read as overflow. When the ledger cannot be read it prints - and does not append (blocks unknown): that suffix belongs to overflow alone, which already reports the failure on the same output.
api key The first API-key profile, followed by (blocked until <time>, <reason>) while the ledger records an active API-key block; - when there is no API-key profile. Printed between overflow and on overflow.
on overflow yes (<name>, held by switch) when a pin names the live overflow profile: a profile switch onto it is a choice to spend, and the rotator does not move off it until profile switch --none (see Pin and overflow). Otherwise yes (<name>) when the profile identified as live in ~/.claude by account is an overflow profile and the ledger's last_cycle.overflow is in or on, which means the rotator found no plan capacity in its last cycle. no (<name> is overflow; plan capacity remains) when the live profile is an overflow profile but the last cycle carries no such tag, for example after the login was put in ~/.claude by hand. no when it is a plan profile, - when the live profile cannot be identified. status runs no probe; the ledger is its only evidence.
no session window Printed only when the list is not empty: the profiles whose current auto-switch reading has seven_day and no five_hour, sorted by name and separated by ,. These profiles are ranked on their week. The line does not say no session limit: a stored reading also loses its five_hour when a session window was not recorded (see the known limitations under No session limit). Only profiles that exist now are listed. The line comes after on overflow and after the ~/.claude is on API key profile ... line when that is printed, and before default and hold. It is read from usage.json without a lock; if the file is missing, unreadable or unsafe, the line is left out and nothing is printed to stderr.
default Printed only when the default pointer names an overflow profile: <name> (overflow; launches use it directly).
log The log path.
note Zero or one. The current hand-change note, without its note: prefix.
alert Zero or more. A current hand-change ALERT or fix line.
warning Zero or more. A profile that lost its login to a manual /login in ~/.claude.
alert (exhausted) alert: auto-switch is off while the live login is exhausted (<profile>: <reason>), printed after the ledger's alert: and warning: lines when the exhausted-while-off condition holds; or alert: unavailable (<error>) when auto-switch is off and a ledger or usage.json cannot be read, so the condition cannot be checked.

Run from a shell where the root now resolves elsewhere, for example cron with no saved root, status finds the running rotator through the record:

root: /home/you/.claude-profiles (pinned by running rotator)
rotate: running
autostart: on (default)
owner: none
pid: 48213
live: spare
last cycle: 2026-10-18T12:50:05Z stayed
overflow: -
on overflow: no
hooks repaired: none in the last 24h
log: /home/you/.claude-profiles/.auto-switch.d/rotate/rotate.log

Capacity line

status runs no probe, starts no process and does not look for claude. The capacity: line comes from the usage history alone, and follows last cycle::

capacity: headroom X login-weeks of N (P%), usable U of N logins[, M unknown], runway ~H h (as of <time>, <age> ago[, <writer>])

The runway allows for the weekly resets of the next 24 hours, as on the summary's runway line (see Rate and runway). When the headroom lasts the 24 hours it reads runway beyond 24 h (lowest L login-weeks) in place of ~H h. When the newest entry is a rotator entry that left logins out, the runway reads runway ~H h from the <time> entry (this cycle left out M logins) or runway unknown (this cycle left out M logins) instead; that entry's runway uses the resets listed in it, counted from its own time.

The newest valid entry stands in for this run's readings, and its at for now: N is the number of profiles in that entry, the headroom and usable count are worked out from it as in the summary, and the rate uses the entries up to six hours before it. The runway is runway unknown when the rate is.

A rotator entry that lists logins as unknown holds only the logins it probed, which are the idle ones; the busy logins being used up are the ones it left out. Its own runway would divide the idle logins' headroom by their small use and come out far too long, or unknown, just while capacity is being used. So the runway of such an entry is not printed. Instead the line takes the runway of the newest entry no more than six hours older that read every login (a profile usage entry, or a rotator entry with no unknown logins) and names that entry's time: runway ~H h from the <time> entry (this cycle left out M logins). With no such entry, or one with too little history for a rate, it prints runway unknown (this cycle left out M logins). Running amplihack profile usage every few hours while logins are busy gives the line a runway. Weights come from capacity-weights.json; the usable threshold comes from AMPLIHACK_PROFILE_USAGE_USABLE_SESSION_PCT, or 95. <age> is how long before the clock now that entry was written, in the largest whole unit: 45s, 3m, 2h or 1d. An old entry is shown as it is, with its age. When the newest entry came from a rotator cycle, it holds only the profiles that cycle measured, so N may be fewer than all profiles; profile usage with no names records every profile it could read. So that a change in N between cycles is not read as a change in usage, the line names the writer of the entry after its age: rotate cycle: probed profiles only or profile usage: all logins. An entry written before the writer was recorded names none. When the entry lists logins its writer could not read, , M unknown follows the usable count; they are in no figure. A rotator entry lists there the logins it skipped as busy, those with no usable trusted identity and those whose probe failed, so M says how many logins the line leaves out. When a profile in that entry has a weight other than 1.0, the line adds [weighted: X' of T] after (P%), as in the summary.

History Line
No file, or no readable entry capacity: no recorded cycle
A file that is refused (see Usage history) capacity: no recorded cycle, and warning: usage history ignored (unsafe file) on stderr
Newest entry has no profiles capacity: headroom unknown (no valid readings), usable 0 of 0 logins, runway unknown (as of <time>, <age> ago)

A pending or inconsistent journal adds a line journal: pending (phase <phase>) or journal: inconsistent, and one that cannot be read journal: damaged. A ledger that cannot be read shows live: - (ledger unreadable), or live: - (ledger unreadable: <field>) when a field was refused, with the same fixed text as the unreadable-ledger stop. When the ledger names no live profile and the excluded profiles cannot be worked out (the auto-switch config is unreadable, so every profile counts as excluded, and the profile store cannot be listed), status shows live: unknown (excluded profiles unreadable: <cause>) rather than live: -, which would say that nothing is live.

The line before log: counts the rotator's repairs of amplihack's hooks block in the last 24 hours (issue #2279): hooks repaired: none in the last 24h, or hooks repaired: N in the last 24h (last <time>); something is still removing amplihack's hooks. Each settings.json file the cycle rewrote counts once. See the hooks block reference.

Under a systemd unit that owns rotation, status shows the owner and the deferral:

root: /home/you/.claude-profiles (source: config)
rotate: running
autostart: on (default) (deferring to amplihack-rotator.service)
owner: amplihack-rotator.service pid 48213 (running); autostart defers to it
pid: 48213
live: spare
last cycle: 2026-11-01T09:30:05Z stayed
capacity: no recorded cycle
overflow: -
on overflow: no
hooks repaired: none in the last 24h
log: /home/you/.claude-profiles/.auto-switch.d/rotate/rotate.log

status reads the owner marker only after the root has passed the same privacy check autostart uses at step 2 (a real directory owned by you and not writable by others). When the root fails it, the marker is not opened, and status prints these two lines, because a launch stops at step 2 and starts no rotator whatever the marker holds:

autostart: on (default) (skipped: root is not private)
owner: not read (root is not private)

owner: unreadable always has the full form in the table above; it means the root is private and the marker failed one of the checks. status reads the marker and the usage readings without a lock and changes nothing.

With auto-switch off and the live login exhausted:

root: /home/you/.claude-profiles (source: config)
rotate: running
autostart: on (default)
owner: none
pid: 48213
live: spare
last cycle: 2026-11-01T10:10:05Z idle
capacity: no recorded cycle
overflow: -
on overflow: no
alert: auto-switch is off while the live login is exhausted (spare: 100% used, threshold 90%)
hooks repaired: none in the last 24h
log: /home/you/.claude-profiles/.auto-switch.d/rotate/rotate.log

After last cycle: and capacity:, status prints each line of the ledger's guidance: a hand-change note as note: <text>, any other line as alert: <line>. Then it prints one warning: <line> for each profile in its lost_login. It does not compare accounts itself; it shows what the last cycle decided. Lines are cleaned of control characters again before printing:

live: login-ay
last cycle: 2026-10-27T03:17:05Z alerted
note: ~/.claude holds the same account as profile login-aw (ledger names login-ay); nothing moved, the next cycle reads again

A confirmed suspicion that the only-login rule refuses shows the ALERT and its fix lines instead:

live: login-ay
last cycle: 2026-10-27T03:19:05Z alerted
alert: ~/.claude holds the same account as profile login-aw on two readings (ledger names login-ay), but login-ay has no login of its own, so recording login-aw would leave login-ay with no login anywhere; nothing moved, no swap
alert: fix 1: if a /login in ~/.claude replaced login-ay's login: close every claude session that uses ~/.claude, then run: mkdir -m 700 <dir> && mv -n <root>/login-aw/.credentials.json <dir>/ && rm <ledger>; then run: amplihack profile login login-ay
alert: fix 2: if login-ay and login-aw are profiles of one account, run amplihack profile verify to see the account each folder holds, then remove one of the two profiles

Recovery no longer adds profiles to lost_login; a warning: line appears only for an entry an earlier release wrote:

live: login-aw
last cycle: 2026-10-27T03:22:05Z stayed
warning: profile login-ay has no login anywhere: a manual /login in ~/.claude replaced it. Run: amplihack profile login login-ay

Rotate autostart

On Unix, amplihack claude, amplihack launch and amplihack profile run start the background rotator when auto-switch is on and no rotator is running. The check runs after the launch has resolved its profile and before Claude starts. It never fails the launch, never changes its exit status and never writes to stdout. On other platforms it does nothing.

It checks, in order, and stops at the first that fails, silently except at step 4. Nothing is created on disk before step 9.

Step Check When it fails
0 AMPLIHACK_RECIPE_RUN_ID is unset or empty, so the launch is not a step of a recipe run. Skipped (recipe-run). Nothing is read, created or printed.
1 Auto-switch is on: <root>/.auto-switch says enabled=on, or AMPLIHACK_CLAUDE_AUTO_SWITCH=1. A missing, damaged or off setting counts as off. No effect.
2 The root exists, is a real directory (not a symlink) owned by you, and is not writable by other users. Skipped. Nothing else under the root is read; in particular neither the owner marker nor the autostart setting is.
3 The effective uid is not 0. Skipped. rotate start still works as root. Root never acts on the owner marker.
4 There is no owner marker. Deferred. Nothing is started or created. Silent when the owner is running; otherwise one line to stderr, shown below.
5 Autostart is on (see the precedence table below). No effect.
6 Not Docker: no --docker flag, and Docker not activated through the environment. The environment activates it only when AMPLIHACK_USE_DOCKER is truthy, the process is not already inside a container, and Docker is running. --auto launches are not skipped. Skipped.
7 The daemon state is not running or unverifiable. Already running, or skipped.
8 The prototype lock is free and the root is private, as start requires. Skipped.
9 Creates the state directory if needed and tries <root>/.auto-switch.d/lock once, without waiting. Busy: another process holds it.
10 Under the lock, the daemon state is still not running. Already running.
11 The AMPLIHACK_ROTATE_* settings in the launch's environment are valid. Failed; no rotator started.
12 Starts the daemon, writes rotate.pid and the root record, then releases the lock. Failed. If the pid file cannot be written, the child is sent SIGTERM.

Steps 9 to 12 run under the state lock, and start and other launches check under the same lock, so at most one rotator runs per root. Unlike start, autostart runs no recovery; the daemon's first cycle does.

After step 12 the launch prints one line to stderr:

amplihack: started Claude login rotator (pid <pid>); 'amplihack profile rotate autostart off' to disable

and appends autostart: started pid <pid> exe <path> to rotate.err. A failure at step 11 or 12, or an I/O error at step 9, is appended to rotate.err as one autostart: failed: <error> line, when that file can be written, and is otherwise ignored. Every rotate.err line has the log time prefix and its control characters removed.

At step 4, a marker whose owner is not running gives one stderr line per launch:

amplihack: rotation is owned by amplihack-rotator.service, which is not running; run 'amplihack profile rotate owner clear' to let launches start the rotator

A marker that cannot be read or trusted gives:

amplihack: the rotation owner marker is unreadable; run 'amplihack profile rotate owner clear' to let launches start the rotator

When autostart is off, launches still defer to the marker, but the line stops after which is not running or is unreadable and gives no advice: clearing the marker would start nothing.

Neither line fails the launch, and neither is written to rotate.err.

Launches inside a recipe run never start the rotator: amplihack recipe run sets AMPLIHACK_RECIPE_RUN_ID for its steps, and step 0 stops there. A recipe run therefore cannot start a second rotator beside one run by a service manager or by hand. A top-level launch, outside any recipe run, starts one as before. The Claude Code SessionStart hook does not start the rotator.

Autostart setting

AMPLIHACK_ROTATE_AUTOSTART <root>/.auto-switch.d/rotate/autostart Effective Status line
1 or on any on autostart: on (env)
0 or off any off autostart: off (env)
unset, empty or invalid missing on autostart: on (default)
unset, empty or invalid on on autostart: on (setting)
unset, empty or invalid off off autostart: off (setting)
unset, empty or invalid anything else off autostart: off (corrupt)

The variable is case-insensitive. Any other value is ignored, and a process that reads it prints warning: ignored AMPLIHACK_ROTATE_AUTOSTART value (use on, off, 1 or 0); the setting decides to stderr once, without repeating the value.

The setting file is read without following symlinks and only up to 64 bytes. It counts as corrupt when it is a symlink, is not a regular file, is not owned by you, is longer than 64 bytes, cannot be read, or holds anything but on or off and an optional newline. rotate autostart on|off replaces it atomically with mode 0600, creating <root>/.auto-switch.d/rotate/ first if needed.

When the variable is set to a valid value, rotate autostart on|off still writes the file, and then warns on stderr that AMPLIHACK_ROTATE_AUTOSTART=<value> overrides it in this environment.

rotate autostart on|off is the only command that writes the file. When the write changes the value, it appends a change: line to the log, for example change: rotate-autostart on -> off by pid=52011 ppid=4120 parent="-bash".

Rotate owner

A rotator run by a service manager, such as a systemd user unit, records itself as the rotation owner. While it is recorded, launches do not start a second rotator: step 4 of autostart defers to it, even when autostart is on.

The marker defers autostart only. rotate start does not read it: while the owner is running, start refuses because a verified rotator is already running, and while it is not, start starts a rotator as usual. That rotator then makes the unit's next watch refuse.

A supervised watch refuses like any other watch when a verified rotator is already running, whether started by autostart, by rotate start or by hand. It exits with status 1 before writing the marker, so the service manager restarts it and it keeps failing until that rotator stops. Run amplihack profile rotate stop before you enable the unit.

Owner marker

The marker is <root>/.auto-switch.d/rotate/owner:

unit=amplihack-rotator.service
pid=48213
since=1793524205

unit is the unit name, pid the rotator's pid and since the epoch seconds, in decimal, when it was written. The keys are written in that order. since is informational: no decision reads it, and a missing, duplicated or malformed since does not make the marker unreadable.

rotate watch writes the marker when all of these hold:

  • it was not started with --spawned, so it is not a child of rotate start or of autostart;
  • it was given --supervised or --supervised=<UNIT>, or INVOCATION_ID is set and non-empty and step 2 of Owner unit name finds a unit;
  • it has taken the state lock and written rotate.pid.

The marker is written atomically with mode 0600, never through a symlink and never over a file owned by another user. If it cannot be written, watch logs skip: owner marker not written (<error>) and runs without one.

Nothing removes the marker except rotate owner clear. A watch that exits, rotate stop, rotate start and a watch without --supervised all leave it in place. When the service manager restarts the unit, the new watch replaces it with its own pid. An unsupervised watch that finds a marker prints one note to stderr and then runs as usual:

rotate: rotation is owned by amplihack-rotator.service; this watch runs anyway and leaves the owner marker in place

Owner unit name

The unit name is the first of:

  1. the value of --supervised=<UNIT>, which must be 1 to 256 bytes with no =, control character or bidirectional-override or isolate character (U+202A to U+202E, U+2066 to U+2069); any other value is refused with RotateRefused (--supervised=UNIT needs a unit name of 1 to 256 bytes without '=', control or bidi characters, status 1);
  2. the last component of the path in /proc/self/cgroup (read up to 4 KiB, preferring the cgroup v2 and name=systemd lines), when it ends in .service and is not a user manager (user@<uid>.service); this is where systemd places a service's processes, while a shell started from a tmux or terminal server ends in .scope and has no unit here;
  3. amplihack-rotator.service.

Reading the marker

A marker is read only from a regular file, opened without following symlinks and without blocking, that is owned by you, is not writable by group or others, and is at most 4 KiB. It holds key=value lines. It is unreadable when any of these checks fails, when unit or pid is missing (a marker with only one of them, or an empty file, is unreadable) or appears twice, when pid is not a positive decimal number without a sign, or when unit is empty, longer than 256 bytes, or contains = or a control character. Unknown keys are ignored.

An unreadable marker still counts as an owner, so autostart defers. A damaged or foreign file at that path therefore cannot let a stray rotator start; run rotate owner clear to remove it. Neither stderr nor status ever prints the marker's bytes.

Owner liveness

The owner is running when /proc/<pid> exists and is owned by your effective uid, and its command line, read up to 64 KiB, is a verified rotator: it contains profile, rotate and watch, and its argv[0] has the same file name as the running amplihack. Otherwise it is not running. A recycled pid that now belongs to some other program is therefore not running. If the name of the running amplihack cannot be found, status and rotate owner print owner: <unit> pid <n> (liveness unknown); autostart defers to it instead of claiming the owner has stopped.

Marker Owner Autostart (step 4) status
none - Carries on to step 5. owner: none
valid running Defers silently. owner: <unit> pid <n> (running); autostart defers to it
valid not running Defers, and prints the which is not running line to stderr. owner: <unit> pid <n> (not running); autostart defers to it; run 'amplihack profile rotate owner clear' to release
unreadable - Defers, and prints the unreadable line to stderr. owner: unreadable; autostart defers to it; run 'amplihack profile rotate owner clear' to release

Clearing the owner

amplihack profile rotate owner clear
owner: cleared (was amplihack-rotator.service)

clear removes the path itself; a symlink there is removed, and its target is left alone. It prints owner: cleared (was unreadable) for an unreadable marker and owner: none when there is nothing to remove. It does not stop a rotator. If the path cannot be removed, it fails with status 1.

Run it when you retire the service: stop and disable the unit, then clear the owner, so that launches start the rotator again. Leaving a stale marker in place is safe; launches defer and warn until it is cleared.

Owner limitations

  • INVOCATION_ID is inherited by every process in a systemd unit. A shell started from a tmux or terminal server that the user manager runs sits in a .scope, so a rotate watch started from it does not claim ownership. A rotate watch started by hand from a shell whose cgroup is itself a .service unit does record itself as the owner. Run rotate owner clear after stopping it. rotate start and autostart are not affected, because they remove INVOCATION_ID from the child.
  • An amplihack binary older than this feature ignores the marker and may still start a rotator from a launch. Upgrade every binary that launches Claude against the root.
  • rotate status prints the owner: line straight after autostart:, so a script that reads status by line number finds pid: one line lower.

Exhausted while off

When auto-switch has been turned off and the live login has no capacity left, nothing moves work onto another login. The background rotator reports this as an ALERT on every cycle, and rotate status as an alert: line:

2026-11-01T10:10:05Z ALERT: auto-switch is off while the live login is exhausted (spare: 100% used, threshold 90%)

The condition holds when all of these are true:

  1. Auto-switch has been turned off: auto-switch off, AMPLIHACK_CLAUDE_AUTO_SWITCH=0, or a corrupt <root>/.auto-switch. With no auto-switch setting at all, it is not off.
  2. The rotate ledger names a live profile, and the auto-switch ledger maps it to the profile whose login it holds.
  3. That profile has a reading in usage.json, and either:
  4. the reading's source is a usage-limit failure whose reset time is still in the future, giving usage limit reached, resets <time> (the latest such reset), or
  5. the higher of its session and weekly percentages is at or above the auto-switch threshold, giving <pct>% used, threshold <t>%. A window whose reset time has passed counts as 0%, as it does for candidate selection: usage.json is not refreshed while sessions are stopped, so its stored percentage is out of date once the window resets. A usage-limit failure whose reset has passed is therefore no ALERT, whatever percentage it recorded.

The reason has exactly one of two forms:

Form Values
<pct>% used, threshold <t>% <pct> is the higher percentage rounded down to a whole number, so 99.7 is written 99; the comparison with the threshold uses the unrounded value. <t> is the threshold as a whole number.
usage limit reached, resets <time> <time> is the reset time in the RFC 3339 UTC form the log uses for its own timestamps, to the second with a Z suffix, for example 2026-11-01T14:00:00Z.

When both apply, the usage-limit form is used. The same text appears in the log line and in the alert: line of rotate status.

No rotate ledger, no live profile, a live profile with no reading, and a non-finite percentage or threshold all give no ALERT. A rotate ledger, auto-switch ledger or usage.json that exists but cannot be read is not taken as "not exhausted": watch writes skip: alert check failed: <error> on every paused cycle instead, and rotate status prints alert: unavailable (<error>). The check takes no lock, runs no probe and writes nothing. The ALERT does not change what the cycle does: the rotator stays idle, and idle: auto-switch is off is still written only once per change. Turn auto-switch back on, or switch logins by hand with profile switch, to act on it.

Rotate daily session archive

rotate watch, including the background rotator, runs amplihack sessions archive --apply at most once a day, so old session logs do not build up in ~/.claude/projects. It is on by default, and the config key sessions.daily_archive turns it off.

After each pass of the watch loop, before it sleeps, and whether or not the rotator is idle or held by a pin, the rotator reads <root>/.auto-switch.d/rotate/sessions-archive.last. The archive is due when:

  • the file is missing, or does not hold a whole number of epoch seconds;
  • 86,400 seconds or more have passed since the time it holds; or
  • the time it holds is in the future, because the clock went back.

When the archive is due, the rotator reads sessions.daily_archive from ~/.amplihack/config.toml (see switching it off). If the key is false, nothing runs and nothing is written. Otherwise the rotator writes the current time to the file before the archive starts. A crash, a held lock or an error therefore waits a full day before the next attempt, rather than retrying every cycle. If the file cannot be written, the archive does not run and the log gets sessions archive: cannot record the run time (<kind>); not run.

The archive runs inside the rotator process, with the days and destination from the config keys sessions.archive_days and sessions.archive_dest, read from the same file at the same time as the switch, or their defaults (3 days, ~/.amplihack/session-archive). amplihack sessions archive and sessions restore in a shell read the same keys, so restore looks in the directory the daily run wrote to. If the file cannot give either key a value, the archive does not run, the time file is already written, and the log gets sessions archive: cannot read <key> (<why>); not run. See sessions configuration.

One pass archives for at most 60 seconds, so a large backlog never holds up rotation for longer than that. The rotator checks the limit, and its stop flag, between sessions, so a pass can run past 60 seconds by the time one session takes, and rotate stop or a signal ends the run after the session in progress. A run that stops early ends its summary line with the reason:

  • ; stopped at the 60-second limit; the rest continues at the next pass
  • ; stopped by rotate stop or a signal; the rest continues at the next pass

and the rotator removes the time file, so the next pass, after the next cycle, carries on where the run stopped. The first run over a backlog of thousands of sessions is therefore spread over several passes. If a run stops early without archiving any session, the summary ends with ; nothing archived, so the next try is a day later instead, and the time file is kept, so sessions that keep failing are not retried on every pass. If the file cannot be removed, the log gets sessions archive: cannot remove the run record (<kind>); the rest waits a day.

Its summary line, or one error line, goes to the log with the prefix sessions archive:, for example:

2026-10-29T03:15:00Z sessions archive: archived 412 sessions, 0.11 GiB (older than 3 days; 7 live sessions kept; 0 failed)

Each session the archive skips or fails also gets its own line, such as sessions archive: skipped <project>/<id>: symlink; see the sessions messages. No error from the archive stops or changes the rotation cycle.

The run moves old logs into the archive directory; it does not delete them. Nothing removes archives from that directory, so it keeps growing, at roughly a quarter of the rate the session logs grew. See sessions disk use for its size, how to move it to another disk and how to delete old archives.

Turning the daily run off

The switch is the user config key sessions.daily_archive:

amplihack config set sessions.daily_archive false

true, or no value, means on. The rotator reads the key from ~/.amplihack/config.toml each time a run is due, so the change reaches a rotator that is already running, without a restart. Turn the run back on with amplihack config set sessions.daily_archive true, or remove the key with amplihack config unset sessions.daily_archive. The key is user-only: a project's .amplihack/config.toml cannot set it, since it decides whether files under ~/.claude/projects are removed. See user config.

The switch is a config key, not an environment variable, because the background rotator does not inherit the launching shell's AMPLIHACK_ROTATE* variables (see Rotate daemon): a variable set where rotate start or autostart runs would never reach it.

Because the run removes files, a config file the rotator cannot use stops it rather than counting as on. When the file cannot be read or parsed, the key holds a value other than true or false, or the file is writable by group or others, the archive does not run, the time file is written so the next try is a day later, and the log gets sessions archive: cannot read sessions.daily_archive (<why>); not run.

Days and destination are config keys for a related reason. A rotator keeps the environment it was started with, and one started by autostart takes it from whichever launch started it. A variable exported later in a shell would therefore reach sessions restore in that shell but not the rotator, and restore would look for the session in a different directory from the one the daily run wrote to.

Rotate prototype coexistence

Before a non-dry-run rotate, start or cycle, the rotator opens <root>/.rotator/lock read-only (O_NOFOLLOW, O_NONBLOCK, never O_CREAT), checks that it is a regular file, tries a non-blocking exclusive lock, and releases it at once. A missing file passes the check and is not created. If the lock is held, the command fails with RotatePrototypeRunning. --dry-run skips this check. The rotator never creates, writes or deletes anything under <root>/.rotator/. A supervised step that hits a far reset makes the same check to decide whether a capacity wait may start. While it holds the lock, an external rotator that takes it with LOCK_NB at that instant is refused once; the check holds the lock only for the length of two system calls.

Rotate exit status

Status When
0 No swap, a swap, a held cycle, a dry run, an ALERT, status, a stop of a stopped or stale rotator, a successful profile switch.
1 RotateConfig, RotatePrototypeRunning, RotateInconsistent, RotateRefused, RotateUnsupported, RotateDaemon, or any other error.
2 A usage error from argument parsing, such as a tuning flag before start.

Rotate session resume

amplihack-hooks limit-resume is a Claude Code StopFailure hook that restarts a session which stopped on a usage limit, once the rotator has swapped ~/.claude to a login with room. amplihack install registers it; see StopFailure in the hook reference. The how-to shows how to use it. The hook reads the rotate ledger, the swap record and its own resume state, and may run tmux against the session's own pane. When its environment names no pane, it also reads the tmux pane ids and ttys from one list-panes listing, matches them to the session's terminal and drops them. From the session's transcript it reads only the timestamp of the last entry (see Stop time). It never moves a login, never reads any other part of the transcript, and never opens .credentials.json, a token file or anything under a profile directory.

The hook resumes a session in one of two ways, never both:

  • Keys (outcome resumed-keys, exit 0): when the session runs in a proved tmux pane that is showing a screen the keys answer, it types Esc, Ctrl+U, continue and Enter into that pane. The exit 2 wake has not released Claude Code's usage-limit menu in the standing sessions reported in #2695, so such a session gets the keys.
  • Wake (outcome not-resumed with detail=no-tmux-pane, pane-unverified or screen-unrecognised, exit 2): otherwise it exits 2 with the resume message on stderr. Nothing was typed and nothing was recorded, so the event stays armed and the next room event tries again. The outcome says why the keys path was not taken. For screen-unrecognised a second fixed line precedes the resume message.

Every other outcome exits 0 and writes nothing to stdout. It writes nothing to stderr either, except one fixed line when a log line or the root could not be written or resolved (see Resume log). The hook never writes to stdout and never exits with any other status. A panic exits 0, after one attempt to log panicked. The resume message is exactly:

amplihack: the login rotator reports a login with capacity. Continue the task you were working on; if the usage limit is still in place, stop and wait.

Claude Code shows it to the model as a system reminder and starts a new turn. The message does not claim the limit is gone: the rotator's reading can be wrong, so the model is told to stop again if it is not.

For screen-unrecognised alone, one further fixed line is written first, so the refusal is not left to the log:

amplihack: limit-resume proved this session's terminal but did not recognise what it was showing, so it typed nothing into it. If a usage-limit prompt is still there, press Esc and continue the session by hand.

The hook relies on Claude Code behaviours that a live check against Claude Code 2.1.306 confirmed (not re-read at 2.1.329). It used a stub StopFailure hook with asyncRewake: true, triggered by an invalid API key (matcher authentication_failed):

  • a turn that ends on an API error runs StopFailure, not Stop;
  • the payload has session_id, transcript_path, cwd, hook_event_name, error and last_assistant_message, plus prompt_id and an effort object, which the hook ignores;
  • in an interactive session, exit 2 starts a new turn with stderr shown to the model as a system reminder. With claude -p the process exits first, so there is no new turn;
  • the payload has no stop_hook_active, not even on the failure of the turn the hook started. A repeated failure is stopped by the event marker instead: the event key leaves out prompt_id, so the same error text in the same session gives the same key.

A second live check, on Claude Code 2.1.307 with a real weekly limit, showed the usage-limit path itself: the stop ran StopFailure with error: "rate_limit", last_assistant_message set to the limit text ("You've hit your weekly limit · resets …") and no stop_hook_active; the hook's exit 2 closed the "What do you want to do?" limit menu and started a new turn. That turn hit the same limit and sent an identical payload, which is why a repeated event on the same login is a duplicate and never resumes again.

Claude Code's timed wait (Usage limit reached · continuing automatically {when} · esc to cancel) is not covered by either check. The strings of the Claude Code 2.1.319 binary (read at that version, not reproduced, and not re-read at 2.1.329) show the wait behind a feature flag, with Continuing automatically {when} · Esc to cancel, Usage limit reached again · …, /usage-credits to continue now and /rate-limit-options to re-arm. They do not show whether StopFailure runs when the wait starts or whether an exit 2 ends it. Esc is the exit the wait names, so the hook sends keys whenever it has a pane proved to be its own terminal and uses the exit 2 wake only when it does not.

Resume decision

The checks run in this order. The first one that fails decides the outcome.

Step Check When it fails
1 The profile root resolves (AMPLIHACK_CLAUDE_PROFILE_ROOT, then ~/.amplihack/profile-root, then ~/.amplihack/claude-profiles) to an absolute path with no .. component. The pointer file must not be writable by group or others, and auto-switch is on by the same rule as auto-switch status. The pointer file is read with no-follow and at most 4 KiB. Root not resolved: exit 0. Nothing under the root is created or written, and nothing is logged because there is no log to reach; one fixed line goes to stderr. Auto-switch off: exit 0, outcome disabled. The line is appended only if a private resume/ folder already exists. The hook never creates it, so a host that has never rotated gets no new file. With no resume/ folder nothing is created and no log-write-failed marker is written; the call is recorded by one fixed stderr line with reason dir_missing.
2 Standard input is a JSON object of at most 1 MiB. The stop was a usage limit (see Limit detection), and session_id is present, at most 256 bytes and valid. Exit 0, with outcome bad-payload for input that is malformed or too large, not-limit for a stop that is not a usage limit (this includes input whose hook_event_name is not StopFailure), and bad-session-id for a missing, oversized or invalid id, with session=-. The limit test runs before the id check, so a not-limit line shows the 12-digit session prefix when session_id is valid and session=- when it is not. A not-limit line always has event=-, because no event claim is made.
3 stop_hook_active is absent, null or false (any other non-boolean value counts as true). Before this check the hook reads the ledger once, for its live profile. When the check passes, it reads the stop time, notes the current swap record and the session's last resume, and works out the login the session stopped on for the event key. When it fails, none of the transcript, the swap record or the resume state is read. Exit 0, outcome stop-hook-active.
4 No marker exists for this limit event. Exit 0, outcome duplicate, or guard-failed if resume/ or one of its subdirectories is unsafe (see Resume state directory).
5 The session's record of earlier resumes is read, and its count is kept for the log. No count refuses a resume. A record that cannot be parsed is treated as no earlier resumes, and one session-record-reset line is logged. Exit 0, outcome guard-failed if resume/ or one of its subdirectories is unsafe.
6 The rotator is running: <root>/.auto-switch.d/rotate/rotate.pid names a running amplihack profile rotate watch process of yours (checked in /proc; skipped where there is none), and the ledger, if present, can be read by the trust rules in Rotator capacity rule. Exit 0 without waiting, outcome rotator-down.
7 resume/ and resume/prompted/ exist or can be created safely, so a prompt during the wait can be recorded; prompt markers older than 7 days and 1 hour are removed. Exit 0, outcome guard-failed.
8 The hook keeps the swap record it noted in step 3 (or that there was none), sets up the event wait, and reads the swap record once. Then it waits for a record that passes Capacity for a resume, for at most 7 days from its start. A record that fails is logged (swap-stale or swap-no-room) and the wait goes on. Exit 0, outcome watch-lost if the wait cannot be set up or a watch is lost; moved-on if you sent a prompt in that session; session-gone if the session exited; no-capacity-timeout at the 7-day deadline; guard-failed if a prompt marker cannot be read safely.
9 Auto-switch is still on, no prompt was sent in the session since the hook started, and the hook has a pane (the named pane, or the single pane on the session's terminal, see Resume keys) that passes its check and is showing a screen the keys answer; otherwise the wake is used instead, with outcome not-resumed, pane-unverified or screen-unrecognised, and the hook reads the event marker and the session's last resume once more, without the lock and writing nothing (duplicate if either applies; guard-failed is logged and the wake still given if the read fails). On the keys path, under the resume lock, steps 4 and 5 still pass, the session has no resume after this hook's start, the event marker is created and the session record is updated and synced to disk. Exit 0, outcome disabled if auto-switch was turned off; moved-on if a prompt was sent; duplicate if another hook resumed this event or this session first; guard-failed if the lock is not taken within 5 seconds or any write fails.
10 With a pane: send the resume keys. Exit 0, outcome resume-keys-failed, with the number of keys sent. The hook releases the marker and its session time under the lock, so the event stays armed, and does not exit 2. If the release fails, guard-failed is logged first and the event stays used.
11 No further check Exit 0, outcome resumed-keys, when keys were sent; exit 2 with the resume message when there was no keys path: outcome not-resumed with detail=no-tmux-pane for no pane named or found, pane-unverified for a pane that was not proved to be this session's terminal, screen-unrecognised for a proved pane that was not showing a screen the keys answer.

Steps 4 and 5 run once without the lock, so a duplicate session exits at once instead of waiting up to 7 days, and again under the lock in step 9. The lock is not held while waiting in step 8. The choice between keys and the wake is made before any commit. Only the keys path commits: the marker and session record are on disk before the first key, and a failed key releases them. A wake writes nothing, so a session that was not typed into is resumed at the next room event.

A session is resumed with keys at most once per waiting period. When two hooks wait for the same session with different events, the first to commit resumes it; the other finds a resume after its own start time and ends as duplicate, or, if keys typed continue first, as moved-on. A new limit that starts in the same second as the previous resume may still resume.

No resume cap

The hook has no limit on how many times it resumes one session. A resume happens only when a login with room is live, so each one follows real capacity, and the event marker and the last-resume rule above stop duplicates. A session that hits four limits in a day is resumed four times. Earlier versions refused a fourth resume in 24 hours, which left a supervisor session stopped for hours after a login had room again. The session record keeps the resume times and resume.log shows their count as resumes=<n>, as evidence only.

Moved on

The session moved on when you sent a prompt in that session during the wait. amplihack's UserPromptSubmit hook (amplihack-hooks user-prompt-submit) records the time of each prompt in resume/prompted/<sha256 hex>, moving the file into place. The waiting hook is woken by that move, reads its own session's marker, checks it again right before the commit in step 9, and exits 0 with outcome moved-on when the time is after its own start. A marker for another session wakes the hook, which reads its own marker and goes back to waiting. The hook's own exit 2 wake is not a prompt, so the woken turn does not count. The continue the resume keys type is a prompt: it ends any other hook waiting for the same session as moved-on. Background task reports and local commands such as /usage are not prompts, so they never end the wait.

The prompt hook writes the marker only when the profile root resolves and resume/ already exists as a private directory. A waiting hook creates resume/ before it starts waiting, so even the first wait sees a prompt, and nothing is created for a user whose sessions never hit a limit with auto-switch on. The prompt hook takes no lock, does not sync the marker to disk, and ignores every error, so it never fails or holds up a prompt.

Limit detection

The stop is a usage limit unless error is one of these values, which Claude Code 2.1.329 uses for failures that are not a limit:

authentication_failed, oauth_org_not_allowed, account_on_hold, verification_required, overloaded, invalid_request, model_not_found, server_error, max_output_tokens and cloud_credential_error.

The values are compared exactly and case-sensitively. So rate_limit, billing_error, unknown, an absent error, an error that is not a string and any value not yet seen are all limits. The installed hook has matcher rate_limit, so Claude Code decides which calls arrive; a renamed limit value therefore cannot end a call silently. Message text (last_assistant_message, error_details) is never matched.

This rule is not an authorisation to type. Keys still need the swap record, the proved pane, a screen the keys answer and the event claim, so a stop that is not a limit never gets keys. It exits 0 as not-limit only when its error is in the list above. A stop classed billing_error is accepted by this rule but reaches the hook only if the registered matcher is widened.

Standard input is read up to 1 MiB; a larger payload or one that is not a JSON object exits 0 as bad-payload. A known field of an unexpected type (for example error_details sent as an object) is read as absent, so it neither stops the hook nor reaches the event key.

Capacity for a resume

Only a swap record resumes a session. When the hook starts waiting it notes the record in swap.json, or that there is none. Each record it reads afterwards is judged in this order:

Order Check Result when it holds
1 The file is missing or unreadable, or the record equals the noted one in every field and is stale by the rule in order 2. Nothing logged; keep waiting.
2 swapped_at is before the threshold (swapped_at < min(stop, start - 1), or swapped_at < start - 1 when there is no stop time), or at or before the session's last resume. reading.measured_at is not checked: the rotator measures before it swaps, so a session that stops between the two stopped on the login being swapped away from. Log swap-stale; keep waiting.
3 The record has overflow and overflow.spend_block is true; or the record has no overflow and reading.session or reading.week is 100 or more. A record with overflow and no spend block has room whatever its figures. Log swap-no-room; keep waiting.
4 — Resume (step 9 of Resume decision).

The threshold is the earlier of two times, both whole seconds:

  • the stop time, the timestamp of the last entry in the session's transcript, rounded down;
  • one second before the hook's start (STOP_SLACK_SECS, 1 second).

The rotator takes swapped_at when the swap has finished. A swap in the hook's start second, or in the second before it, may have finished after the stop and is not stale, whether or not a stop time was read. When the hook starts some seconds after the stop, the stop time lowers the threshold, so a swap between the stop and the hook's start still counts. With stop T and start T+10, a swap at T+3 resumes the session and a swap at T-5 does not. The stop time never raises the threshold above start - 1, so a swap that counts without a stop time also counts with one. The same rule applies to the noted record: a swap that finishes between the stop and the hook's start is the record the hook notes, and it resumes the session at once when the new login has room. The cost of the allowance is that a swap made just before the stop can send the session one continue it did not need; without it, a session stopped on the outgoing login would wait for the next swap, up to 7 days.

A swap at or before the session's last recorded resume is never treated as after the stop, whatever the times: the session ran again after that resume, so it stopped later. A resumed session that hits a limit again within a second is therefore not woken twice on one swap; it waits for the next one.

seq is never compared for order. A record that differs from the noted one in any field and passes the time checks counts, so a rotator whose seq started again at 1, for example after swap.json was deleted, still resumes sessions, and a record rewritten unchanged never does.

So a record written before the stop never resumes a session. A session that stops on the login the rotator has just swapped to waits for the next swap. A stay, an ALERT, a profile switch and the passing of time never resume a session, because none of them writes a swap record. The hook does not read the target login or apply the rotator's thresholds; it trusts the reading in the record.

Stop time

The stop time is the timestamp of the last complete entry in the transcript named by the payload's transcript_path, as whole epoch seconds, rounded down. It is read once, after the stop_hook_active check in step 3 of Resume decision passes, by swap_record::read_stop_time in amplihack_utils::rotator_status:

Rule Detail
Open O_NOFOLLOW, O_NONBLOCK and O_CLOEXEC. A symlink as the last path component is refused; symlinks in parent directories are allowed, because the checks below apply to the opened file. A FIFO does not block the open.
File A regular file owned by you and not writable by group or others (mode & 0o022 == 0), checked on the open file. A transcript need not be 0600 or have a single link.
Size At most the last 65 536 bytes (STOP_TAIL_BYTES) are read. A partial last line is ignored, and so is a partial first line when the read did not start at the beginning of the file. A last entry longer than 65 536 bytes gives no stop time.
Entry Only the timestamp field of the last non-empty complete line is read. It must be an RFC 3339 string; a number, a missing field or a line that is not JSON gives no stop time.
Range Accepted only when it is after 1970 and not after the hook's start (0 < stop <= start).

When transcript_path is absent, or any rule fails, there is no stop time and the hook decides exactly as it would without one. The stop time is never logged and never reaches resume.log, stderr, stdout, the resume message or the event key, and is never hashed. It only decides whether the noted swap counts as after the stop, and so which login goes into the event key. The reader returns only a number of seconds or nothing, with no error to report. It does not retry or wait.

Claude Code may write the error entry after the hook starts, or not at all. The last entry is then older than the stop, which can only lower the threshold, so the session may get one continue it did not need; it never waits for a swap it should have taken. The last-resume rule and the room check still apply.

Swap record

The rotator writes <root>/.auto-switch.d/rotate/swap.json in the swapped branch of the rotate cycle, after the ledger is saved and reads back with live equal to the new login, and before it releases the rotate lock. It is written through the same atomic writer as the ledger: a temporary file in the same directory, mode 0600, then a rename, so a reader never sees a partial file.

{
  "seq": 42,
  "live_login": "spare",
  "from_login": "work",
  "swapped_at": 1762654215,
  "reading": { "session": 12, "week": 31, "measured_at": 1762654190 }
}
Field Meaning
seq The previous record's seq plus 1, or 1 when there is no previous record or it cannot be read.
live_login The profile now live in ~/.claude.
from_login The profile swapped out.
swapped_at Epoch seconds when the swap finished, taken after the login was moved, not when the cycle started.
reading.session, reading.week The new login's session and weekly use from this cycle's measured reading, rounded up to a whole percent and clamped to 0–255.
reading.measured_at Epoch seconds when that reading was taken.
overflow Present only when the new login is a marked overflow profile: an object with tier, its tier in overflow= (1 to 9 for a credit profile, 10 for the API-key profile), and spend_block, true when a spend block in the ledger, or the API-key block for the API-key profile, stood on it when the record was written. Left out for a plan login.

A swap onto a marked overflow profile looks like this:

{
  "seq": 43,
  "live_login": "team-credits",
  "from_login": "work",
  "swapped_at": 1762654215,
  "reading": { "session": 0, "week": 100, "measured_at": 1762654190 },
  "overflow": { "tier": 2, "spend_block": false }
}

The record holds only these fields: profile names, numbers, flags and times, never an account, a token or a path. Nothing is written for a stay, an ALERT, a refused or failed swap, a profile switch or an in-session swap. For a plan login, a swap whose target reading is not a measured reading, or whose session or weekly figure is not a finite number, writes nothing, so a missing figure is never recorded as 0%.

A swap onto a marked overflow profile, by any reason (overflow-in from a plan login, from one overflow profile to the next tier, or overflow-out from the API key onto a credit profile), is always recorded once the ledger shows it live. Such a profile is billed per token, and a credit profile in use is often at 100% of its plan week, so its room is its spend-block state, not its plan figures. Each figure is written as read when it is known and finite, and as 100 otherwise. A hook built before the overflow field ignores it and judges the figures: it resumes on figures below 100% and otherwise waits, and it never fails on the record. When the record is not written the rotator logs one line, swap record not written: <reason>, and the swap and the cycle's outcome stand. When a previous record exists but cannot be read or parsed, the new record is written with seq 1 and the rotator logs one line, swap record seq restarts at 1: previous unreadable (<reason>) or swap record seq restarts at 1: previous unparsable. The first record logs nothing.

The hook reads the record loosely but safely: at most 4096 bytes, with no-follow, from a regular file owned by you and not writable by group or others. It ignores unknown fields. A record is not trusted, and is read as missing, when live_login or from_login fails the name rules, or when swapped_at or reading.measured_at is 0 or less or more than 300 seconds in the future.

Event wait

The hook waits in one blocking poll(2) call, with nothing read on an interval. It watches:

Source What it watches What it means
inotify on <root>/.auto-switch.d/rotate/ swap.json closed after writing or renamed into place A swap record may have changed; read and judge it.
inotify on <root>/.auto-switch.d/resume/prompted/ any file renamed into place A prompt may have been sent; check this session's marker.
a pidfd on the hook's parent process, the process the hook command runs through the process exits The session is normally gone: session-gone. The process is not Claude Code itself, so an exit of the session is otherwise noticed at the maximum wait.
the poll timeout the time left until 7 days after the hook's start no-capacity-timeout. The timeout never resumes a session.

Both directories must be real directories, not symlinks, owned by you and not writable by group or others. The hook's parent pid must not be 1, and must still be the hook's parent once the pidfd is open, so a reused pid cannot stand in for the session. If the pidfd is missing when the hook checks the session before sending a key, the session counts as not running and no key is sent; this check does not replace the watch-lost outcome below. If any of this fails, or inotify or pidfd_open is unavailable (a kernel older than 5.3, or a system other than Linux), the hook ends as watch-lost. It does not fall back to polling.

A watched directory that is deleted or moved, or an event the hook cannot parse, ends the wait as watch-lost. An inotify queue overflow counts as a possible swap: the hook reads and judges the record. After the watches are in place the hook reads swap.json once before it waits, so a swap written between noting the record and setting up the watch is not missed. Turning auto-switch off does not wake the hook; it is checked in step 9, so a waiting hook ends as disabled at the next swap that would resume it.

Resume keys

The hook looks for a pane in this order. First it uses its own environment, noted once when it starts: only when $TMUX is set and not empty and $TMUX_PANE is exactly % followed by 1 to 9 digits. When the environment names no pane, it looks the pane up by terminal (see Pane lookup by terminal). Either pane gets the same proof below. The pane id is kept in memory only, never written to disk, and logged only as the first 12 hex digits of its SHA-256. That tag is a correlation aid, not a secret: the salt is a fixed constant and pane ids are few, so the tag can be enumerated. It keeps the pane id and the terminal path out of resume.log; it does not hide them from someone who already holds the log. No $TMUX value, terminal path, or tmux or /proc output is ever written to the log.

The pane id is checked as a whole against ^%[0-9]+$ before any tmux call, and is passed as its own argument after -t, never through a shell. $TMUX_PANE is inherited environment, so it is treated as a claim to be proved, never as evidence. A named pane that is refused never falls back to the lookup by terminal.

The pane is used only if it passes this check, made once, right before the commit. Claude Code runs the hook command through a process of its own, which has a pipe on its standard input and its own process group (#3156), so the hook's parent is not Claude Code and is never consulted. The check starts from the hook's own process and walks up to the process that holds the terminal, the holder:

  1. The hook walks up its ancestry through /proc/<pid>/stat to the nearest process whose standard input (/proc/<pid>/fd/0) is a terminal. The walk stops at pid 0 or 1, visits at most 16 processes, never visits one twice, and requires every process it passes to have the hook's effective user id.
  2. tmux display-message -p -t %N '#{pane_tty}' exits 0 and prints an absolute path under /dev/ of at most 256 bytes, and that path is the terminal found in step 1.
  3. The process found in step 1, the holder, is the terminal's foreground process group (/proc/<pid>/stat). The holder is an ancestor of the hook that is not necessarily Claude Code itself: it can be a launcher or a shell. Children of Claude Code, such as background agents, are never reached by the walk, because the walk goes up and not down.

The check is made once. Between it and the first key the hook adds no delay, retry or poll. The process ids it used belong to the hook's own ancestors under its own user, so a process id reused in that instant is an accepted residual risk, not a case the hook guards against.

A failure at any step for a named or found pane gives outcome pane-unverified, with a detail from this closed list:

detail Cause
bad-pane-id $TMUX_PANE is not % followed by digits.
no-tty-ancestor No process in the walk has a terminal on its standard input, the walk reached pid 1, or it reached a process with a different user id.
walk-limit The walk visited 16 processes, or the chain looped.
unreadable-proc A /proc entry cannot be read or its stat cannot be parsed, or a parent pid of 0 ended the chain.
tty-mismatch The pane's #{pane_tty} is not the terminal the walk found, or tmux failed or printed nothing.
not-foreground The process holding the terminal is not its foreground process group.

Every one of these exits 2 with the resume message. None of them tries another pane, and the hook never runs list-clients. A pane inherited from a shell that started Claude Code outside that pane, or a pane another session owns, is not the terminal of any process in this hook's ancestry, so it fails at step 2.

Pane lookup by terminal

When the hook's environment names no pane, for example because Claude Code was started with $TMUX_PANE unset, the hook finds the pane from the session's terminal:

  1. It walks its ancestry once, as in step 1 above. If the walk finds no terminal (for example because standard input is a pipe), no pane is found, tmux is not run, and the outcome is not-resumed with detail=no-tmux-pane.
  2. It runs one read-only tmux list-panes -a -F '#{pane_id} #{pane_tty}': fixed arguments, no shell, standard input and standard error closed, and the inherited environment, so $TMUX chooses the server and the default server is used otherwise. It reads at most 64 KiB of output.
  3. The output must be one <pane id> <tty> line per pane, with exactly one space, a pane id of % and digits, and a non-empty tty without whitespace. One trailing newline is allowed. Any other line, including an empty line or a carriage return, or one id with two different ttys, makes the whole listing unusable. Identical repeated lines count once, because -a lists a window once for each session it is linked to.
  4. Exactly one pane must have the terminal the walk found. No match, more than one pane id, a failed or oversized listing, or an unusable listing all give not-resumed with detail=no-tmux-pane.
  5. The single pane is then proved exactly as a named pane is, with one display-message call and the same checks and refusal words. This also refuses a pane id reused between the listing and the proof, as tty-mismatch.

The listing is held in memory, dropped after matching and never logged. A session with a terminal but no named pane costs one list-panes per room event. A session on a tmux server that $TMUX does not name, with $TMUX unset, is not found and is logged as not-resumed.

Resume screen

Proving the pane says where the keys would land, not whether they are the right answer to what is on it. A pane that passes the proof may have moved on to a permission prompt, a billing prompt or a shell: there, Ctrl+U would clear a draft and Enter would answer a question the hook did not ask. So, once the pane is proved and before anything is typed, the hook reads the screen once:

tmux capture-pane -p -t %N

No -S is given, so only the visible screen is read and never the scrollback: a limit notice that has scrolled away cannot stand in for the one showing now. The run is made once, with the pane id checked again as a whole and passed as its own argument, no shell and null standard input; there is no retry, delay or poll.

What tmux printed is matched, lowercased, against a closed list of fixed phrases: what do you want to do?, usage limit, continuing automatically, session limit, 5-hour limit and weekly limit. The first two name the screens the sessions in #2695 and #2085 were held on; the rest are the window names Claude Code prints when a usage limit stops a turn. A screen holding any of them gets the keys.

Anything else gets no keys at all. The outcome is screen-unrecognised, exit 2, with a detail from this closed list:

detail Cause
screen-unknown The screen was read and holds none of the phrases.
screen-unreadable tmux could not be run, exited non-zero, or printed nothing but whitespace.

Nothing read from the pane is kept, returned or logged: the capture is matched and dropped, and the log carries only the fixed word above. The match is a substring test over at most 64 KiB, not a parser, and it is the whole of the hook's reading of the screen. It can be wrong in both directions: a screen that merely mentions a usage limit matches, and a future wording of the menu that uses none of these phrases does not. A false match sends the four keys to a pane that was already proved to be this session's own terminal; a false refusal leaves the session where the exit 2 wake leaves it, which is where every session without a proved pane already is.

Resume key sequence

The keys are four separate tmux runs, each with a fixed argument list, no shell, null standard input and output, and each waited on for its exit status before the next:

Order Command Purpose
1 tmux send-keys -t %N Escape Leave the timed wait, or close the limit menu.
2 tmux send-keys -t %N C-u Clear the input box, including a dimmed predicted prompt.
3 tmux send-keys -t %N -l continue Type continue as literal text.
4 tmux send-keys -t %N Enter Send it.

Before each key the hook checks, without blocking, that the session's process is still running and that /proc/<holder>/stat still shows the holder proved by the pane check as the terminal's foreground process group, so a session suspended with Ctrl-Z gets no more keys. The holder is an ancestor of the hook that is not necessarily Claude Code itself. A key whose tmux run exits non-zero, or a session found gone or suspended, stops the sequence: the remaining keys are not sent, and the outcome is resume-keys-failed with keys_sent set to the number sent and detail naming the cause (session-gone for a session that exited or was suspended, or the error kind). The hook never falls back to exit 2 after the commit. If the session exits or is suspended in the instant between the check and a key, that one key may reach whatever then reads the pane.

No other key or text can be sent: the key type has only these four values. The hook never sends a digit, so it never picks a numbered limit option, and never types /usage-credits or /rate-limit-options. tmux is found through PATH and reaches the server named by $TMUX; both belong to the same user as the session, which is the trust boundary.

Rotator capacity rule

This is the ledger rule that says a rotator cycle recorded capacity (CycleStatus::fresh_capacity in amplihack_utils::rotator_status). A reset wait and a capacity wait use it for the usage-limit wait's rotator capacity check, together with the rotator room rule, which asks that the login the cycle left live has room. Capacity alone does not end a wait. A login-change wait applies neither. The limit-resume hook does not resume on it; it resumes only on a swap record, and it does not read the room rule. The hook still reads the ledger, by the trust rules at the end of this section, for the live profile and for the rotator-down check. The live profile is the login in the event key unless a noted swap record shows that the session stopped on the outgoing login.

The rule reads <root>/.auto-switch.d/rotate/ledger.json (see Rotate state directory) and uses only live, alert and last_cycle. There is capacity when all of these hold:

  • last_cycle.measured_at is after the time the wait started, so the measurement, or the reading behind it, was taken after the limit hit;
  • last_cycle.outcome is swapped, stayed or switched (written by profile switch, with measured_at the time of the switch);
  • alert is not set.

The rotator writes these outcomes so that capacity means one of:

  • a fresh, successful reading of the live login below 100% on both windows (stayed); a stay on an overflow profile read in this cycle with no active spend block, at any figures, and a stay on a platform-tier login also record stayed (see Stays and capacity);
  • a swap to a login with room (swapped);
  • a profile switch to a login (switched).

A stay on a failed, carried or unknown live probe records stayed-unread, which is not in the list above, so it is not capacity. A no-capacity ALERT written while the live login reads below 100% on both windows is advisory: it is stored in advisory_alert, not alert, and the cycle records stayed, so it does not block it. The rule does not read advisory_alert.

last_cycle.at is set when the cycle ends, so a cycle that was already measuring when the limit hit can be recorded after the wait starts with readings taken before the limit; measured_at rules it out whatever the probe timeout. A ledger written by a rotator older than #1659, which has no measured_at, needs last_cycle.at more than 60 seconds after the wait started instead.

A rotator started before an upgrade keeps running the old binary. While it runs, amplihack install and a one-shot amplihack profile rotate print one line naming its pid and how to restart it, and every ledger write leaves out measured_at, which that binary would reject. The rotator is matched by its /proc/<pid>/exe file, so a binary replaced at the same path counts as another. From this version on the rotator ignores ledger fields it does not know.

Going back to an amplihack older than #1659 is not covered by that protection. The older rotator rejects a ledger that has last_cycle.measured_at, never rewrites a ledger it cannot read, and logs a failed cycle every interval without rotating again. Nothing else reports it: a limit-resume hook still finds a running rotator and waits its full 7 days for a swap record that never comes. Before the older binary runs, including a launch that would start the rotator automatically, stop the rotator with this version (amplihack profile rotate stop), then delete <root>/.auto-switch.d/rotate/ledger.json, then start the older rotator. The ledger holds only bookkeeping; the next cycle works out the live profile again from the accounts. Deleting it also clears the swap hold and the alert de-duplication key, so the first cycle may swap or alert once more. If an older rotator is already running and logging failures, the same three steps, with rotate stop run by either binary, recover it.

A cycle that moved onto an overflow profile records swapped, and one that stayed on an overflow profile whose probe read the login in this cycle, with no active spend block on it, records stayed at any figures, even with its plan windows at 100% (see Stays and capacity). Both have no alert, so they count as capacity for the usage-limit wait, and the step it reruns runs on credits. The limit-resume hook resumes on the swap record of that move when no spend block stood on the overflow profile, at any plan figures (see Swap record). A stay on an overflow profile whose live probe failed, was carried, was unknown or hit a spend limit, or whose login has an unexpired entry in overflow_blocked, records stayed-unread and is not capacity. last_cycle.overflow does not change the verdict; the rule does not read overflow_blocked itself, because the rotator has already applied it to the outcome it records. A spend block with nowhere to move ends the cycle on the no-capacity ALERT, which is not capacity.

Any outcome other than swapped, stayed or switched (alerted, stayed-unread, skipped, idle, held, or one the rule does not know), a missing ledger, or a ledger that is not trusted means no capacity yet. A hook from before #1907 reads stayed-unread as an outcome it does not know, so it also waits. The rule does not apply the rotator's thresholds itself.

The hook and the wait read the ledger more loosely than the rotator does: they ignore unknown fields, but still requires "version": 1, at most 64 KiB, a regular file owned by you, not a symlink and not writable by group or others. A last_cycle.at or measured_at of 0 or more than 300 seconds in the future is ignored. A live value that fails the name rules is logged as -.

Rotator room rule

The capacity rule above records that a cycle found capacity somewhere. It does not say that the login the cycle left in ~/.claude can run a step: a swap onto a login at s=98% records swapped, and counts as capacity. The room rule closes that gap (CycleStatus::fresh_room, beside fresh_capacity in amplihack_utils::rotator_status). The rule is read in two forms.

The form the rotator capacity exit reads is met when both of these hold:

An outcome that is not capacity fails it whatever live_room holds.

The three login changed exits read the other form, which asks the same two questions of the latest recorded cycle and leaves out the age: the record's outcome is capacity (swapped, stayed or switched, with no alert), and it says room. Both forms read the record through one function, so a record that ends a wait in one form is a record the other reads the same way.

What the reader makes of a ledger it cannot use depends on why:

Ledger rotator capacity exit login changed exits
Present and readable, and the record says room ends the wait, if also fresh capacity open
Present and readable, and the record says no room, or is not capacity does not end the wait closed
Present and unusable: unreadable, oversize, a symlink, not a regular file, owned by someone else, group or other writable, bad JSON, or a "version" other than 1 does not end the wait closed
Absent: no file at all has nothing to read, so does not end the wait open, because no rotator is running whose record could say otherwise

Only a missing file is absent. Every other way of failing to read the ledger is closed.

rotate stop records no cycle, so it adds nothing that could satisfy either form.

Only the usage-limit wait reads this rule, for a reset wait and a capacity wait. The limit-resume hook keeps the capacity rule and the swap record and calls neither fresh_room nor says_room, so it can still resume a session onto a login whose session use is at or above --session-at, provided the swap record shows both windows below 100%, or, for a marked overflow profile, no spend block.

Resume state directory

Everything is under <root>/.auto-switch.d/resume/. Each directory is created one level at a time with mode 0700, and the hook refuses to use any path that is a symlink, is not owned by you, or is writable by group or others. It never changes the mode of a path that already exists. Files hold only hashes, counts and epoch seconds. No pane id is stored.

Path Contents
lock Lock file for steps 4 and 9, and for appending to resume.log. The guard waits on it for at most 5 seconds. The log waits on it with a blocking lock, with no timeout; nothing is logged while the guard holds it.
log-write-failed One line, replaced each time, with the time, the outcome and the reason a log line could not be written: dir_missing, dir_unprivate, lock_failed, open_failed or write_failed. It does not grow. It is written only when resume/ exists and is private, never into an unsafe folder.
events/<sha256 hex> One empty marker per limit event resumed with keys. A wake writes none. The name is the SHA-256 of a fixed prefix followed by session_id, error, error_details, last_assistant_message and the login the session stopped on, each written with its length, so no two different payloads share a name. The login the session stopped on is the noted swap record's from_login when the swap falls between one second before the stop time and the hook's start (stop - 1 <= swapped_at <= start). The bound depends on the stop alone, not on when the hook started or on the session's past resumes, so every run of the hook for one stop gets the same name, whatever second it starts in and before and after that stop is resumed; a repeat run is duplicate and never resumes the session a second time. The second before the stop is the allowance Capacity for a resume gives a hook that starts in the stop's second, so a session resumed through it has its event named for that record's from_login. A hook that starts two or more seconds after the stop does not resume on a swap in the second before the stop, but its event is still named for that swap's from_login. The cost: a session resumed on that swap in the second before its next stop, which stops again with the same text and whose hook starts two or more seconds late, gets the earlier event's name and is duplicate, so it is left stopped rather than sent keys twice. Without a stop time it is from_login when the record is after the stop by the rule in Capacity for a resume and not later than the hook's start. Otherwise it is the ledger's live profile when the hook started. A session that stops on the outgoing login while the rotator swaps, is resumed, and stops again on the new login therefore gets a new event, not duplicate. The same login hitting its limit again is the same event; a limit after the rotator swapped to another login is a new one. Markers older than 7 days are removed.
sessions/<sha256 hex> One file per session, named by the SHA-256 of a different fixed prefix and its session_id, with one epoch-seconds line per resume in the last 24 hours. The count is evidence for resume.log (resumes=<n>) and decides nothing. A file that cannot be parsed counts as no earlier resumes: it is rewritten holding only the current resume, and one session-record-reset line is logged.
prompted/<sha256 hex> One file per session, named like sessions/, holding the epoch seconds of your last prompt in it. Written by the UserPromptSubmit hook, replaced atomically. Removed after 7 days and 1 hour (the longest wait plus 1 hour) when a hook starts waiting or commits. A file that cannot be parsed or is not private makes a waiting hook end as guard-failed.
resume.log One line per call: every decision, including the early exits disabled, not-limit, bad-session-id and bad-payload, and one per swap record judged stale or without room. A silent day therefore means the hook was not called. Where resume/ does not exist, the record of each call is the stderr line rather than a log line.
resume.log.1 The previous log. resume.log is renamed to it when it passes 64 KiB.

Resume log

2026-11-09T00:41:07Z resume session=3f9a1c2b7e04 event=7d41e0a9c2b1 outcome=swap-no-room live=work cycle=stayed swap_seq=41 swap_live=third error=rate_limit
2026-11-09T00:43:12Z resume session=3f9a1c2b7e04 event=7d41e0a9c2b1 outcome=resumed-keys live=work cycle=stayed swap_seq=42 swap_live=spare pane=5b0e19c4a7d2 keys_sent=4 error=rate_limit
2026-11-09T00:43:12Z resume session=91be04d2aa70 event=a0c55e1f9d38 outcome=not-resumed live=work cycle=stayed swap_seq=42 swap_live=spare detail=no-tmux-pane error=rate_limit
2026-11-09T00:43:12Z resume session=4e1c8b07d26a event=b73ad9052f14 outcome=screen-unrecognised live=work cycle=stayed swap_seq=42 swap_live=spare detail=screen-unknown error=rate_limit
2026-11-09T02:10:55Z resume session=c41d7a9e0b13 event=e9f2b6a01c7d outcome=resume-keys-failed live=spare cycle=stayed swap_seq=43 swap_live=spare pane=0d3a8f61e2b9 keys_sent=2 detail=session-gone error=rate_limit
2026-11-09T02:15:01Z resume session=6a0b3c9d1e42 event=17c5e8d2f0a6 outcome=watch-lost live=spare cycle=stayed detail=NotFound error=rate_limit
2026-11-09T02:16:40Z resume session=8c2f5e71a0d9 event=- outcome=not-limit live=- cycle=- error=server_error
2026-11-09T02:17:02Z resume session=- event=- outcome=bad-session-id live=- cycle=- error=rate_limit

Every sample line above carries error=. A log written before the field existed holds lines without it; they stay valid and are read as error=.

session and event are the first 12 hex digits of the hashes above. live and cycle are the ledger's live profile and last_cycle.outcome when the hook started (the login that hit the limit), or - when the hook did not get as far as reading it. The fields after cycle appear only when they apply:

Field Contents
swap_seq The seq of the swap record the decision was about.
swap_live That record's live_login.
pane The first 12 hex digits of the SHA-256 of the pane id, when keys were sent or tried, or a pane was proved or refused. The log does not say whether the pane came from the environment or from the lookup by terminal.
keys_sent How many of the four keys were sent (0–4).
resumes How many key resumes the session's record already held in the last 24 hours when the record was read, in step 5. It does not count the resume this line is about, so the first resume of a session logs resumes=0. A record that could not be parsed reads as 0. Evidence for an operator; nothing branches on it.
error Always last, on every line. The payload's error value reduced to lowercase ASCII, with every character outside a-z and _ written as _, at most 32 characters. An absent or non-string value gives error=. The value always matches ^[a-z_]*$; error_details and message text are never read into the line.
detail Why there was no keys path, or why a watch or key failed: session-gone (the session exited, or was suspended while keys were sent), or the name of the I/O error kind, such as NotFound or PermissionDenied. For not-resumed, the one fixed word no-tmux-pane (no pane was named or found). For pane-unverified, one of bad-pane-id, no-tty-ancestor, walk-limit, unreadable-proc, tty-mismatch or not-foreground. For screen-unrecognised, screen-unreadable or screen-unknown. The value is always one of these fixed words, never text taken from the pane, tmux, /proc or the environment.

Every field holds only A-Z, a-z, 0-9, ., _, : and -; any other character is written as -. The log never holds message text, error text, pane ids, account IDs or tokens. A log written by an earlier version, without the new fields, is still valid. Failing to write it does not change the outcome or the exit code, and it is never silent:

  • When resume/ exists and is private, the reason is written to log-write-failed (see Resume state directory).
  • When the hook exits 0, it writes one fixed line to stderr saying that a log line or the root could not be written or resolved. It names a reason from the fixed list, never a path or error text. On exit 2 stderr goes to the model, so the resume message is unchanged.
  • Where the root cannot be resolved, the stderr line is the only record.
  • The early exits (disabled, not-limit, bad-session-id, bad-payload and panicked) never create resume/. With no resume/ folder, each of them is recorded only by the stderr line, with reason dir_missing.
Outcome Exit Meaning
resumed-keys 0 A swap record with room arrived, the resume was recorded, and all four keys were sent to the session's pane. This is the only outcome that records the event as used.
not-resumed 2 Logged with detail=no-tmux-pane, when no pane was named or found: the exit 2 wake was given, nothing was typed and nothing was recorded, so the event stays armed and the next room event tries again. If the session runs in tmux, check that the hook reaches the session's own tmux server.
pane-unverified 2 A pane was named or found, but it was not proved to be the terminal of this hook's own Claude Code (detail says which check failed). Nothing was typed or recorded, and the hook exited 2 with the continue message. A session held on the usage-limit menu stays there, so this outcome in resume.log is the sign to continue the session by hand.
screen-unrecognised 2 The pane is this session's own terminal, but what it was showing is not a screen the keys answer (detail=screen-unknown) or could not be read at all (detail=screen-unreadable). Nothing was typed or recorded, so the event stays armed; the hook exited 2 with the unrecognised-screen line and the continue message. See Resume screen.
resume-keys-failed 0 A key failed or the session exited part way; keys_sent says how many went. The record of the event is released so the next room event tries again. No exit 2 follows.
swap-stale — A new swap record was swapped at or before the stop. The hook keeps waiting. Never the final outcome.
swap-no-room — A new swap record shows the new login at 100% on a window. The hook keeps waiting. Never the final outcome.
watch-lost 0 The event wait could not be set up, or a watch was lost. Never resumes.
no-capacity-timeout 0 No swap record with room within 7 days.
moved-on 0 You sent a prompt in that session during the wait, so the hook did not resume it.
disabled 0 Auto-switch was off, at the start of the call or when a swap record would have resumed the session. At the start, the line is written only if a private resume/ folder already exists; otherwise nothing is created and the call is recorded by one stderr line with reason dir_missing; no failure marker is written.
not-limit 0 The stop was not a usage limit: its error is a known non-limit value (see Limit detection), or the input was not a StopFailure. error= shows which value. session= is the session prefix when the id is valid, else -; event= is -.
bad-session-id 0 session_id was missing, over 256 bytes or invalid. The line has session=-.
bad-payload 0 Standard input was malformed or over 1 MiB.
panicked 0 The hook panicked. One attempt is made to log this line; if the log cannot be reached, only the stderr line records it.
duplicate 0 This limit event, or this session since the hook started, was already resumed with keys. Also given instead of a wake when that is found just before the wake.
session-record-reset 0 The session's record of earlier resumes could not be parsed. It was treated as no earlier resumes; the next resume with keys rewrites it, and until then each run logs this line. The run goes on, and its own line follows. Logged once per run, with no record contents.
stop-hook-active 0 Claude Code reported a stop hook already running.
session-gone 0 The Claude Code session that started the hook exited during the wait.
rotator-down 0 When the hook started, no rotator was running, or its ledger could not be read (for example a newer version). The hook did not wait.
guard-failed 0 resume/, the lock, a marker or the session record could not be used safely. It can be logged alone before a wake line (the read before the wake failed and the session is still woken) or before resume-keys-failed (the release failed and the event stays used).

Resume limits

Constant Value
Wait for a swap record 604800 s (7 days)
Hook timeout margin 300 s
Registered hook timeout 608400 s
Swap record size 4096 bytes
Clock skew allowed 300 s
Keys per resume 4
Resumes per limit event 1
Resume lock wait 5 s
Event marker retention 7 days

The wait plus the margin is less than the hook timeout, so the hook always decides before Claude Code stops it. The wait is a lifetime cap, not an interval: it ends the wait and never starts a resume.

Usage-limit wait

A limit never ends a step: every limit starts a wait that retries (issue

2911). The usage-limit waits reference owns the

tables for limit kinds, the limit record and the waiting_for_capacity line.

When a recipe agent step fails on a usage limit and no auto-switch rerun is left, the step's supervisor waits and then runs the step once more. It is on by default and does not need auto-switch or profiles. Task-oriented guidance is in the how-to.

There are three kinds of wait:

  • a reset wait, for a limit that resets within five hours: it waits for that reset, or for a login with room to become live, whichever comes first (see Reset time and Waking only on room). For a step under an inherited profile with auto-switch on, a stored profile that a reading taken during the wait shows has capacity ends the wait as well, without that profile's login becoming live, and the retry then runs under it rather than under the exhausted inherited one (see Capacity for a profile step);
  • a capacity wait, for a limit that does not reset within five hours (a weekly limit), states no readable reset, has a reset already behind the clock, or is credit exhaustion: it waits for a login with capacity or for the failed login's own reset when one is stated and still ahead. With no usable reset it has no deadline (see Capacity wait);
  • a login-change wait, for an organisation spend limit that states no reset: no reset lifts that limit and no login of the same organisation would either, so it waits for the login in ~/.claude to change (see Login-change wait). It is the one wait that no capacity reading ends: only the login key changing, a stop signal or the end of the session ends it. It has no deadline.

A limit always starts one of these three. The step is not waited for only when the wait is disabled, the output carries no limit message, or the prompt is piped and could not be stored (see Order of attempts).

The wait reads only files: the harness's limit message, the capacity file, the stored readings and the ledgers. It makes no usage, token or identity request for any profile and writes no credential file, so a profile in the auto-switch exclude list is never probed or refreshed by it, and never counts as a login that could take over.

The capacity governor does not hold an agent step of a running recipe at an exhausted weekly or session limit: this wait owns that case, so the governor's shorter wait never replaces it (see Exhausted limits inside a recipe).

Gate

A launch is supervised for the wait when all of these hold:

  1. no --profile flag;
  2. Claude's arguments set -p or --print (read as Claude reads them, so an option's value such as --model -p does not count);
  3. AMPLIHACK_AUTO_SWITCH_SUPERVISED is unset (the launch is not itself a supervised attempt);
  4. AMPLIHACK_NONINTERACTIVE is exactly 1 (amplihack recipe run sets it for every step). The settings are read only after this check;
  5. the wait is enabled; and
  6. the mode is not --docker or --auto. With an inherited profile those modes are refused earlier, so this matters only without one.

When checks 1 to 5 pass but the step cannot be supervised (check 6, or a scratch directory failure), the launch writes skipped reason=not_supervised once and runs unsupervised, as before. That launch inherits fd 0 whole: no prompt copier has read anything, because one reads only once a first attempt is running; see Stdin handling.

With an inherited profile and auto-switch on, the auto-switch reruns come first and the wait follows. A reset wait is for the inherited profile's reset, not for the reset of the last profile auto-switch tried (see Order of attempts). Its retry runs under the inherited profile, unless the wait ended on login capacity, in which case it runs under the profile that showed capacity. The retry after a capacity wait runs under the profile that showed capacity. A login-change wait is for the login in ~/.claude, and its retry runs on whichever login is live there. See Retry login. Otherwise the same supervisor runs with no profile substitution: the retry runs under the inherited profile, or with no override when none was inherited. With no inherited profile, recipe launches watch the login in CLAUDE_CONFIG_DIR when set, or the live host login in ~/.claude. Other launches may apply the .default pointer's profile. The wait then watches that profile's login, unless it is the rotator's live profile in ~/.claude.

The supervisor keeps the held-back stdout in <root>/.auto-switch.d/rerun/ when auto-switch is on, otherwise in $HOME/.amplihack/rerun/. $HOME/.amplihack must be a real directory owned by the current user that group and others cannot write (created at 0700 when missing, never chmoded), and rerun/ must be mode 0700.

Stdin handling

What an attempt receives depends on what stdin is:

Stdin First attempt A rerun
A pipe or a socket, prompt not in the arguments, an --input-format channel included A pipe fed by the copier (below) A pipe fed from memory with every byte the copier kept, from the first
A pipe or a socket, prompt in the arguments Inherited unchanged /dev/null
A regular file Inherited unchanged The file again, from the offset the step started at (on Linux through its own open of /proc/self/fd/0, so no read offset is shared with other processes)
A terminal Inherited unchanged Inherited unchanged
A closed descriptor Inherited unchanged /dev/null

The feature covers any caller that supplies the prompt on stdin, whatever launches it. A socket is not told apart from a pipe, and is treated the same way. When stdin is a pipe and Claude's arguments carry no prompt, the supervisor sets up a copier. The copier reads stdin in fixed-size blocks, keeps each block in memory and then writes it to the attempt's stdin, and closes the attempt's stdin when the pipe reaches end of file. The attempt sees the prompt as it arrives, with no delay. Nothing is written to disk.

Everything the copy needs is made before the first attempt starts: a second description of stdin, the first attempt's stdin pipe, and the copier thread. When any of them cannot be made, which happens only to a process out of file descriptors or threads, the step is not run at all. Nothing has been read from stdin by then, and the step fails at once with this step was not run: its prompt comes on a pipe, and the copy of it that a retry would read could not be set up (…). An attempt run without a copy could not be repeated after a usage limit, so it is not run; an earlier version ran it, and a limit on it ended the step with skipped reason=piped_prompt.

The copier thread waits until the first attempt's child exists, and reads nothing before then, so no byte of this process's stdin is taken until there is a child to give it to. That is what lets the supervisor stand down and leave fd 0 whole (below); a capture dropped before then ends the waiting thread without its reading a byte. It is also why a write that fails on the attempt's end of the pipe always means a step that stopped reading rather than an attempt that never ran.

--input-format stream-json makes stdin a channel of messages rather than one prompt, and it is copied and replayed like any other piped prompt (issue

3036). Every supervised attempt's stdout is held back until the step finishes,

and the output of an attempt that is run again is discarded, so the caller has seen nothing of an attempt that met a limit; a retry given the same input from its first byte is the same step from the caller's side. A channel its caller still holds open when a retry is due is fed to the retry as it arrives, as below. amplihack's own usage request also uses stream-json, but it runs claude directly and is never supervised.

The copy holds the prompt as opaque bytes, with no size cap, in the supervisor's own memory, and is dropped when the step ends, whether it succeeded or failed. A cap would be a budget that ends a step on a limit. Earlier versions kept the copy in <pid>-0.in in the rerun directory (see above); the next supervised launch still removes such a file once its owning process is gone.

Before a rerun the supervisor checks that the prompt was not cut short, and nothing else; it does not wait for the copier. It then gives Claude a pipe that a feeder thread fills with the kept bytes, from the first, and then with each further byte as the copier keeps it, closing the pipe when the copier reaches the end of stdin. Every attempt therefore reads byte-identical input, and the step continues the usage-limit wait or auto-switch rerun it would have had with the prompt in -p. The pipe's write end belongs to the supervisor, so an attempt cannot change what a later one reads.

Nothing waits on the caller's pipe. The copier finishes at the end of stdin, and stdin is a pipe belonging to whoever launched the step: nothing promises it will ever be closed. A rerun started while the caller is still writing is in the first attempt's position: it reads what has arrived, then the rest as it arrives, and reaches the end of its stdin when the caller closes the pipe. A caller that holds the pipe open holds up only an attempt that reads it, and an attempt that does not read its stdin runs and ends. Once a step that ran a rerun has finished, the supervisor joins the copier if it is certain to finish (it has reached the end of stdin, it has failed, or the last writer of stdin has gone), so that every line the copier writes comes before the step's result. Nothing is timed: the question asked is the state of the descriptor, not the clock.

A write to an attempt that has already exited (EPIPE) is ignored: it stops neither the copy nor the step, the kept copy still receives the whole prompt, and every later attempt still reads it whole. It is reported, on stderr, as this step stopped reading its prompt before all of it had been delivered. The recipe runner says as much when it writes a task straight to an agent that exits early; a supervised step puts the copier between the two and the copier always drains the runner's write, so the runner's own warning cannot fire for such a step and this line takes its place. Like the runner's it is diagnostic: it names no part of the prompt and changes no exit code.

One failure remains, and it costs the prompt itself rather than its copy. The copy cannot fail on its own account: every block is kept in memory before it is forwarded, and there is no file to create, write, flush or read back. Before, a capture file that could not be created or written was carried on in memory (issue #3036), but a copier that panicked, a final flush that failed, or a part on disk that could not be read back each refused the rerun with skipped reason=piped_prompt, and so let a usage limit end a step whose attempt had been given its whole task.

  • Stdin cannot be read to its end. There are no further bytes to forward, so the copy ends and attempt one's stdin closes. Closing it is the only signal a pipe gives its reader, and a reader takes it for the end of the prompt: the attempt cannot tell the shortened prompt from a whole one, acts on what it was given, and may well exit 0. A copier that panics is treated the same way, because it closes the attempt's stdin wherever it stopped. So this case is reported twice and ends the step:

  • the copier writes one line naming the error as it happens (amplihack: this step's prompt could not be read to its end (…)), which is the record that survives even when nothing later asks about the copy;

  • the supervisor reads the flag before it passes the attempt's result up, and refuses to report that attempt's success as the step's. The attempt's own stdout is still printed and its exit code is kept when it already failed; only a success is replaced, with exit 1 and a line naming the consequence (amplihack: this step's prompt was cut short …).

The flag is read without joining the copier, and it cannot be missed for this case: it is published before the attempt's stdin is closed (by the copier for the first attempt, by the feeder for a rerun), and the attempt reaches end of file only after that. An attempt that exits without reading to the end of its prompt, where the source fails afterwards, is seen once the copier is joined at the end of a step that ran a rerun; otherwise the copier's own line is the record. The loss refuses the rerun and the wait too: a step that met a limit ends with failed reason=prompt_cut_short, a lost prompt and not a limit ending (see usage-limit waits).

An empty non-blocking read is not such a failure. O_NONBLOCK lives on the open file description, not on the descriptor, so a process sharing the one the step inherited on fd 0 can set it, and a read of the empty pipe then fails with EAGAIN rather than waiting. The copier waits for the next byte with poll(2) and reads again, exactly as a blocking read would have.

Another case is not a failure of the copy at all: the caller has not closed the pipe. A step that meets no usage limit never joins the copier and finishes as it always did. A step that does meet one waits for its reset, and the retry it earns starts at once, fed what has arrived and then the rest as it arrives. Before issue #3036 this case ended the step with skipped reason=piped_prompt. The first fix for #3036 waited for the caller to close the pipe, writing waiting_for_prompt, and a caller that never closed it held the step for ever; now nothing waits for it and that line is not written.

Standing down. The supervisor stands down, and the caller runs the step once in this process, when it cannot start at all: no scratch directory, no stop-signal handler, or a first attempt that never spawned. That plain launch inherits this process's own fd 0, and it inherits it whole: every one of those paths is reached before a first attempt is running, which is when the copier is let go, so not one byte has been taken off it. The supervisor checks that before it stands down and refuses to run the step at all if a copier has been let go after all. No path reaches that today, and the check is what keeps a new one from silently handing a launch a shortened prompt, because a shortened prompt is a shortened task that would be acted on in silence.

The prompt is any positional argument, wherever it is, read with Claude's option table so that the values of options such as --model, --output-format, --max-turns, --allowedTools and --append-system-prompt are not taken for it; a prompt that starts with - counts only after --. The table includes Claude's hidden value-taking options (such as --max-thinking-tokens), which claude --help does not list. An option in no table, such as one a newer Claude added, is read as taking the next non-option word as its value. That errs toward "no prompt in the arguments", which means that the supervisor also copies stdin, a pipe that the step never reads included. What that costs is a copy in memory and a feeder thread for each rerun. It never holds the step on a caller that keeps the pipe open, and it never costs a byte of the prompt in argv, which Claude reads as it always did.

Order of attempts

After an attempt hits a usage limit, in this order:

  1. a stop signal already received ends the step with 128 plus the signal;
  2. auto-switch on and an eligible profile left: rerun under that profile at once, whether or not the step has already waited (issue #2967; see Moving to another login before a wait). A piped prompt still arriving is fed to the rerun as it arrives, as in step 3;
  3. auto-switch moved the step off the inherited profile before the first attempt only because that profile is over the threshold (no window at 100%), and no eligible profile is left: rerun under the inherited profile at once. This is an auto-switch rerun, made at most once per step: no start or end is written, so a limit on that rerun still goes through steps 4 to 6. A piped prompt is replayed from its stored copy, so this rerun is made. A prompt still arriving is fed to the rerun as it arrives (see Stdin), so the rerun runs at once. It is refused only when no whole copy can ever exist, because the prompt could not be read to its end; the reason is named (auto-switch: no rerun under profile …). The step then goes on to step 4: the log gets skipped reason=disabled from step 4 when the wait is off, else failed reason=prompt_cut_short from step 5 if the prompt could not be read to its end;
  4. the wait turned off by recipe.usage_limit_wait = false or AMPLIHACK_USAGE_LIMIT_WAIT=0: skipped reason=disabled, and the result is passed up. This is the one configured ending, and it is intended; CI does not turn the wait off (issue #2911);
  5. the output carries no limit message in a harness's shape (skipped reason=no_limit_message), or the prompt is piped and could not be read to its end (failed reason=prompt_cut_short), so the step fails whether or not it met a limit: a lost prompt, not a limit ending (see Stdin). The result is passed up. A prompt that is merely still arriving is not lost, and the retry is fed it as it arrives. A piped prompt whose copy could not be set up never gets this far: the step was not run;
  6. otherwise the limit selects a wait (see Capacity wait for the table): a reset wait, a capacity wait or a login-change wait. A capacity or login-change wait writes a waiting_for_capacity line, then start, the wait, and end. After end reason=signal the step exits with 128 plus the signal; after session ended the failed attempt's result is passed up; after any other reason resume is written and the step runs once more, at once, on the copy of its prompt.

No limit message ends a step except through step 5. A limit with no readable reset, a reset more than five hours away, a reset behind the clock and a spend limit that states no reset all start a wait at step 6.

A $HOME/.claude step reaches step 6 and finds that the login has already changed more often than not, because the rotator reacts to the same exhausted reading that failed the attempt. The wait then ends before it begins, spending no time; see A login that changed before the wait.

Step 6 reads the inherited profile's limit, not the last attempt's. The wait is timed by that profile's reset, because that is the login the retry uses unless the wait ends on another login's capacity (see Retry login). When auto-switch ran the step under other profiles before running out, their limits only steer auto-switch's choice of the next profile: a candidate that resets later does not stretch the wait, and a candidate's weekly limit or spend limit does not cancel it. With auto-switch on, the end of a limit block the rotate ledger records on any other login auto-switch could move the step to, run on or not, ends the wait when it comes first, and the retry then runs on that login (The earliest-reset deadline). When auto-switch moved the step off the inherited profile before the first attempt, the inherited profile's limit comes from the usage readings: the latest reset among its windows at 100%. A reset from a reading more than five hours away is treated like a weekly limit in a message: it starts a capacity wait. A window over the auto-switch threshold but under 100% is a reason to prefer another profile, not a limit, so it neither times nor cancels the wait. If no window is at 100%, the inherited profile still has capacity and no wait is built: when the candidates are limited, the step goes back to the inherited profile through step 3, with no start or end event, and the wait is kept for a limit on that profile itself. If that move is refused (a piped prompt that could not be stored), step 4 or 5 still writes the skipped event.

A step may wait any number of times. Each wait is planned from the limit that caused it; see Login key.

Login key

The login key is the name of the login the failed attempt ran on, read immediately before that attempt was launched. For a $HOME/.claude step it is the rotate ledger's live profile, else the swap record's live login. For any other step there is no key. The name is read at runtime from the files the rotator writes under its own lock, never from .claude.json, whose account field may hold an e-mail address or a UUID. A step that can read neither file has no key.

The login key is what the login-change checks compare. The account= field and the wait's mark name the login more widely (issue #2967): the profile the supervisor launched the attempt under, else the inherited profile, else the login key. A step under a stored profile is therefore named by that profile, where before #2967 it had no key and logged account=unknown. A host with no profile store, a CLAUDE_CONFIG_DIR step, and a $HOME/.claude step whose key cannot be read still say account=unknown (The login a wait names).

Each reading carries which of the two files it came from along with the name. The two are read in order, the cycle ledger first and the swap record as a fallback, so a ledger that is missing, unreadable or being replaced switches the answer's source without any login having moved. Comparisons keep the source (A login that changed before the wait), while the account= field uses the name alone.

The key identifies the login for the room check, the short-circuit before a wait and the account= field. It does not limit waits. A step has no count of waits, no mark per login and no budget, and a wait on a login it has already waited on is not refused. No wait has a length setting: a wait for a stated reset ends at that reset, and one whose limit stated no usable reset has no deadline (see A wait has no length setting). The end of the step's session and a stop signal apply to each wait unchanged. AMPLIHACK_STEP_TIMEOUT does not: a step timeout does not cut a wait or stop the retry after it (issue #3037; see The step timeout does not cut a wait).

Only these end a step that met a limit: a stop signal, the end of the session, the wait turned off by the operator (skipped reason=disabled), skipped reason=no_limit_message and failed reason=prompt_cut_short (a piped prompt that could not be read to its end, which fails the step whether or not it met a limit). Every retry runs the step from the start with the same prompt, so anything a failed attempt already did (a commit, a push, a comment) may happen again. Write agent steps so that running one twice is harmless.

A limit after a wait

A retry that meets a limit is planned like any other limit. There is no refusal, no count and no budget: the step waits again, and each wait is announced. A wait that ended because something said try now and was contradicted by the retry is still waited out, and one reentered line says so.

The chain is paced by waiting, not by counting. A wait with a deadline ends in the future, and a wait with none ends only on an event. A reset already behind the clock becomes a capacity wait with no deadline (see A reset that has already passed), so a retry cannot meet the same limit in a loop that spends no time.

A 429 report is the last stderr line that begins with API Error: 429, 429 Too Many Requests, rate_limit_error or rate limit exceeded, or, when no stderr line does, the last non-empty line of the stdout tail if it begins with one of them. Surrounding whitespace is trimmed first, as it is for a usage-limit message, and case is ignored. A phrase that ends in a digit must not be followed by another, so API Error: 4290 is not a 429 report. The same words mid-line, or in an earlier line of model output, do not count; they are the model's own prose. This reading applies only at this position. Everywhere else a 429 is still the short-lived transport fault the failure classifier calls it, and here too it starts a wait and nothing else: no profile is recorded as limited and auto-switch does not move. When the output carries both a usage limit and a 429, the usage limit decides. A 429 report states no reset and no kind of limit, so when it does start a wait that wait is a capacity wait with reset=none.

A 429 report is the one reading in this table that does not always start a wait, and it is the only place left where "could another login take over?" is asked before a wait begins. A 429 is not a limit message: it says nothing about any account's windows, so there is nothing about it to wait out. With no login that could take over, the step hands the 429 back to the recipe runner as the transient transport fault it is, and writes no wait line at all. Every limit in the table below starts a wait unconditionally; see Removed endings.

The retry's output The next wait
A usage-limit message that states a reset still ahead, within five hours A reset wait for that reset
A weekly limit, a reset more than five hours away, no readable reset or unrecognised wording A capacity wait
A message whose stated reset the clock has already passed A capacity wait, reason=passed_reset; see A reset that has already passed
A spend limit that states no reset A login-change wait
A spend limit that states a weekly reset A capacity wait, after the step has blocked its login
Codex's out-of-credits line A capacity wait, reason=credits
A 429 report, and another login could take over A capacity wait with reset=none
A 429 report, and no login could take over No wait; the 429 is passed up as a transient fault

The checks that apply to every wait apply here too: a disabled wait and a stop signal. Each re-entry that starts a wait writes one reentered line, once, before the second wait's start, as shown under Log lines.

A reset that has already passed

A retry can meet a usage-limit message whose stated reset the clock has already reached. A clock time is placed today while it is at most 10 minutes in the past (see Reset time), so a retry that runs at 08:32 reads resets 8:30am as two minutes ago, and an epoch message can state any past instant. A reset wait on such a reset would end the moment it began.

A past reset shows that the stated reset cannot be relied on: the login has not recovered, or the harness is repeating a time that no longer holds. It does not show that no wait is owed. The wait is therefore planned from capacity instead of from the clock, on the first attempt as on a retry:

  • It is a capacity wait, announced with waiting_for_capacity ... reason=passed_reset, and its start line carries the stated reset in reset=.
  • The reset adds no deadline, because it is behind the clock. The wait has none, so its lines read until=none and bound=none; see Capacity wait deadline.
  • It ends on the events any capacity wait ends on (see Reasons a wait ends), and on a $HOME/.claude step only when the login the retry will use has room. A swap onto a login with no room, or rotator stop, does not wake it.
  • A limit on the retry after it starts another wait.

The wait starts whether or not another login exists. With no running rotator and no second login nothing ends it on its own: it waits until a person changes the login or stops the step (see A wait with no deadline).

The log shows the second wait after the line that reports the re-entry; see Log lines.

Reset time

The wait reads only the harness's own limit message: the last stderr line in its shape, else the last non-empty line of the stdout tail when that whole line has it. In -p mode stdout is the model's answer, so prose that mentions a usage limit never starts a wait (the recipe runner's classifier still sees the limit and ends the run). For Claude the shape is a line that starts with Claude AI usage limit reached| and Unix seconds, or with You've hit your and also contains limit and ·. The patterns live in crates/amplihack-cli/src/commands/recipe/run/limit_patterns.rs.

Message Example Result
Session limit You've hit your session limit · resets 1pm (America/Los_Angeles) reset wait, when the reset is at most five hours away
5-hour limit You've hit your 5-hour limit · resets 8:20pm (America/Los_Angeles) reset wait, when the reset is at most five hours away
Per-model limit You've hit your Opus limit · resets 8:20pm (America/Los_Angeles) reset wait, when the reset is at most five hours away
Weekly limit You've hit your weekly limit · resets Oct 8, 12am (America/Los_Angeles) capacity wait, reason=reset_too_far
Spend limit with a session reset You've hit your org's monthly spend limit · run /usage-credits … · your session limit resets 1pm (America/Los_Angeles) wait for that reset: the session limit is what stops work
Spend limit with a weekly reset … monthly spend limit · … · your weekly limit resets Oct 8, 12am (America/Los_Angeles) capacity wait, as for a weekly limit. The step also blocks its login until that reset.
Spend limit, no reset You've hit your org's monthly spend limit · run /usage-credits … login-change wait, whatever the step's login and whether or not a rotator runs. No reset lifts it, and room on another stored login does not either
Epoch Claude AI usage limit reached\|1792335000 reset wait, when at most five hours away; further away, as for a weekly limit
Shape, no readable reset, or wording the supervisor does not recognise You've hit your session limit · try again later capacity wait, reason=no_reset; read as a session limit
No message in the shape model prose, credit balance is too low skipped reason=no_limit_message, or not a usage limit at all
Credit exhaustion Your workspace is out of credits (Codex), also after ERROR: capacity wait, reason=credits
Codex usage limit Usage limit reached. You've reached your usage limit. … (Codex) capacity wait, reason=no_reset; read as a session limit
Codex service rate limit … Codex exec failed with status exit status: 1: service rate limit; retry later or check account quota capacity wait, reason=no_reset; read as a session limit

A spend-limit message that states a reset also records a block on the login the step ran under, before the wait is planned; see A spend limit blocks the login the step ran under. So does a spend limit that states no reset, until the rotator's own spend reset. The record never ends, delays or refuses a step: when it cannot be written, the wait is planned as if it had been.

The text after resets is an optional date (Mon D,, three-letter English month), a clock time (H[:MM]am/pm or 24-hour HH:MM), one space and an IANA zone in parentheses, looked up in the compiled-in chrono-tz table. No year, day or zone is guessed. Without a date the time is placed today in that zone, with one in this year; more than 10 minutes in the past means tomorrow, or next year. A spring-forward gap moves to the first valid instant, a fall-back overlap takes the earlier one. A reset more than five hours away, or none that parses, is not waited for by a reset wait: waiting would hold the run for hours with nothing known to change. Such a limit starts a capacity wait instead when another login could take over.

Deadline

This section covers reset waits; a capacity wait has its own deadline, and so does a login-change wait. A reset wait ends at the earliest candidate that applies (a tie is named by the earlier row):

Candidate Applies when bound=
reset + 120 s, or now + 120 s when the reset has passed always reset+margin
another login's block end + 120 s auto-switch is on, and a limit block recorded on another login the step could move to ends before that (issue #2967) earliest_reset+margin

A reset wait has no timed bound but these two. It ends at its reset plus 120 seconds, or earlier on a login with room or a login change (Reasons a wait ends). No setting shortens it.

There is no five-hour ceiling in the deadline either. The five-hour rule decides which wait a limit earns (Reset time): a reset more than five hours away starts a capacity wait, which also ends at that reset, held to its kind's window (Capacity wait deadline). A reset wait is therefore never longer than five hours and 120 seconds, because no longer reset reaches one. See Login key.

Ending the wait early

A wait can end on an event before its deadline, and a wait with no deadline ends only that way. On a $HOME/.claude step a wait can also end before it begins.

A login that changed before the wait

A $HOME/.claude step reads its login key immediately before each attempt is launched, and reads it again after a limit before it plans a wait. When the two differ, the rotator moved another login into ~/.claude while the attempt was failing. If that login has room, as Waking only on room defines it, there is nothing left to wait for, and the supervisor writes

amplihack.recipe.usage_limit_wait start reason=usage_limit harness=claude reset=… until=… bound=…
amplihack.recipe.usage_limit_wait end reason=login changed
amplihack.recipe.usage_limit_wait resume attempt=2

back to back and runs the step again at once on the login now live. No time passes, so nothing is appended to the file AMPLIHACK_USAGE_WAIT_LEDGER names. The pair also reaches the run's recipe log, so a reader sees that the step met a limit and moved on.

When the login that arrived has no room, or the ledger cannot say, the step does not retry onto it. It plans the wait it would have planned had nothing changed, and that wait ends on the first of its exits that Waking only on room allows. A login-change wait is the exception: it retries at once on any change, as it always did.

The short-circuit is not counted against the step: a step has no limit on its waits. A rotator swapping on every attempt costs the attempts and nothing else, and the login now live meets its own limit, if it has one, with a wait of its own. See Login key.

This is the common case on a host where every step shares one ~/.claude login. The rotator reacts to the same exhausted reading that failed the attempt, so the swap very often lands before the supervisor would have taken its baseline. Without this check the step would take the new login as its baseline, see nothing change afterwards, and sleep to the old account's reset.

The comparison fails closed. A change counts only when both readings name a login, both came from the same file, and the names differ. Anything else reads as "no change", and the step waits as it otherwise would:

First reading Second reading Read as
cycle ledger, work cycle ledger, personal changed
swap record, work swap record, personal changed
cycle ledger, work swap record, personal no change
cycle ledger, work swap record, work no change
either, work neither file readable no change
neither file readable either, work no change

The room check (Waking only on room) reads the same ledger file, by the same trust rules as the rotator capacity rule. It adds no comparison to this table: a change is first decided by the table, and only then is the room asked.

The cross-source rows are the reason the source is carried at all. The swap record is written at a different moment from the cycle ledger and may name the login before or after the one the ledger names, so two readings taken from different files are not evidence of anything happening in between. A ledger that is momentarily unreadable while the rotator replaces it falls back to the swap record and so reads as no change, rather than as a swap that did not happen. The cost of that is one wait the step was going to make in any case; the cost of the other error would be an attempt burnt on a login that is still at its limit.

Reasons a wait ends

Every kind of wait blocks until a file it reads is written, a stop signal arrives, the process that started the step exits, or, for a wait that has one, its deadline comes, and stops at the first of the reasons below that applies to it. No timer ends a wait: the only deadline is a stated reset. Signals and the session check come first, then the deadline, then, after a write, the file checks: rotator capacity, the login fingerprint, login capacity, then the login key. A wait that reads capacity checks rotator capacity again before it ends login changed. A check reads files (the rotate ledger, the swap record, the readings, .claude.json and the credentials file) and never runs a /usage probe or an agent; nothing is read on an interval. See How a wait wakes.

end reason= Wait Cause Retry
signal all SIGINT, SIGTERM or SIGHUP was received no; exits 128 + signal
session ended all the process that started the step exited (the supervisor's parent changed) no
reset reached reset, capacity the reset+margin deadline passed; on a capacity wait this is the failed login's own reset. A wait whose limit stated no usable reset has no deadline and cannot end this way yes
login changed all the login changed before the wait was planned, or a reading of the fingerprint after a write differs from the baseline (a .claude.json that does not parse is no reading). On a reset or capacity wait for a $HOME/.claude step, the change counts only when the login that arrived has room yes
rotator capacity reset, capacity the step uses $HOME/.claude and the rotate ledger records a cycle that meets the rotator room rule: a cycle with capacity (swapped, stayed or switched, no alert; stayed-unread is not capacity) that says room (live_room: true, or a switched record that does not state false), whose measured_at is after the wait began, or, from a rotator that writes no measured_at, recorded more than 60 s after it yes
login capacity reset, capacity the step runs under an inherited profile with auto-switch on, and a reading taken after the wait began shows that another stored profile has capacity (see Capacity for a profile step) yes, under that profile

max reached and capacity expired are no longer written. They were the ends of a timed outer bound that has been removed; a wait whose limit stated no usable reset now has no deadline (see A wait with no deadline).

Both capacity rows, and the room condition on login changed, apply to a reset wait and to a capacity wait, and to neither of them on a login-change wait, which takes login changed on any change, as it always did. A login-change wait is started by an organisation spend limit, which is a limit on the organisation's credit rather than on any session or week, and no capacity reading reports credit: a rotator cycle that measures the live login's windows, and a stored profile's reading, both say only that some account has session capacity. A cycle that swaps the login does still end the wait, but through the login fingerprint described below, not through either capacity check: the fingerprint watches $HOME/.claude itself, so the swap is seen as the directory changing under the step, and the end is recorded as login changed, at the write that made the swap. A cycle that measures the same login and stays there leaves the wait in place. The two capacity checks are therefore not run at all for that plan, rather than run and ignored.

rotator capacity uses the rotator room rule, checked at each write before the fingerprint, and again before a write ends a wait login changed, so a cycle that swaps the login and records room ends a wait as rotator capacity, wherever the rotator's write lands among the wait's reads. The limit-resume hook does not use it; it acts only on a swap record.

A cycle that moved onto a credit-backed overflow profile (swapped, overflow=in) or stayed on one whose probe read it in this cycle with no active spend block (stayed, overflow=on) is capacity at any figures, and the room rule adds only the live_room condition. The rotator writes live_room for a credit-backed or API-key login from its reading, as for any other login. Session use below --session-at and week use below 100% record true, so the wait ends as rotator capacity and the step runs again on credits, as it did before; the API-key profile's fixed 0% reading always passes. The one narrowing is a credit-backed profile that reads at or above --session-at, or at 100% on its week: it records false, and a wait that used to end when the rotator moved onto it now sleeps on.

The login fingerprint watches the directory the retry will use: <root>/<inherited profile>, else $CLAUDE_CONFIG_DIR, else $HOME/.claude. It has three parts:

  • the ledger account: for a profile, the account the auto-switch ledger records for it; for $HOME/.claude, the rotate ledger's live profile;
  • the account in the .claude.json Claude reads for that directory, as Account identity defines it;
  • whether .credentials.json exists (lstat only; it is never opened, so an OAuth token refresh is not a change).

A file that is missing, a symlink, not owned by the current user, writable by others, too large or unparseable counts as absent, with no warning. One differing probe followed by a matching one is ignored, so a torn read while another session rewrites .claude.json does not end the wait. The fingerprint is never printed, logged or written.

The fingerprint is not the login key. The fingerprint says when a wait ends and has no readable form at all; the key is a profile name, says which waits a step may still make, and is the account= field of the recipe-log lines. They are read from different files and neither is derived from the other.

Waking only on room

A change of login is not, by itself, a reason to run the step again. When every plan login is close to its session limit, the login that arrives can be nearly as spent as the one that left, and a run of swaps can change ~/.claude several times in a few minutes. If each change ended every waiting step, each step's retry would meet a limit on a login that had no room, once per change. A reset wait or a capacity wait on a $HOME/.claude step therefore ends early only when the login the retry will use has room.

Room is the rotator's own reading, not the wait's. The rotator records last_cycle.live_room with each cycle, using the session-room test. The wait applies no threshold of its own and reads no percentage. It asks the one question, through the rotator room rule, and every way it cannot get a clear room is no room, with the one exception of a person's own profile switch, which still wakes the step.

Four exits of a $HOME/.claude step's wait can lead to a retry on the login now live. The room rule gates all four:

Exit What it needs besides the change
rotator capacity, a cycle with capacity recorded after the wait began that cycle says room
login changed, a reading after a write shows a new fingerprint the ledger's latest cycle is capacity and says room
login changed, the login key read from the rotator's own files differs from the key before the attempt the ledger's latest cycle is capacity and says room
login changed, before the wait was planned, so the retry would run at once the ledger's latest cycle is capacity and says room

"Says room" is the table under Plan room in the ledger. The first row also needs the cycle to be newer than the wait, as the rotator room rule says. The other three read the latest recorded cycle, whatever its age, and apply no freshness test: the change is the evidence that something happened, and the record says whether the login last measured could run a step. A record that says room, left by an old cycle, therefore opens these three exits when the login changes before a newer cycle has judged the login that arrived. They are closed by a latest cycle that is not capacity (stayed-unread, alerted, held, skipped, idle, or one with an alert), by one that says no room, and by a ledger that exists and cannot be used.

When the room check is closed, the change is not lost. The fingerprint still differs from its baseline, and each later write asks again. The wait ends at the first write after which the latest cycle is capacity and says room, which is the rotator's next write to its ledger. A login that has changed before the wait, with no room, is not short-circuited: the step plans an ordinary wait, and that wait ends on the exits above.

What is not gated

These cases keep the behaviour they had before the room rule, either because the rule does not apply to them or because it answers yes.

Case Why
A login-change wait It waits for one organisation's spend limit to be replaced by another organisation's credit. No capacity reading reports credit, so a room test would end it never. It keeps every exit it had. A limit that meets its retry is waited out again.
A fingerprint change on a step that does not use $HOME/.claude: an inherited profile, or $CLAUDE_CONFIG_DIR The rotator never swaps into those directories, so its room reading says nothing about them. The step keeps the login changed exit it had.
A step on $HOME/.claude whose profile root holds no rotator ledger at all There is no rotator whose reading could say no room. This is the host where a person changes the login by hand, or a host that never ran a rotator, and the step keeps the login changed exits it had. Only a missing file is this case. A ledger that exists and cannot be used closes the gate, as the table in the Rotator room rule lists.
login capacity A profile step's exit reads stored readings under auto-switch's own candidate rules, which count a login as having room below 100%. It is not a rotator signal and does not read live_room.

Stopping the rotator. amplihack profile rotate stop sends SIGTERM and removes the pid file. It records no cycle: a cycle still measuring when the signal arrives ends with the log line stop: signal received; cycle abandoned and records nothing, and a cycle that has reached its swap finishes and records as usual. A wait ends on rotator capacity only on a cycle with capacity that says room, recorded after the wait began, so a stop supplies nothing for that exit. The three login changed exits need the login to change, which a stop does not do.

A manual switch still wakes. amplihack profile switch records the outcome switched and takes no reading, so it carries no live_room. That record says room, so a step waiting on the login that was in ~/.claude before the switch ends its wait, as it did before this rule. A switched record that states live_room: false does not.

An example. A threshold swap puts login-ab live, with its session at 92%, and three steps are waiting on login-aa's limit. The default --session-at is 85, so login-ab has no room to run a step:

2026-11-19T20:31:07Z swap login-aa->login-ab live s=100% w=71% target s=92% w=64% reason=threshold

The cycle records "outcome": "swapped" with "live_room": false. It is capacity under the capacity rule, and the login did change, but no wait ends. Hours later login-ab's session window resets, a cycle stays on it and records "live_room": true, and the waits end together:

amplihack.recipe.usage_limit_wait end reason=rotator capacity
amplihack.recipe.usage_limit_wait resume attempt=2

A rotator that chooses its targets by room it can use now does not trade a login with room for one with little more, and holds a move onto a login at or above --session-at for --hold seconds (see Rotate hold), so a run of swaps between nearly exhausted logins, which used to wake every wait at each swap, does not happen. The room rule covers the swaps that still can: a plan-room swap onto a login at or above --session-at, a threshold swap onto a login without capacity, an upgrade swap, a failed-probe swap and a swap made by an older rotator.

Cost. The gate fails closed, and a wake it cannot confirm is a wake it does not make:

  • A ledger written by a rotator older than the field has no live_room, so its swapped and stayed cycles say no room. No wait ends on them until the rotator is restarted on a binary that writes the field (amplihack profile rotate stop, then amplihack profile rotate start); the waits sleep to their reset meanwhile, and a profile switch still wakes them.
  • A swap lands a moment before the cycle that records it is saved. A probe in that gap reads the latest saved cycle, whatever its age. If that cycle says room, the three login changed exits are open and the step retries on the login that has just arrived before the rotator has judged it; when that login is full, the retry meets a limit and is waited out again. Otherwise they stay closed and the rotator's write of the new cycle wakes the wait to read it. The rotator capacity exit is not open in the gap, because it needs a cycle newer than the wait.
  • The same gap is wider after a profile switch: the switched record says room until the rotator's next cycle replaces it.

Capacity wait

A capacity wait covers a limit that gives a reset wait nothing to end on: a weekly limit or a reset more than five hours away, a message that states no readable reset, a reset already behind the clock (see A reset that has already passed), a spend limit that states a weekly reset, and credit exhaustion that reaches the supervisor. Wording the supervisor does not recognise is read as a session limit. A capacity wait waits for any login with capacity, or for the failed login's own reset plus 120 s when one is stated and still ahead, then runs the step once more. With no usable reset it has no deadline.

When a capacity wait starts

A capacity wait starts for every such limit, on every kind of step, once the checks in steps 1 to 5 of Order of attempts have passed (wait enabled, a prompt that can be replayed, a limit message in a harness's shape). It makes no check for a running rotator, for a second stored login or for the kind of login the step uses. A login can gain room while the wait runs, and the wait sees it. When nothing ends the wait early, a wait for a stated reset runs to that reset and the step retries; a wait with no usable reset waits on for a login with room or a login change (Capacity wait deadline).

Limit Wait reason= of the waiting_for_capacity line
Reset still ahead, within five hours reset wait none
Weekly limit, or a reset more than five hours away capacity wait reset_too_far
No readable reset, or unrecognised wording capacity wait no_reset
Reset already behind the clock capacity wait passed_reset
Spend limit stating a weekly reset capacity wait reset_too_far
Spend limit stating no reset login-change wait spend_limit
Credit exhaustion capacity wait credits

What ends a capacity wait early depends on the step. A $HOME/.claude step is ended by a login change or a rotator cycle with room, and needs a running rotator for the second. A step under an inherited profile with auto-switch on is ended by a stored reading that shows another profile with room (see Capacity for a profile step). Neither needs the other to exist for the wait to start. The check "another login could take over" is no longer a condition of starting a wait.

The reads a capacity wait makes while it runs are bounded and local. They make no network request for any profile, excluded or not.

Another login could take over is the one read-only check this behaviour keeps. No limit starts a wait on it any more; it is asked only for a bare 429 report, which is not a limit message. It is also what "holds its own login, as auto-switch checks it" means wherever that phrase appears. It never probes the network and never writes, so it makes no request for any profile, excluded or not. It is true when the profile store holds at least one profile that:

  • is not the step's own login: the inherited profile for a profile step, or, for a $HOME/.claude step, the rotate ledger's live profile (any stored profile counts when the ledger names none);
  • is not in the auto-switch exclude list;
  • holds its own login, as auto-switch checks it: a .credentials.json file, or, on macOS, a profile with no file whose .claude.json has an identifiable oauthAccount and whose Keychain item exists. A profile whose Keychain could not be read is not a candidate. A selection that may move a launch (before its first attempt, at a usage limit, and once after a wait) prints one line on stderr for each such profile that is not excluded, hosting or lent, naming the profile and the cause; this check and the wait's own reads print nothing;
  • is a plan login, or an overflow profile that overflow= marks while the overflow gate is open; an API-key profile is never a plan login, so an unmarked one never counts (issue #1804);
  • for the marked API-key profile, has a key that passes its login check and no active API-key platform block;
  • has no recorded spend block.

These are the auto-switch candidate rules that cannot change while a wait runs, taken from the same code the selection uses (OverflowPool::could_select and rerun::login_ready), so the check never counts a login auto-switch would refuse. The rules that can change are ignored here: a profile over the threshold, or with a weekly-limit record, still counts, because it may regain capacity while the wait runs. Capacity is not required at this point; it is what a wait looks for.

A missing profile root, a store that cannot be opened, or any read error (a symlink, wrong owner, a file others can write, a malformed file) counts as false. For a 429 report that means no wait at all, and the 429 is handed back as the transient fault it is. For a step with no inherited profile, the profile store is opened only when the step's login directory is $HOME/.claude of the HOME the step runs with. A nested run with a redirected HOME therefore reads the store under that HOME, never the real user's.

Capacity wait deadline

A capacity wait's deadline is one of:

Deadline Applies when bound=
the failed login's reset + 120 s, the reset held to its kind's window the limit message states a reset that is still in the future reset+margin
none (until=none) the limit states no reset still in the future: none readable, credit exhaustion, a reset already passed, or a bare 429 none
another login's block end + 120 s auto-switch is on, and a limit block recorded on another login the step could move to ends before the row above would end the wait (issue #2967); the reset= field keeps the limit's own reset earliest_reset+margin

A stated reset still ahead is the deadline however far away it is: a weekly limit days away is waited for once, to its reset. The reset is held to its kind's window first (five hours for a session limit, seven days for a weekly one, 62 days for a spend limit), as the limit record holds it, so a forged or misread message cannot hold a step longer than that. The start line prints the held reset in reset=. The arithmetic saturates.

A reset the clock has already passed adds no deadline, so the wait for a reset behind the clock has none. Its start line still prints the stated reset in reset=, with until=none and bound=none.

A capacity wait with no deadline ends only on an event: a login with room, a login change, a stop signal or the end of the session. On a host with no rotator and no other login nothing ends it on its own, and the step prints a sentence saying so; a person ends it with amplihack profile switch or a stop signal (see A wait with no deadline). The step timeout plays no part (issue #3037). No timer ends a capacity wait (The timed parts that remain).

Capacity for a profile step

This check runs on a reset wait and on a capacity wait alike. A reset wait under an inherited profile therefore ends as soon as another stored profile is seen to have room, rather than sleeping to a reset that may be hours off while other logins are idle. It does not run on a login-change wait, whose limit is on an organisation's credit and which no reading of session capacity can lift.

A spend limit is the exception, on either kind of step. Room on another stored login never lifts an organisation spend limit that states no reset, so no capacity reading ends the wait it starts. That wait is a login-change wait, which only a change of the login in ~/.claude, a stop signal or the end of the session ends. Session capacity and organisation credit are different quantities, and only the second is what that limit is about.

A $HOME/.claude step uses the login changed and rotator capacity checks, each held to room. A step under an inherited profile with auto-switch on uses login changed and, instead of rotator capacity, checks after each write, after the fingerprint, for a profile that auto-switch would choose now. The check judges capacity from the stored readings only, and uses auto-switch's own candidate rules, so a profile with a spend block, over the threshold, on another platform, with a weekly-limit record or in the exclude list never counts. Nor does a profile whose login is lent to another directory, or whose own directory hosts another account; both states are written by an in-session swap, not by a waiting step, which takes no lease at all (see Retry login). A reading counts only when it was taken after the wait began and no more than 60 s in the future (start < observed_at <= now + 60). No /usage probe is made: a profile whose window has reset is only seen once a status line or the rotator records a new reading for it, so a wait on a profile step may run on after a login has in fact recovered. The how-to lists the reasons a wait reaches its reset with another login idle beside it, in the order to check them, under A wait that ran to its reset while another login had room.

A reset wait starts on its reset alone and does not need a rotator running. Without a rotator, though, an unattended recipe run has nothing recording readings, so such a wait usually still runs to its reset. The check itself is a set of bounded local reads, made after each write to a file the wait watches: the effective configuration, the auto-switch ledger, the readings file, a listing of the profile root to enumerate the stored profiles, and the overflow inputs, which resolve each stored profile's kind from its own files and read the rotate ledger for spend blocks and the overflow gate. Each candidate costs one further stat for its login file; on macOS a candidate with no login file and an identifiable oauthAccount also costs one Keychain lookup, measured at 18 to 23 ms for an absent item in an unlocked login Keychain, and a marked API-key candidate costs auto-switch's own login check against the profile's .claude.json and settings.json. None of them makes a network call. There is no timer, poll or retry; the check rides the reads the fingerprint already makes after a write, so a wait with no write makes none. A read that fails, and a file that is missing or damaged, counts as no candidate, so the wait runs on rather than moving the step.

The check writes nothing. It applies the same candidate rules as the auto-switch rerun check, narrowed by the freshness restriction above, but it does not print the ALERT: API key not used session=… line to the step's stderr, append it to the rotate log, or write the key-held marker. The stderr line is written on every check that finds a held set, so over a five-hour wait it would repeat around six hundred times and crowd the step's output; the rotate-log line and the marker are written once per set, and are suppressed with it.

If the key was already being held back when the wait began, the alert was written by the rerun check that ran just before it, and that is the record of why work was held off the API key. A held set that first arises during the wait, because a plan profile's reading ages out or the profile is removed, is recorded nowhere until the next launch or rerun check. A key-held marker left by an earlier check is likewise not cleared during the wait, even if the held profiles gain readings while it runs; the next launch or rerun check clears it.

One record is not suppressed, and it is not part of the step's own output: a profile marked in overflow= and detected as an API-key profile that fails auto-switch's own login check emits a WARN through tracing naming the profile and the reason, never a key value. One check reads that profile's login several times over, because the candidate rules test it as they narrow the field by organisation, make the selection, and work out which logins are being held back, so each check emits several identical warnings rather than one, and a wait of several hours leaves hundreds of them. Where the record goes depends on the tracing subscriber the process installed, and a run with none keeps no copy.

The two ways to stop them do not have the same effect on the wait. While the login check fails, the profile stays out of the candidate pool and the wait runs on as though it were not there. Fixing the profile's .claude.json or settings.json ends the warnings and makes the profile selectable, which is what the overflow= mark is for: a wait may then end on it. Taking the mark off with amplihack profile overflow remove <name> ends the warnings and leaves the profile unselectable, because an unmarked API-key profile is neither a plan login nor in the overflow order, so no selection ever chooses it.

A step pinned to a profile can therefore change account part way through a run. Where one profile must be kept for billing or data separation, there are two ways to hold a step on it:

  • turn auto-switch off (amplihack profile auto-switch off), which removes the login capacity exit along with the auto-switch reruns; or
  • put the other profiles in the auto-switch exclude list (amplihack profile auto-switch exclude <name>…, which replaces the list, so name every profile to exclude in one call), which keeps them from being chosen while leaving auto-switch on for the rest.

An explicit $CLAUDE_CONFIG_DIR, with no inherited profile, is never moved by this check at all: such a step is the login the user chose.

Retry login

Step's login After login changed After rotator capacity After login capacity
$HOME/.claude the live $HOME/.claude the live $HOME/.claude not used
inherited profile, auto-switch on the profile auto-switch chooses from fresh readings, else the inherited profile not used the profile a second selection chooses, else the inherited profile

The $HOME/.claude row holds for every kind of wait: a step with no inherited profile has nothing for the retry to choose between, so any of its exits leaves the retry on the live $HOME/.claude. In the inherited-profile row, every column holds for a capacity wait, but for a reset wait only the login capacity column does: that is the one exit which moves a reset wait's retry to another account. A reset wait that ends on login changed retries under the inherited profile, because the fingerprint watches that profile's own directory, so a change there is a new login for the same profile, and because the wait was timed by that profile's reset. The profile is passed only as a validated profile name. After a login-change wait the retry runs on whatever login is live in ~/.claude, which is the only thing that wait waits for.

Each wait chooses its own retry login, and only its own. The choice is cleared when a wait is planned, before anything else about that wait is decided, and is set again only by a wait that actually ran. A step that waits twice therefore cannot have its second retry steered by what its first wait saw, and the short-circuit in A login that changed before the wait, which returns before any wait runs, leaves the choice empty and retries on the live $HOME/.claude. The login key and the retry login answer different questions and are written at different moments: the key names the login the failed attempt ran on, the retry login says where the next attempt runs.

The second selection reads the stored readings with the same freshness window as the check that ended the wait: taken after the wait began and no more than 60 s in the future, both measured from the wait's own start, not from its end. That window is what lets the retry act on the very reading that ended the wait. Measured from the end instead, every reading taken while the step slept would count as stale, no candidate would be found, and the step would retry on the exhausted profile every time.

The reading that ended the wait is advisory, not a reservation. The candidate is chosen once to end the wait and again when the retry is built, and the second selection may find nothing: between the two, the login that showed room may have been taken by an in-session swap on this host, lent out, spend-blocked, or pushed over the threshold by a newer reading. The retry then runs on the inherited login, exhausted as it was.

Both of the lease-shaped causes, the swap itself and the login being lent out, originate in an in-session swap: it is the only move that writes a ledger entry, and so the only one that leases what it moves to. A step retrying after a wait writes no ledger entry and takes no lease; it only sets CLAUDE_CONFIG_DIR for the one attempt. Several waiting steps that read the same login at the same poll therefore all retry under it, and none of them displaces the others. Issue #2733 tracks the consequence, which is a shared login rather than a lost race.

What that costs depends on whether a reading ended the wait early, and only the case that lost something is announced:

The wait ended Second selection finds nothing Announced
login capacity — a reading showed room the room was taken in between; the step gave up a wait it could have finished yes
a capacity wait ending any other way (reset reached, login changed, rotator capacity) no login ever had room; the retry runs on the login that just recovered, which is the designed outcome no
a reset wait reaching its own deadline no second selection is made at all; the retry runs under the inherited profile, as before no
a login-change wait ending on login changed no second selection is made at all; the retry runs on the login the rotator has just made live no

The announcement is one line on the step's stderr, so the lost race is not read out of the absence of a line:

amplihack: no login has room now; this step retries under the limited profile (auto-switch)

A capacity wait has always made the second selection however it ended (#1801), because the step was waiting for some login to free up rather than for its own reset; finding none then is the expected outcome and costs one more attempt and nothing else. That is why it prints nothing. A reset wait that reaches its deadline with no other login available is unchanged in every respect.

When the retry moves to another profile, the step's stderr names it before the retry starts, in the same form as every other auto-switch move:

amplihack: a login has capacity again; rerunning this step under profile "personal" (auto-switch)

Closing line

No closing line is written any more. Until issue #3037 a wait that reached the step timeout wrote one more line after its last progress line, failed reason=step_timeout: usage limit not lifted, and the step failed while its limit still stood. A step timeout no longer cuts a wait (see The step timeout does not cut a wait), and no other timer ends one (see Removed endings). The one line the wait writes that begins failed is failed reason=prompt_cut_short, and it reports a lost prompt, not a limit.

A step that ends having met a limit, because the wait is turned off or its piped prompt could not be read to its end, is still classed usage_limit. The supervisor reports every limit an attempt meets to the recipe runner over the recovery channel, the runner records it as the run's failure_cause, and the run is classed from that field, not from the harness's words or from the sentence the step writes beside failed reason=prompt_cut_short. A relaunch of the same command resumes at that step (see A prompt that could not be read to its end). Auto-drive reads that marker and stops a loop as USAGE_LIMIT, not STUCK.

Login-change wait

An organisation spend limit that states no reset is not lifted by waiting, and another login of the same organisation would not lift it either, so a capacity wait does not apply. On a host where the rotator moves logins through $HOME/.claude, though, the login that arrives next may belong to another organisation entirely. A $HOME/.claude step that hits a spend limit with no readable reset therefore starts a login-change wait: it waits for the login in ~/.claude to change, and for nothing else.

Limit Step's login Result
Spend limit, no readable reset any step login-change wait. It needs no running rotator to start, and it has no deadline
Spend limit with a session reset any reset wait, as before: the session limit is what stops work
Spend limit with a weekly reset any capacity wait, as for a weekly limit

Only a rotator, or a person with amplihack profile switch, moves a login into ~/.claude. With no rotator running, nothing ends this wait on its own: the step waits until a person switches the login or stops the step, and its lines say so with until=none (see A wait with no deadline).

It makes none of the capacity wait's other reads, while it is being planned or while it runs. It does not run the "another login could take over" check on the stored profiles, it never consults the stored readings, and it does not watch the rotate ledger for a cycle with capacity. No reading of session capacity says whether the next login's organisation has credit, and the rotator picks what goes into ~/.claude in any case. In particular a fresh rotator cycle that does not swap, one that measures the live login and stays on it, leaves the wait in place, where on a reset or capacity wait it would end it as rotator capacity. A cycle that does swap ends the wait, recorded as login changed (see Reasons a wait ends), the end the retry acts on. Two independent readings can reach it.

This wait is not held to room, for the reason given under What is not gated. The arriving login can therefore be nearly spent; a limit or a 429 on the first attempt after the wait is waited out again rather than ending the step.

The login fingerprint notices that the directory the step would retry in has changed under it, at the write that changed it. Its baseline is read when the wait starts, so a swap that landed between the attempt failing and that reading is absorbed into the baseline.

The login key read from the rotator's own files closes that gap. It is anchored on a reading taken before the attempt was launched, so it names such a swap at the next write the wait reads. It applies to $HOME/.claude steps only, which are the only ones the rotator swaps. The same key drives the wait's mark and the short circuit before the wait.

It is wall time the budget does not see. Like every other wait, a login-change wait appends its real length to the file AMPLIHACK_USAGE_WAIT_LEDGER names, and auto-drive subtracts that from the wall time it counts. A step can therefore sit in a login-change wait, which has no deadline, without moving auto-drive's budget. That is deliberate, and it is the same bargain a reset or capacity wait makes. On a host where no swap can arrive, a person ends it with amplihack profile switch or a stop signal.

Login-change wait deadline

Candidate Applies when bound=
none (until=none) always none

A login-change wait has no deadline. The limit stated no reset, so there is no reset row, and the start line carries reset=none until=none bound=none. end reason=reset reached cannot occur. The start line also reads reason=spend_limit rather than reason=usage_limit, because a spend limit is the only limit that starts this wait; see Log lines.

Nothing bounds a wait or the chain on a timer: AMPLIHACK_STEP_TIMEOUT is not folded into any wait (issue #3037), and a stop signal is what ends a step that must stop waiting.

end reason= Retry
login changed yes, on the login now live in ~/.claude
signal no; exits 128 + signal
session ended no

A $HOME/.claude step whose limit is weekly or has no readable reset starts a capacity wait. Only a spend limit with no reset reaches a login-change wait. A login-change wait needs no running rotator to start: with none running, it waits until a person switches the login (amplihack profile switch) or stops the step.

Log lines

Each line goes to stderr and starts with amplihack.recipe.usage_limit_wait, then the event and key=value fields. Times are local, %Y-%m-%d %H:%M:%S %:z. Reset-wait and capacity-wait lines keep their fields and order; new fields are only ever added at the end. A capacity wait's start line has wait=capacity after reason=, and a login-change wait's has wait=login_change.

The start and end lines of each wait also go to the run's recipe log when there is one, and so does a reentered line, which is identical in both sinks. The end line is identical; the start line is this one with harness= dropped and account=<login> put where it was. A waiting_for_capacity line reaches it too. No other event reaches that sink.

Event Fields
start (reset wait) reason=usage_limit harness=claude reset=<time> until=<time> bound=reset+margin\|earliest_reset+margin
start (capacity wait) reason=usage_limit wait=capacity harness=claude reset=<time>\|none until=<time>\|none bound=reset+margin\|earliest_reset+margin\|none; until=none bound=none when the limit stated no reset still ahead and no other login's block end comes first
start (login-change wait) reason=spend_limit wait=login_change harness=claude reset=none until=none bound=none
reentered met=usage_limit\|rate_limit; once per re-entry, before that wait's start. met=usage_limit is also written for a passed reset, whose start is a capacity wait
progress remaining=<secs>s, or remaining=none for a wait with no deadline, every 60 s
end reason=<end reason> from the table above
resume attempt=<n>, counting every attempt in the step
skipped reason=disabled\|not_supervised\|no_limit_message; reason=ci is no longer written, because CI does not turn the wait off (issue #2911)
failed reason=prompt_cut_short; the step's piped prompt could not be read to its end, so the step fails whether or not it met a limit (see usage-limit waits). Replaces skipped reason=piped_prompt
waiting_for_capacity reason=reset_too_far\|no_reset\|spend_limit\|credits\|passed_reset harness=<name> until=<time>\|none, before the wait's start; the recipe log has account=<login> in place of harness=. until=none is followed on stderr by a sentence saying the wait has no deadline (A wait with no deadline)
no_file_events reason=unsupported\|watch_failed\|wait_failed; stderr only, once per wait, where no file event can be had (A wait with no file events)

reason= on a start line says what stopped the step, not which kind of wait followed. An organisation spend limit that states no reset, which is the only limit that starts a login-change wait, reads reason=spend_limit; every other limit reads reason=usage_limit. That includes a spend limit which also states a session reset: the session limit is what actually stopped work, so it is waited out as one and reads reason=usage_limit on an ordinary reset-wait start line. The wait= token, not reason=, is what names the kind of wait. The reason= of a waiting_for_capacity line is a different, closed set.

A reset wait:

amplihack.recipe.usage_limit_wait start reason=usage_limit harness=claude reset=2026-10-18 08:30:00 -07:00 until=2026-10-18 08:32:00 -07:00 bound=reset+margin
amplihack.recipe.usage_limit_wait progress remaining=1740s
amplihack.recipe.usage_limit_wait end reason=login changed
amplihack.recipe.usage_limit_wait resume attempt=2

A reset wait ended by a reading showing another login has room. The start line has no wait=capacity, so it does not announce that this exit is possible; the capacity check runs on a reset wait as well. The move notice after the resume is not a wait line, and names the login the retry runs under:

amplihack.recipe.usage_limit_wait start reason=usage_limit harness=claude reset=2026-10-18 08:30:00 -07:00 until=2026-10-18 08:32:00 -07:00 bound=reset+margin
amplihack.recipe.usage_limit_wait progress remaining=1740s
amplihack.recipe.usage_limit_wait end reason=login capacity
amplihack.recipe.usage_limit_wait resume attempt=2
amplihack: a login has capacity again; rerunning this step under profile "personal" (auto-switch)

The same four wait lines followed by no login has room now mean the second selection found nothing and the retry ran on the inherited login: see Retry login.

A capacity wait on a weekly limit, ended by the rotator. The reset is days away, so the wait still ends at it (plus 120 s) if nothing ends it first:

amplihack.recipe.usage_limit_wait waiting_for_capacity reason=reset_too_far harness=claude until=2026-11-05 00:02:00 -07:00
amplihack.recipe.usage_limit_wait start reason=usage_limit wait=capacity harness=claude reset=2026-11-05 00:00:00 -07:00 until=2026-11-05 00:02:00 -07:00 bound=reset+margin
amplihack.recipe.usage_limit_wait progress remaining=397080s
amplihack.recipe.usage_limit_wait end reason=rotator capacity
amplihack.recipe.usage_limit_wait resume attempt=2

A capacity wait with no readable reset. It has no deadline, and the sentence after the waiting_for_capacity line says so to the person reading stderr. Here a person's amplihack profile switch ended it, through the switched record that command writes to the rotate ledger:

amplihack.recipe.usage_limit_wait waiting_for_capacity reason=no_reset harness=claude until=none
amplihack: nothing records when this limit lifts, so this step waits with no deadline until a login has room or the login changes. `amplihack profile switch` ends such a wait for a step on ~/.claude; a stop signal ends the step. See docs/reference/usage-limit-waits.md
amplihack.recipe.usage_limit_wait start reason=usage_limit wait=capacity harness=claude reset=none until=none bound=none
amplihack.recipe.usage_limit_wait progress remaining=none
amplihack.recipe.usage_limit_wait end reason=rotator capacity
amplihack.recipe.usage_limit_wait resume attempt=2

Every wait with until=none writes that sentence; the examples below leave it out.

A $HOME/.claude step whose login the rotator had already swapped while the attempt was failing, which is the common case on a shared-login host:

amplihack.recipe.usage_limit_wait start reason=usage_limit harness=claude reset=2026-11-16 13:00:00 +00:00 until=2026-11-16 13:02:00 +00:00 bound=reset+margin
amplihack.recipe.usage_limit_wait end reason=login changed
amplihack.recipe.usage_limit_wait resume attempt=2

A login-change wait on a spend limit. It has no deadline and waits for the login to change, which here a rotator swap did. The retry runs on the login the rotator has just made live, and a limit there starts a second wait of its own, keyed to that login. With nothing to change the login, the wait goes on writing progress remaining=none each minute until a person switches the login or stops the step:

amplihack.recipe.usage_limit_wait waiting_for_capacity reason=spend_limit harness=claude until=none
amplihack.recipe.usage_limit_wait start reason=spend_limit wait=login_change harness=claude reset=none until=none bound=none
amplihack.recipe.usage_limit_wait progress remaining=none
amplihack.recipe.usage_limit_wait end reason=login changed
amplihack.recipe.usage_limit_wait resume attempt=2

A capacity wait ended by the rotator, whose retry returned a 429, so the step waited a second time. The reentered line comes once, between the first wait's resume and the second wait's waiting_for_capacity:

amplihack.recipe.usage_limit_wait waiting_for_capacity reason=no_reset harness=claude until=none
amplihack.recipe.usage_limit_wait start reason=usage_limit wait=capacity harness=claude reset=none until=none bound=none
amplihack.recipe.usage_limit_wait progress remaining=none
amplihack.recipe.usage_limit_wait end reason=rotator capacity
amplihack.recipe.usage_limit_wait resume attempt=2
amplihack.recipe.usage_limit_wait reentered met=rate_limit
amplihack.recipe.usage_limit_wait waiting_for_capacity reason=no_reset harness=claude until=none
amplihack.recipe.usage_limit_wait start reason=usage_limit wait=capacity harness=claude reset=none until=none bound=none
amplihack.recipe.usage_limit_wait progress remaining=none
amplihack.recipe.usage_limit_wait end reason=rotator capacity
amplihack.recipe.usage_limit_wait resume attempt=3

attempt= keeps counting every attempt in the step, so attempt=3 is the retry after the second wait. Neither wait has a deadline, so the first does not shorten the second. The reentered line tells a second start that follows a contradicted signal from one that follows a new login.

A reset wait whose retry met the same message, now stating a reset that has passed (the reset already behind the clock). The second start is a capacity wait whose reset= is the time already behind the clock, with until=none and bound=none:

amplihack.recipe.usage_limit_wait start reason=usage_limit harness=claude reset=2026-11-19 08:30:00 -08:00 until=2026-11-19 08:32:00 -08:00 bound=reset+margin
amplihack.recipe.usage_limit_wait progress remaining=1860s
amplihack.recipe.usage_limit_wait end reason=reset reached
amplihack.recipe.usage_limit_wait resume attempt=2
amplihack.recipe.usage_limit_wait reentered met=usage_limit
amplihack.recipe.usage_limit_wait waiting_for_capacity reason=passed_reset harness=claude until=none
amplihack.recipe.usage_limit_wait start reason=usage_limit wait=capacity harness=claude reset=2026-11-19 08:30:00 -08:00 until=none bound=none
amplihack.recipe.usage_limit_wait progress remaining=none
amplihack.recipe.usage_limit_wait end reason=rotator capacity
amplihack.recipe.usage_limit_wait resume attempt=3

The chain has no end of its own. It ends when a retry succeeds, a stop signal arrives or the session ends; the step timeout does not end it.

A stated reset of 0 or 1 is written like any other time (at -08:00, 1969-12-31 16:00:00 -08:00), and an instant the zone cannot represent is written as @<seconds>, so the start line is well formed for any past reset.

No stderr line contains credentials, account names, profile names, e-mail addresses, organisation IDs, config directory paths, config content or text copied from Claude's output. Only fixed words, event and reason tokens, times and integers are written.

The two lines that go to the run's recipe log carry one field more, account=, holding the profile name the rotator records for the login being waited on. They carry nothing else the stderr lines do not: no credential, no e-mail address, no organisation ID, no path and no text from Claude's output. That file is created mode 0600 in a 0700 directory and already holds the run's whole output.

When AMPLIHACK_USAGE_WAIT_LEDGER names an absolute path, each wait that ends also appends its real length in whole seconds, as one line, to that file. The file is created with mode 0600 and is never opened through a symlink. A failed write prints a WARNING and does not change the step's result. Auto-drive sets the variable so that its wall budget leaves waits out (Budget keys and defaults). A wait that ends before it begins, because the login had already changed, writes nothing there: no time passed.

The wait in the recipe log

The progress lines go to the step's agent-stderr file, which the recipe runner keeps but does not stream. A reader watching the run's recipe log used to see only the runner's working (Ns elapsed) heartbeat, so a step that slept for three hours looked hung, and runs were stopped on that reading.

A detached run (amplihack recipe run --detach) exports the absolute path of its log in AMPLIHACK_RECIPE_LOG, and every supervised step appends two lines to that file for each wait it makes (and a third, reentered, when a wait is entered again):

amplihack.recipe.usage_limit_wait start reason=usage_limit account=work reset=2026-11-16 13:00:00 +00:00 until=2026-11-16 13:02:00 +00:00 bound=reset+margin
amplihack.recipe.usage_limit_wait end reason=login changed

The fields, in order:

Field Value
reason= usage_limit, or spend_limit for a limit on the organisation's credit, as on stderr
wait= capacity or login_change, as on stderr; absent on a reset wait
account= the login being waited on, or unknown
reset= the reset the limit stated, or none
until= the wait's deadline, or none for a wait that has none
bound= which row set that deadline (none when there is none), as on the stderr start line

Every token means the same thing in both sinks. The line is the stderr start line with harness= dropped and account= put in its place, so one grep amplihack.recipe.usage_limit_wait over the recipe log and the step's stderr together reads as one stream. No failed reason=… line is written any more (see Closing line), so a reason= here is always a start line's.

A login-change wait therefore appears as:

amplihack.recipe.usage_limit_wait start reason=spend_limit wait=login_change account=research reset=none until=none bound=none
amplihack.recipe.usage_limit_wait end reason=login changed

The start line is what a reader needs: it says the step stopped on a spend limit, that it is waiting for the login to change rather than for a clock, which account it is waiting on, and, with until=none, that no deadline will end the wait.

Exactly one start and one end reach the recipe log for each wait. No progress, resume, skipped or failed line does: the recipe log says that the step is waiting, on which login, until when, and how the wait ended, and the step's stderr keeps the full account. A step that waits twice, on two logins, writes two pairs.

One more line can reach it: the reentered line of a limit after a wait. It has no account= and no text from the step's output, only met=usage_limit or met=rate_limit from a fixed list, so a reader sees that the signal was contradicted, and by which kind of limit, and nothing else.

The account name. It is the profile name the rotator records, read at runtime from the rotate ledger's live or the swap record's live login, as Login key describes. It is never an e-mail address, a UUID, an organisation ID or a path, and it is never read from .claude.json, whose account field may hold an address. A name that is not in the rotator's own form (1 to 64 bytes of ASCII letters, digits, ., _ or -) is written as unknown rather than trimmed to fit, so two logins can never collapse onto one identity in the log.

A host with no profile store has neither file, so every line says account=unknown and the login key is absent throughout: such a step waits once, as it always did, and account=unknown in the log is how an operator recognises that case. The same value appears when the rotator's files exist but cannot be read at that moment.

How a line is written. One write_all on a descriptor opened with O_APPEND | O_NOFOLLOW, created mode 0600. A path that is a symlink, not a regular file, owned by another user, accessible to group or others, or has more than one link is refused and nothing is written. Every failure is silent: the stderr lines already carry the information, and a log that cannot be appended to is not a reason to change what the step does.

A wait line always stands whole. Two writers share the file: the step, appending the lines above, and the detached run's copier, which forwards the runner's output as it arrives. The copier writes only whole lines. It holds back the tail of a read that stops mid-line and writes it with the rest of that line when the rest arrives, flushing the remainder with a closing newline when the pipe ends. A wait line can therefore never land inside the runner's working (Ns elapsed) heartbeat, and grep amplihack.recipe.usage_limit_wait <log> finds each line entire, whatever the timing of the runner's output. Since each writer appends whole lines to a descriptor opened O_APPEND, the two interleave by line and never by byte.

Holding the tail changes what the recipe log receives, not what the terminal receives: the run's own standard output is streamed byte for byte as before, so interactive output is unaffected. A runner that writes a very long run of bytes with no newline at all is flushed once the held tail reaches 1 MiB, rather than held indefinitely or discarded.

When nothing is written. AMPLIHACK_RECIPE_LOG unset, empty, relative, or naming a file that fails any check above means no line and no new file, and the step behaves exactly as it would without the variable. A relative path is refused rather than resolved, because the step's working directory is repository content. No parent directory is ever created.

Which runs have one. amplihack recipe run --detach sets the variable, and a run started from a terminal without it does not: its stderr is on the terminal already, so a top-level foreground run writes no recipe-log lines. A foreground run or a sub-recipe started inside a detached run inherits the variable and appends to the enclosing run's log, which is where its output is already going. That is intended: the lines land in the one log a reader is watching, and nesting does not split them across files. Only a nested run that is itself detached takes a log of its own, because a detached run overwrites the inherited value with its own path.

Nothing is ever written to the file AMPLIHACK_RECIPE_LOG_JSONL names. That file holds the runner's own JSONL schema, and appending plain text to it would corrupt it.

AMPLIHACK_RECIPE_LOG is an internal marker amplihack sets for its own children, in the same class as AMPLIHACK_TREE_ID and AMPLIHACK_SESSION_DEPTH. It is never read from a config.toml, a recipe spec or a step's declared environment, and a detached run overwrites any value it inherits, so no detached run's steps can append into another detached run's log. Do not set it by hand.

The lines are informational. A detached run copies each step's own output into the recipe log, so an agent step could print a line in this shape. Nothing reads these lines as authority, and nothing in the wait's own control path reads them back: the reentered line is written for a person, and the decision to enter again is made from the attempt's output and the wait that just ended, never from the log. Auto-drive's wall budget still comes from the separate file AMPLIHACK_USAGE_WAIT_LEDGER names, which only the wait writes, and the recipe runner's failure classification still comes from the step's own exit and evidence tail.

Usage-limit wait settings

Setting config.toml key Environment variable Default
Enabled recipe.usage_limit_wait AMPLIHACK_USAGE_LIMIT_WAIT true

It is an ordinary user-config key: set it with amplihack config set recipe.usage_limit_wait false, in the user or project config.toml, or with the variable, which outranks the files. The variable takes true, false, 1 or 0; an invalid value is reported by the config loader, by the variable's name only, and ignored. false or 0 turns the wait off, and a limit is passed up at once as skipped reason=disabled.

It is the only setting. A wait has no length: a wait for a stated reset ends at that reset plus 120 s, or sooner on room or a login change, and a capacity or login-change wait whose limit stated no usable reset has no deadline. AMPLIHACK_STEP_TIMEOUT is not a bound either (issue

3037). recipe.usage_limit_max_wait_secs has been removed: a file that

still sets it gets an unknown key warning and the rest of the file applies, and config set refuses it as an unknown key. AMPLIHACK_USAGE_LIMIT_MAX_WAIT_SECS is not read; while the wait is on, a step that finds it exported prints a warning saying so. See A wait has no length setting.

With no setting in the environment or a file, the wait is on, in CI as elsewhere: CI is not read (issue #2911). It used to turn the wait off by default and write skipped reason=ci, but amplihack's delegation layer exports CI=true to every delegated claude -p, so a recipe run started from one ended at its first limit. A job that should not wait sets recipe.usage_limit_wait = false or AMPLIHACK_USAGE_LIMIT_WAIT=0. Settings are read only when AMPLIHACK_NONINTERACTIVE is exactly 1.

Limit-resume hook

The limit-resume hook resumes an interactive Claude session stopped by a limit (StopFailure, with asyncRewake) after a rotator swap, by typing into its tmux pane or by exiting 2. A recipe step's claude -p instead exits on the limit, and this wait reruns it. The hook's session checks mean it never reruns a -p session that has already exited, so the two never both act on one limit.

Test seams

In debug builds only, AMPLIHACK_USAGE_LIMIT_WAIT_TEST_NOW (Unix seconds) sets the wait's start time and AMPLIHACK_USAGE_LIMIT_WAIT_TEST_SCALE (1 to 1000000) divides every sleep. Signals and the session check still run at least once per real second. Release builds ignore both.

Platform

The wait is Unix-only. Elsewhere the settings are never read and a usage limit ends the run as before.

Errors

Errors print one line to stderr as error: <message> plus hint: <next step> and exit with status 1. Messages never include file contents.

profile usage reports a profile it cannot read as a state on that profile's row, not as an error; only its setup failures use this format.

Condition Hint
Invalid name Lists the allowed pattern
Profile exists / not found (including overflow add on a name with no profile directory) amplihack profile list
Symlinked or out-of-root profile Remove the symlink and re-add
Pointer dangling (names a missing profile) amplihack profile switch <name>
Pointer corrupt or oversized Re-run profile switch <name>
remove without --yes Re-run with --yes
login produced a duplicate login sign out of claude.ai in your browser (or use a private/incognito window), then run 'amplihack profile login <name>' again. See Login check.
login found a new or previous login that is not a private regular file, or a .rejected-logins entry that already exists Nothing was moved; follow the paths in the message. See Login check.
login named the rotator's live profile log in with plain 'claude', or stop the rotator first. See Login check.
--profile with --docker/--auto Launch without the flag combination
Inherited AMPLIHACK_CLAUDE_PROFILE with --docker, --auto or env-activated Docker unset AMPLIHACK_CLAUDE_PROFILE and CLAUDE_CONFIG_DIR to run with --docker/--auto
Inherited AMPLIHACK_CLAUDE_PROFILE is an invalid name or not found Unset AMPLIHACK_CLAUDE_PROFILE, or create the profile with amplihack profile add <name>
Inherited AMPLIHACK_CLAUDE_PROFILE names a profile that exists but cannot be used The hint for the underlying cause, e.g. check permissions on the profile root for an I/O error or the chmod go-rwx hint for unsafe permissions
Recipe context key in the AMPLIHACK_ namespace (recipe run -c amplihack_…=…) Remove the key; the namespace is reserved
InvalidRoot: a non-empty AMPLIHACK_CLAUDE_PROFILE_ROOT, or the profile root argument, is empty, relative, not UTF-8, holds control characters or has a .. component; or HOME is unset use an absolute path: set AMPLIHACK_CLAUDE_PROFILE_ROOT to one, or run: amplihack profile root <absolute dir>
InvalidSavedRoot: ~/.amplihack/profile-root is invalid (the message names the file and the reason), or profile root <dir> cannot write it safely fix or remove ~/.amplihack/profile-root, or run: amplihack profile root <absolute dir>
Leased: the profile's login is live in another profile's session wait for that session to end, or run `amplihack profile auto-switch status`
HostsForeignAccount: the profile's directory holds another account's login wait for that session to end, or run `amplihack profile auto-switch status`
AutoSwitchConfig: .auto-switch cannot be written, the change would exceed 4096 bytes, or the settings lock stayed busy for 10 seconds (the message ends in retry; run the command again) fix what the message names and retry; do not remove <root>/.auto-switch, which holds the exclude list (see "Settings file" in docs/reference/profile-command.md)
AutoSwitchExcludeAtRisk: .auto-switch is a symlink, not a regular file, or owned by another user (no command replaces it; the message says to fix the owner with chown or replace the symlink with a regular file holding the same exclude= line), or it is a corrupt regular file of yours; in each case removing it would drop its exclude list. Either on or off is run without --exclude while it does not parse or others can write it (its exclude list is unknown), or threshold, exclude, overflow add or overflow remove needs to keep its other keys. The message names the recovery: on --exclude NAME,... or off --exclude NAME,... when the list is unknown, on or off when it is a private file of yours that parses. See Unreadable exclude list do not remove <root>/.auto-switch: that drops its exclude list, and the rotator would probe and refresh the logins it excluded; see "Unreadable exclude list" in docs/reference/profile-command.md
AutoSwitchUnsupported: an auto-switch command on a platform without Unix file semantics auto-switch needs Linux or another Unix; leave it off
AutoSwitchInvariant: the state files are damaged or a login is not where the state says see the Recovery section of docs/howto/claude-profiles.md
AutoSwitchInstall: a profile's settings.json is a symlink, owned by someone else, not a JSON object, or cannot be written fix or remove the reported file, then run `amplihack profile auto-switch repair`
RotateConfig: a rotate flag or AMPLIHACK_ROTATE_* value is not a whole number in range run `amplihack profile rotate --help` for the accepted values
RotatePrototypeRunning: the external rotator holds <root>/.rotator/lock stop the external rotator (tmux session claude-rotator) first
RotateRefused: a check before the swap failed, or the atomic exchange failed; nothing was moved. Also every profile switch refusal (no stored login, lock busy, recovery inconsistent, live login unusable) and a switch --none that found the lock busy nothing was moved; see "Swap refused" in docs/howto/claude-profile-rotation.md
profile switch moved the live login, then could not write the pin or the default pointer. Not a RotateRefused: the login did move The message itself says to run amplihack profile switch <name> again; see Rotate switch
RotateInconsistent: the rotate ledger or journal is damaged, or recovery cannot tell which way is safe see the Recovery section of docs/howto/claude-profile-rotation.md
RotateUnsupported: profile rotate on a platform without Unix file semantics rotate needs Linux or another Unix
RotateDaemon: start found a rotator running, stop timed out, the process cannot be verified, or overflow clear could not take the state lock within 10 seconds (rotator busy, retry) run `amplihack profile rotate status`

Auto-switch errors name profiles in the message; hints are fixed text. For example:

error: profile "personal": its login is in use by a session in profile "work"
hint: wait for that session to end, or run `amplihack profile auto-switch status`
error: profile "work": its directory holds the login of profile "personal" for a running session
hint: wait for that session to end, or run `amplihack profile auto-switch status`

Auto-switch notes on stderr, errors and status contain only profile names, paths relative to the root, phases, percentages and times. They never contain token values, e-mail addresses or organisation IDs.

The inherited-profile message names AMPLIHACK_CLAUDE_PROFILE, shows the value escaped (Rust {:?} form) and cut to 64 characters, and gives a fixed reason: invalid name, not found, refused path, unsafe permissions, i/o error on profile root (<kind>), not usable or not applied with --docker, --auto or Docker. <kind> is the I/O error kind, such as permission denied; it never contains the value. For example, as printed to stderr:

error: inherited AMPLIHACK_CLAUDE_PROFILE "work": not found
hint: unset AMPLIHACK_CLAUDE_PROFILE, or create the profile with `amplihack profile add <name>`

Control characters in the value are escaped, so a malformed value cannot write terminal escape sequences.

Security notes

When creating a profile amplihack reads the allowlisted assets and parses settings.json; it never modifies the source directory and never copies credential or history files. Allowlisted setting values and asset contents are copied verbatim, so any secrets embedded in hooks, status-line commands or skills remain the user's responsibility. Unix source reads are anchored to a no-follow root descriptor; non-Unix platforms have a residual same-user check-then-open race. Profiles are not a security boundary against the same OS user. The pre-spawn re-validation narrows but does not close the window between the check and exec; it is not atomic. This is defense in depth: anyone who can write the profile store already has the user's privileges.

Auto-switch moves .credentials.json files and does nothing else with them: it never opens, reads, parses, copies or refreshes them. The direct usage read and credential identity reader read credentials for their respective bounded requests. Rotation/switch ownership checks reuse the identity reader. Auto-switch's file operations are renameat2(RENAME_NOREPLACE) between two directories under the root, utimensat (without following symlinks) to set the modification time, metadata checks, and syncing the directories that contain them. Each account's login is in exactly one place at any moment. .claude.json and settings.json may contain secrets (primaryApiKey, env, apiKeyHelper): only the oauthAccount key is copied out of .claude.json, rewrites of .claude.json and settings.json keep the file's existing permission bits (setuid, setgid and sticky are dropped; a new settings.json is 0600), and parse errors report the path, line and column only. State directories are 0700 and state files 0600, and symlinks are refused, as for the profile store. Auto-switch makes no network calls. Profile usage uses the direct usage reader; rotation, switching, recovery and verification use the bounded credential identity reader when they need account evidence. The status-line wrapper runs the original command with sh -c, which is what Claude itself does with it; the supervisor for reruns starts amplihack directly with no shell.

Autostart reads only the auto-switch setting, its own setting file and /proc; it never opens a login file. It prints only the pid, and its status line only on, off and the source. It refuses a root writable by others and runs nothing as root, so another user cannot use the setting or the pid file to start a process for you. The rotator it starts keeps the AMPLIHACK_ROTATE_* values and the binary of the launch that started it; rotate.err records which binary that was.

The direct read reads a profile's .credentials.json in memory and uses its token only for that profile's row. It takes these measures:

  • The file is opened without following symlinks, must be a regular file owned by you and not writable by group or others, and is read up to 64 KiB. A token must be 1 to 4096 bytes of printable ASCII with no space. Any doubt about a token leads to the claude fallback (or to error under direct), never to a weaker check.
  • The usage endpoint and the token URL are HTTPS unless both are overridden with loopback addresses. Overrides are checked as described under Direct read, and their warnings never repeat the value. Redirects are not followed, proxies are not used, a non-200 body is never read, and a 200 body is read up to 64 KiB and parsed only with serde_json.
  • Every error on this path becomes a fixed reason. Only the HTTP status and the kind of transport error are inspected, in one function, and a source test fails the build if usage_direct.rs formats an error or a token binding in any other way.
  • A refresh is never made for ~/.claude or for a directory a login is lent to or from, because a running session may own that token. It runs under Claude's own .oauth_refresh.lock, is refused while a swap journal exists, re-reads the file under the lock, and checks the directory and file before the request is sent, so a refresh that cannot be saved is not attempted. The new file is written with mode 0600 through a private temporary file in the same directory, keeping every other field.
  • Tokens are not zeroed in memory; they are dropped when the read returns.

The fallback probe never opens, reads, logs or prints a login file or token, and amplihack writes nothing to the profile directory for it; claude may update its own files there, as any claude run does. Both attempts start claude through these command builders: build_profile_command, which profile login also uses; build_default_dir_command for a profile whose login is live in ~/.claude; and build_home_command for a login in ~/.claude that no profile owns. So the profile directory check and the CLAUDE_CONFIG_DIR rules apply to both attempts. Its arguments and the one request line it writes are fixed text, with no value from the environment, a profile or a state file in them, and no permission or tool flags. The answer is matched strictly: type, response.subtype and response.request_id must be exact, rate_limits_available and is_enabled must be JSON booleans, an answer whose extra_usage is anything other than absent, null or {"is_enabled": false} is not accepted, and a missing or non-numeric utilization is no value rather than 0. A display_name or resets_at string longer than 64 characters, or with a control character or a character in U+202A to U+202E or U+2066 to U+2069 in it, is dropped, so it reaches neither the table nor the JSON. The answer is parsed only from the 64 KiB of stdout read, with serde_json's nesting limit. A hook or plugin that writes to claude's stdout could print a forged answer before claude's own; the first match decides, so that probe's figures would be wrong, as forged /usage text would make them. claude itself still runs the project's hooks, settings and MCP servers for the working directory amplihack was started from, as any claude -p does. With ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN or CLAUDE_CODE_OAUTH_TOKEN set, whichever attempt answered, the usage is not recorded; see Refreshing auto-switch readings.

Overflow spends real money, so every uncertain case fails towards not spending: a corrupt .auto-switch gives no overflow profiles, an unreadable rotate ledger stops the cycle, a failed live probe never moves onto credits or the API key, a plan candidate whose probe timed out or could not run blocks the move onto credits or the API key, and so does a plan profile skipped as directory refused, on every cycle until the directory is fixed or the profile removed, a reset more than 8 days away counts as unknown, an answer to the usage request that reports credits on, or reports them in a form amplihack does not recognise, is not accepted, profiles marked as overflow are probed with /usage only so a spend limit is always seen, an overflow profile whose probe failed is not used, exclude beats overflow, an unknown plan reset never moves onto overflow without --overflow-unknown-reset 1, and auto-switch uses an overflow profile only under the running rotator's own gate (none when that rotator has not recorded one), with spend blocks unknown meaning none. The rotator is not a spending cap: the organization spend limit at https://claude.ai/settings/usage is the only hard limit, and a session rerun by the usage-limit wait while on credits spends them. The limit-resume hook does not resume a session onto a login whose swap record shows a plan window at 100%. Spend-block records are checked when the ledger is loaded, so a hand-edited block cannot last more than 62 days after its at. A group- or other-writable .auto-switch is corrupt and gives no overflow profiles, and every change to it goes through one locked writer that fails rather than write unlocked, so a remove that reports success is never silently undone. Overflow output holds profile names, times and the fixed usage URL; Claude's output and account e-mail addresses are never stored or printed.

Residual risks of auto-switch:

  • Processes running as you, and root, are out of scope. They can read, move or replace every file involved, including the state directory and the saved status line; the ownership, mode and symlink checks stop accidents and other users, not them.
  • Rerun buffers hold a step's stdout until the step finishes, or after a crash until the next recovery run (at most 24 hours); see Usage-limit reruns.
  • A rerun repeats the whole step, including side effects of the attempt that hit its limit.
  • The trigger is the runner's own text classifier. Output an agent was led to print (for example by prompt injection) can cost one extra attempt per profile, but only for a step that already failed with a non-zero exit and was not killed.

Identity and duplicate logins

How amplihack decides that two logins are the same account, how profile login refuses a duplicate, how a launch of the rotator's live profile is redirected, and how the default is cleared. The walkthrough is in Accounts, organizations and duplicate logins.

Account identity

For session/display callers, an account is read from the oauthAccount object of a .claude.json: accountUuid (the user), organizationUuid (the organization) and emailAddress. A value that is not a string, is over 320 bytes or contains control characters counts as missing. The e-mail address is lower-cased, and it also counts as missing unless the lower-cased form is still at most 320 bytes and has exactly one @, text on both sides of it and no whitespace. The profile endpoint's answer (account.uuid, organization.uuid and account.email), which rotation and profile verify read, follows the same rules. Only these fields are read.

Every caller that reads an account through these rules sees the e-mail rule, not only rotation: auto-switch's swap, the login checks, the duplicate-login check, the .default resolution, the limit-wait fingerprint, the direct usage read, and the check that stops a swap while Claude rewrites ~/.claude.json (#1702). For each of them, a login with no account UUID and a malformed e-mail is no account, and a record keyed by a malformed e-mail matches no login. The swap stop treats such a ~/.claude.json as unreadable, so the cycle stops as home-unreadable and nothing moves.

Left Right Same account
uuid u, org o1 uuid u, org o1 yes
uuid u, org o1 uuid u, org o2 no
uuid u, org o1 uuid u, no org no
uuid u, no org uuid u, no org yes
different uuids (any) no
uuid on one side only (any) no
no uuid on either side — the e-mail addresses match, ignoring case

Rotation and manual switching apply the same full-account comparison to trusted login evidence, rather than to session JSON. Organization changes remain identity changes. Expected records retain the legacy compatibility rules below. Standalone login, display warnings and other auto-switch callers retain their separate behavior.

The rotate ledger retains its existing fields and adds optional login_identity, populated from authorized trusted evidence. Its account remains a display key; the key alone is insufficient for a full-account ownership or recovery decision. Older ledger readers ignore the new field after #1659; the existing compatibility projection omits it when a strict older rotator is detected. Older binaries reject new journal fields/phases, so finish a pending transaction with the binary that understands its journal.

When the rotator loads the ledger, a present login_identity must meet the rule below. This is stricter than the session reading above: there, an unsafe value counts as missing, whereas in the ledger it stops the rotator. The values are the same, though: amplihack writes login_identity only from an account read under the rules above, so a block it wrote always loads again. Only a hand edit or a foreign writer can produce a block that fails.

  • it is a JSON object;
  • each of accountUuid, organizationUuid and emailAddress, where present, is a string that is not empty, is at most 320 bytes and contains no control characters (C0, DEL or C1) and no bidirectional override or isolate characters (U+202A to U+202E and U+2066 to U+2069); a key set to null, a number or any other non-string fails;
  • emailAddress, where present, contains exactly one @, has text on both sides of it and contains no whitespace, and is still at most 320 bytes once lower-cased;
  • at least one of accountUuid and emailAddress is present, so {} and a block holding only organizationUuid fail.

Other keys inside the object are ignored, and letter case is not checked. The rotator rejects a ledger that breaks the rule as RotateInconsistent, with the message rotate ledger: invalid login_identity, without echoing the value or naming the key inside the block that failed. An absent login_identity, or a top-level "login_identity": null, still loads. The error is reported and the file is never overwritten: the cycle ends with the unreadable-ledger stop, which reads rotate ledger unreadable (invalid login_identity); ..., profile switch refuses with the same line, --dry-run prints it after would alert:, and no login moves. profile rotate status shows live: - (ledger unreadable: invalid login_identity). The block is never repaired, dropped or replaced silently.

Other readers of the rotate ledger treat a refused ledger as absent, as they do for any other unreadable ledger: profile verify and the profile-kind check name no live profile, profile usage and profile overflow warn and show no API-key or spend block, and auto-switch's takeover and overflow checks fall back to the choices they make with no ledger. The Claude Code status line reads the auto-switch ledger (<root>/.auto-switch.d/ledger.json), not this one, and is unaffected.

To recover, stop the rotator with amplihack profile rotate stop. In <root>/.auto-switch.d/rotate/ledger.json, remove the login_identity key or set it to null, and keep the file at mode 0600. Then start the rotator again with amplihack profile rotate start. The block is written again only by authorised swap completion or confirmed credential-based recovery. Until then, ownership decisions refuse conservatively, as they do for a legacy ledger that holds only a UUID.

Recorded account

Each profile can have a recorded account: the account amplihack knows the profile is meant to hold. Claude can rewrite a profile's .claude.json, so the account in that file is not trusted on its own. The record is what it is compared against.

The record is <root>/.auto-switch.d/expected/<name>.json:

{
  "account": "<key>",
  "org": "<organization uuid>"
}

<key> is the account's uuid, or its e-mail address when it has no uuid. org is the login's organizationUuid, or null when it has none. The file holds nothing else: no token or display name. It is written atomically, mode 0600, owned by you and never through a symlink. It has no version field.

A record is written in five cases only:

When What is recorded
profile login <name> is accepted The account in the profile's new .claude.json. A later accepted login overwrites it. This includes a macOS Keychain login, which writes only the oauthAccount block. Nothing is recorded when that file has no account, or when the login did not finish.
A swap adopts the login in ~/.claude as default-original[-N] The trusted outgoing account, only after a complete ownership check establishes the new profile may own it. A session block cannot supply identity; unreadable claims prevent adoption.
A swap completes from a profile that has no record The trusted outgoing account, only when existing ledger/provenance and compatibility checks establish ownership and a complete trusted scan finds no other profile claiming it. Session JSON cannot backfill missing evidence. Existing restrictions after hand-change recovery still apply.
A rotate cycle seeds a live profile with no record The account from one fresh trusted reading, only with full ledger ownership and no other claim.
profile seed-record <name> --write The account from one fresh trusted reading of the profile you named, only when the seeding rules hold.

Nothing else writes a record, and profile verify --fix never does. Both seeding paths require an account uuid and an organization, and never replace an existing record. A swap never records the incoming (to) profile and never overwrites a usable record of the outgoing one. An adopted login replaces any record left under the new default-original[-N] name by a removed profile, or deletes it when the adopted login is not recorded. The adoption and backfill cases share one rule: an account that another profile holds or has recorded is never recorded for a second profile, because that other profile may be its owner. No record is ever derived from a profile name or from accounts/<name>.json. A failure to write one prints a warning and does not fail the login or the swap:

warning: the recorded account for profile 'work' was not saved: <reason>

For rotation/switch authorization, missing and unusable records are separate states. A missing record may follow the existing adoption or backfill rules with trusted evidence. An existing unreadable record, unsafe mode/owner, symlink, file over 64 KiB, invalid JSON, unusable account, or missing/invalid org makes ownership uncertain and refuses the affected operation. A warning cannot substitute for the check. No login moves and no ledger identity changes while that required evidence is unusable. Standalone login and display callers retain their existing record-reading behavior.

A record whose account is the login's uuid matches only when org equals the login's organizationUuid, both being absent counting as equal: the same user in another organization is another account, and is refused, as under the account identity rule. A record whose account is an e-mail address, written from a login without a uuid, matches any login with that e-mail, ignoring case, and the organization is not compared. This holds even when the current login has a uuid, so such a record does not tell one organization from another; the account identity rule would. A normal OAuth login has a uuid, so e-mail records are rare.

The backfill in the last row of the table is skipped when another profile holds the outgoing account or has it recorded. A profile folder can already hold another account's login, written by a Claude session started with CLAUDE_CONFIG_DIR on that folder; recording it would make the guard protect the wrong account. Such a profile stays unrecorded until its next accepted profile login or a seed that passes.

Three things read the record:

  • the duplicate-login warning, to name the profile whose login is wrong;
  • profile usage and profile auto-switch status, which print one line per profile whose login is not its recorded account, whether or not that login is also a duplicate:
warning: profile '<name>' holds a login that is not the account recorded for it; fix: run 'amplihack profile login <name>' with the browser signed out of claude.ai or in a private window.

The line names the profile, never an account. auto-switch status prints it among its notes, without the warning: prefix; - the rotate swap, which refuses to move the login in ~/.claude into a profile whose record names another account.

A profile with no record has no expected account to compare. Its display warnings may use the cannot-tell form; rotation/switch still require trusted ownership authorization. Records are created by an accepted profile login, an authorized adoption/backfill or seeding, as described above.

profile remove leaves the record in place. If the name is reused, the old record can refuse one swap; an accepted profile login <name> replaces it.

Login check

amplihack profile login <name> runs in three steps. The usual lease refusals apply first. A login to the rotator's live profile is refused before step 1, with nothing moved, because its login is ~/.claude and the rotator refuses to swap back into a profile that has a login of its own:

error: profile '<name>' is the rotator's live profile; its login is ~/.claude. Nothing was moved.
hint: log in with plain 'claude', or stop the rotator first.
  1. Before Claude starts. amplihack creates a new directory <root>/.rejected-logins/.pending-<name>-<time>/ and writes the profile's current oauthAccount block there as oauthAccount.json. It then removes the oauthAccount key from <root>/<name>/.claude.json, keeping the file's mode and its other keys, so that any oauthAccount present after Claude exits was written by this login. If <root>/<name>/.credentials.json exists, it is then renamed into the .pending-… directory, and only then is its path printed: note: holding the previous login of profile '<name>' in <path> while you log in. With no .credentials.json to hold, as on macOS, the note names the block instead: note: holding the previous oauthAccount block of profile '<name>' in <path> while you log in. A previous login that is a symlink, has more than one link or is not private stops the command here, before Claude starts, with nothing moved and .claude.json unchanged. If the key cannot be removed, nothing is moved and the .pending-… directory is removed. If the login cannot be moved after the key was removed, the block is put back first; if that also fails, the .pending-… directory is kept, because its oauthAccount.json is then the only copy of the block, and the error names it.
  2. Claude runs. amplihack ignores SIGINT while it waits, so Ctrl-C ends Claude and the restore in step 3 still runs. No lock is held.
  3. After Claude exits. amplihack takes the state lock again and checks leases again; if the profile is now leased or hosting another account, or the rotator made it the live profile while Claude ran (the rotator takes no lease), it stops, moves nothing, and prints where each login is and, whenever a block was saved, the .pending-… directory that holds it (see While Claude runs). If cleanup fails after Claude itself failed, the message starts with claude exited with an error first: and Claude's error. Otherwise:
Outcome What happens Exit
Claude exited non-zero Any new .credentials.json goes to <name>-<time>/. The previous login and oauthAccount are restored. No duplicate check. Claude's status
Claude exited 0, no new .credentials.json, no new account in .claude.json The login did not finish. The previous login, if one was held, and the earlier oauthAccount block are restored. With a held login: Claude exited without writing a login file; the previous login of profile '<name>' was restored. Without one, nothing is recorded. 1 with a held login, otherwise 0
Claude exited 0, no new .credentials.json, a new account in .claude.json, a previous login was held The macOS Keychain case: Claude keeps the login in the Keychain and writes only oauthAccount. The new account is checked for duplicates. If it is not a duplicate, the login is accepted: the previous login moves to <name>-<time>-replaced/ as for a file login, and the account becomes the recorded account. If it is a duplicate, the previous login and oauthAccount are restored; see Keychain refusal. If the check cannot run, the previous login and oauthAccount are restored, with could not check profile '<name>' for duplicate logins: <reason>; its oauthAccount was restored. 0, or 1 for a duplicate or a failed check
Claude exited 0, no .credentials.json before or after, a new account in .claude.json The macOS Keychain case with no previous login file. oauthAccount is left as Claude wrote it, even for a duplicate: restoring the old block would make .claude.json disagree with the login in the Keychain. For a duplicate the refusal is printed, but there is no file to move. Otherwise the account becomes the recorded account. 0, or 1 for a duplicate
New login is not a private regular file Nothing is moved and its mode is not changed. The error reports the mode and says the login may be exposed; the previous login stays in the .pending-… directory, and the hint prints that path. 1
New login duplicates another login Refused; see below. 1
The profiles cannot be listed, or the auto-switch state cannot be opened The check fails closed: the new login is set aside and the previous one restored as for a refusal, with could not check profile '<name>' for duplicate logins: <reason>. 1
New login is accepted The previous login, if any, moves to <name>-<time>-replaced/ and its path is printed. The empty .pending-… directory is removed. The new account becomes the profile's recorded account. 0

The new login is compared with every other profile (its own .claude.json, or its saved block while it hosts another account) and with $HOME/.claude.json. The rotator's live profile is never compared with ~/.claude, because it is refused before Claude starts.

A refusal:

  1. prints note: moving the new login of profile '<name>' to <path>;
  2. renames the new .credentials.json into <root>/.rejected-logins/<name>-<time>/ and writes its oauthAccount block there as oauthAccount.json;
  3. renames the previous login back, if there was one;
  4. sets only the oauthAccount key of <root>/<name>/.claude.json back to the saved block, or removes the key if there was none, keeping the file's mode. Other keys stay as Claude left them. .claude.json is never created. If a block has to go back but the file is missing, unparsable or not a JSON object, amplihack stops and keeps the .pending-… directory, whose oauthAccount.json is then the only copy of the block;
  5. removes the empty .pending-… directory and prints:
error: profile '<name>' was signed in to the same account and organization as <holder>. The new login was moved to <path>; '<name>' is back to its previous login.
hint: sign out of claude.ai in your browser (or use a private/incognito window), then run 'amplihack profile login <name>' again.

<holder> is profile '<other>', ~/.claude (rotator live profile '<live>') when the live profile is known, or ~/.claude.

Keychain refusal

When Claude wrote no login file but the new oauthAccount duplicates another login, there is no new file to move aside. The held login is renamed back, oauthAccount is set back to the saved block, the empty .pending-… directory is removed, and nothing is recorded:

error: profile '<name>' is signed in to the same account and organization as <holder>; Claude wrote no login file. The previous login file and oauthAccount of '<name>' were put back, but the macOS Keychain may still hold the refused account, and Claude may use it until '<name>' is logged in again
hint: sign out of claude.ai in your browser (or use a private/incognito window), then run 'amplihack profile login <name>' again.

The refused login stays in the Keychain until you sign out of it. amplihack asks only whether an item exists for a profile's directory; it never reads an item's secret or changes an item.

What counts as a new account

After Claude exits, .claude.json is read with the same bounded reader used everywhere else: no symlinks, a size limit, a JSON object only. A new account is an oauthAccount block from which an account identity can be read. An empty, malformed or unsafe block is not a new account, so it never causes a working login file to be replaced without a duplicate check. A block identical to the one before the login is a new account too: signing in again to the same account is accepted.

While Claude runs

Because the key is removed in step 1, the profile has no oauthAccount while Claude runs. During that time, a duplicate check by another profile login and the account fallback used when there is no rotator ledger do not see an account for this profile. No lease is taken for this window: the lease check runs before Claude starts and again after it exits, and the rotator decides from its ledgers.

If the profile is leased, hosts another account or was made the rotator's live profile when Claude exits, amplihack writes nothing to .claude.json and moves nothing, so the key stays removed. The earlier block is in .pending-<name>-<time>/oauthAccount.json. The message names the .pending-… directory whenever a block was saved there, including when the profile had no .credentials.json, so on macOS this message is the only place the path is printed.

If a step fails part-way, amplihack stops and prints the path of every login it has moved. It never copies or deletes one.

<time> is UTC as YYYYMMDDTHHMMSSZ. .rejected-logins/ is created 0700 under a profile root that is not a symlink; each entry directory is created new (an existing one is an error, nothing moves) and is 0700; files are 0600. amplihack never deletes anything under .rejected-logins/ except its own empty .pending-… directory and that directory's oauthAccount.json. Logins there are not listed by profile list and are never rotation or auto-switch candidates.

The check never opens, reads, copies, changes the mode of or deletes a .credentials.json; it only checks its metadata without following symlinks and renames it with renameat2(RENAME_NOREPLACE), syncing both directories. Messages contain profile names and paths only, never uuids, organization IDs or e-mail addresses. On platforms without Unix file semantics, login runs Claude as before, with no check.

Duplicate-login warning

The warning has four forms. When amplihack can tell which profile holds the wrong login, the fix names that profile:

profiles '<a>' and '<b>' are signed in to the same account and organization (duplicate login); fix: run 'amplihack profile login <wrong>' with the browser signed out of claude.ai or in a private window.

When it can tell that the login in ~/.claude is the wrong one, the fix is a /login in ~/.claude, since profile login is refused for the live profile:

profiles '~/.claude' and '<b>' are signed in to the same account and organization (duplicate login); the login in ~/.claude is not the account recorded for profile '<live>'; fix: run plain 'claude' and '/login' to the account '<live>' is meant for, with the browser signed out of claude.ai or in a private window.

Otherwise it says so. For two profiles the fix names no profile:

profiles '<a>' and '<b>' are signed in to the same account and organization (duplicate login); amplihack cannot tell which of them holds the wrong login; fix: run 'amplihack profile login <name>' for the one that should hold a different account, with the browser signed out of claude.ai or in a private window.

<name> is printed as written; it is not replaced by a profile name. For ~/.claude and a profile, the fix gives both commands:

profiles '~/.claude' and '<b>' are signed in to the same account and organization (duplicate login); amplihack cannot tell which of them holds the wrong login; fix: run 'amplihack profile login <b>' if '<b>' should hold a different account, or plain 'claude' and '/login' if ~/.claude should, with the browser signed out of claude.ai or in a private window.

A profile is mismatched when it has a recorded account and its current account does not match it. The current account is the one in the profile's own .claude.json, or its saved block while its directory hosts another account. ~/.claude has no record of its own: it is judged by the record of the rotator's live profile <live>, which is the account ~/.claude should hold, so it is mismatched when <live> has a record and the account in $HOME/.claude.json does not match it. With no live profile known, ~/.claude is not judged.

Pair Records Form <wrong>
two profiles exactly one is mismatched (the other matches its record or has none) profile the mismatched profile, whether it is <a> or <b>
two profiles one matches its record and the other has none profile the profile without a record, whether it is <a> or <b>
two profiles both match their records, both are mismatched, or neither has a record cannot tell none
~/.claude and a profile ~/.claude is mismatched; the profile matches its record or has none ~/.claude none; the /login fix
~/.claude and a profile the profile is mismatched; ~/.claude matches <live>'s record or is not judged profile the profile
~/.claude and a profile the profile has no record; ~/.claude matches <live>'s record, or no live profile is known profile the profile
~/.claude and a profile the profile matches its record, both are mismatched, or a live profile is known and neither has a record cannot tell none

A holder whose account matches its record is taken as the rightful one, and a holder of the same account without a record is named as the duplicate. This rests on how records are written (see Recorded account): profile login refuses a login another profile already holds, and a swap records an adopted login or a backfilled one only when no other profile holds that account or has it recorded. So a record for an account another holder also has was written before that holder had it. The rule is the same for two profiles and for ~/.claude, whose record is <live>'s. ~/.claude is not named when only the profile has a record, because the ~/.claude form states that it is not <live>'s recorded account, which is unknown then.

A profile that matches its record is never named. This keeps the warning in step with the rotator: when the login in ~/.claude is not <live>'s recorded account, the swap is refused with the login in ~/.claude is not the account recorded for profile <live>, and the warning names ~/.claude too, not the profile that happens to hold the same account.

For example, login-au and login-ay both hold the login-ay account, and only login-au has a record that names another account:

profiles 'login-au' and 'login-ay' are signed in to the same account and organization (duplicate login); fix: run 'amplihack profile login login-au' with the browser signed out of claude.ai or in a private window.

auto-switch status prints it as a status note on stdout. profile usage prints it on stderr prefixed with warning:, after its other warnings, and it does not change the table, the JSON or the exit status. Both cover every profile under the root, whatever names usage was given.

One line is printed per pair. Pairs of profiles follow profile list order; a pair with the login in ~/.claude comes last, with '~/.claude' as <a> and the profile as <b>. The rotator's live profile is never paired with ~/.claude. Names are cleaned of control characters. Neither form prints a uuid, organization, e-mail or the recorded key.

When the auto-switch state cannot be opened, no record can be read: every profile pair gets the cannot-tell form, and so does every pair with ~/.claude while a live profile is known. Without a live profile, a pair with ~/.claude names the profile.

Live profile launch

When amplihack claude or amplihack launch resolves a profile (from --profile, an inherited AMPLIHACK_CLAUDE_PROFILE, or the default pointer) and that profile is the one rotate live profile detection names, the launch runs with no profile: CLAUDE_CONFIG_DIR and AMPLIHACK_CLAUDE_PROFILE are not set for the child, so Claude uses ~/.claude. One line goes to stderr:

note: profile '<name>' is the rotator's live login, which is in ~/.claude; launching against ~/.claude.
Case Result
The resolved profile is the live profile Redirected, one note. The pre-spawn check, the auto-switch launch checks and the launch hold do not run, as for a launch with no profile.
Detection finds no live profile, is ambiguous, or fails Not redirected, no note.
Windows or another platform without Unix file semantics Not redirected, no note.
--docker, --auto, env-activated Docker Unchanged; these are handled before this check.
profile run <name> Not redirected. It uses <root>/<name>/.

A plain amplihack claude with an ambient CLAUDE_CONFIG_DIR you exported yourself and no profile selected is unchanged.

Clearing the default

amplihack profile switch --none
State before Output Exit
.default exists (valid, corrupt or dangling) Default profile cleared. 0
.default missing No default profile was set. 0
a name and --none together, or neither clap usage error 2
a rotation pin was removed too the line above, then Rotation released; the rotator picks the best login on its next cycle. 0
the rotate state lock stays busy for 2 seconds RotateRefused; neither .default nor the pin changes 1

--none removes the rotation pin and then <root>/.default, both under the rotate state lock, which it takes even when there is no pin. It moves no login: the login in ~/.claude stays where it is until the rotator's next cycle decides otherwise. It does not need the named profile to exist. On a platform without Unix file semantics there is no pin, and --none removes only .default.

$ amplihack profile switch --none
Default profile cleared.
Rotation released; the rotator picks the best login on its next cycle.

There is no switch default alias: default is a valid profile name, so switch default selects the profile called default.

API-key profiles

An API-key profile runs Claude Code on the Claude Platform API, which is billed per token, instead of on a claude.ai subscription login, which is billed by plan. Every other profile is a subscription profile. The code calls the API-key kind platform; every command prints it as api-key. The how-tos explain when to use one: Use an API key as the last resort and API-key profiles and usage limits.

Where the platform credential lives

An API-key profile's login file, <root>/<name>/.credentials.json, holds {} or another JSON object with no claudeAiOauth key. With no OAuth login in its config directory, Claude Code falls back to the Claude Platform credential stored under the real home directory, for example in ~/.config/anthropic/. That credential is per home directory, not per profile, so:

  • every API-key profile on a machine uses the same Platform account;
  • moving the profile's {} login file into ~/.claude makes plain claude use that account, which is how the rotator makes an API-key profile live;
  • any config directory with no OAuth login falls back to the same paid credential, which is why launches of a subscription profile with no login are refused.

amplihack never opens, reads, lists, copies or names a file under ~/.config/anthropic/. It does not create, change or test API keys, never runs apiKeyHelper, and never prints, logs or stores any part of a key.

Kind detection

The kind is worked out again on every read and never stored. Only key names and file presence are used; no value is read. All inspection of .credentials.json, settings.json and .claude.json happens in rotate/identify.rs. On macOS, one further question is asked of the login Keychain; see Keychain logins.

The first rule that matches wins. kind list prints the source shown:

Order Evidence Kind Source shown
1 A kind= entry for the profile in <root>/.auto-switch as set override
2 The login file is a readable JSON object with a claudeAiOauth key subscription detected: oauth login
2 The login file is a readable JSON object that is {} or has no claudeAiOauth key api-key detected: login file has no oauth login
2 The login file exists but is unreadable subscription, with no login detected: login file unreadable
3 (macOS) The login file is missing, .claude.json has an identifiable oauthAccount, and the login Keychain holds an item for the profile's directory subscription, with its own login detected: oauth login in the macOS Keychain
3 (macOS) As above, but the Keychain could not be read subscription, with no login, even when an API-key setting is named detected: macOS Keychain unreadable
4 The login file is missing, the rotate ledger names the profile as live, and ~/.claude/.credentials.json has a claudeAiOauth key subscription detected: live in ~/.claude (oauth login)
4 As above, and ~/.claude/.credentials.json is a readable object with no claudeAiOauth key api-key detected: live in ~/.claude (no oauth login)
4 As above, and ~/.claude/.credentials.json is missing or unreadable subscription, with no login detected: live in ~/.claude (login file unreadable)
5 The login file is missing and the profile names an API-key setting api-key detected: api key setting
6 None of the above subscription, with no login detected: no login

Only a readable {} file, or an object without claudeAiOauth, is evidence of the platform credential. A missing login file is not: on its own it resolves to detected: no login, a subscription profile with no login, which run, launch and switch refuse. A damaged or unreadable file is not either. Every doubtful case therefore refuses a launch instead of billing per token. A Keychain that cannot be read is one of those doubtful cases: it is never taken as proof of an API key.

An API-key setting is any of these names, checked for presence only:

  • ANTHROPIC_API_KEY under env in settings.json;
  • apiKeyHelper in settings.json;
  • primaryApiKey in .claude.json.

Key settings count only when the profile has no login file (rule 5), and only when the Keychain, where it was asked, did not answer that the profile holds a login or that it could not be read. They give one source, detected: api key setting, however many of them are present. A profile whose login file has a claudeAiOauth key stays a subscription profile whatever settings it names; on macOS the same holds for a profile whose Keychain item exists. kind list and show then print one warning on stderr for either kind of login, because Claude may prefer the key:

warning: profile login-av has an oauth login and an API-key setting is also configured; Claude may bill per token. Set the kind to confirm: amplihack profile kind set login-av subscription

An override silences the warning. Nothing is refused.

What counts as evidence:

  • A login file is unreadable when it exists but cannot be read, is a symlink, is not a regular file owned by you, is over 64 KiB, is not valid JSON, or is valid JSON that is not an object.
  • A settings.json or .claude.json that fails the same checks, or is writable by group or others, counts as naming no setting.
  • The oauthAccount block in .claude.json plays no part in rules 1, 2 and 4 to 6. Rule 3 uses it only as the precondition for asking the Keychain.
  • Rule 4 reads ~/.claude/.credentials.json only when the rotate ledger names the profile as live. An unreadable ledger names no profile.
  • When .auto-switch is corrupt, no override is trusted and only detection is used.

Keychain logins

On macOS, Claude Code keeps a profile's login in the login Keychain and writes no .credentials.json. Without a further rule, every such profile would resolve to detected: no login and be refused. Rule 3 of the detection table asks the Keychain instead.

Rule 3 applies only when all of these hold:

  • the platform is macOS;
  • no override names the profile as api-key (an api-key override never starts the lookup);
  • the profile's own .credentials.json is missing. A file that exists, readable or not, decides the kind by rules 1 and 2 and the Keychain is not asked;
  • the profile's .claude.json has an oauthAccount block that identifies an account, read through the same bounded reader as every other .claude.json check. A missing, corrupt or empty block means the Keychain is not asked, and the profile keeps the detected: no login refusal.

The Keychain is then asked whether an item exists for the profile's configuration directory. The service name is Claude Code-credentials-<h>, where <h> is the first eight lower-case hex digits of the SHA-256 of the absolute directory path, with no trailing slash, in Unicode Normalization Form C (NFC) and encoded as UTF-8. Claude Code normalises the directory to NFC before it hashes it, so a directory name whose accented letters reach amplihack decomposed, for example e followed by U+0301 in place of é, still names the item Claude Code wrote. A path that is already in NFC, which includes every ASCII path, is hashed as its bytes unchanged. Nothing else is done to the path, so it must be the path exported as CLAUDE_CONFIG_DIR. This is the name Claude Code gives the item when CLAUDE_CONFIG_DIR is set; amplihack reproduces it in one function and pins it with test vectors. The unsuffixed service that ~/.claude uses is not looked up, because every profile has a configuration directory of its own.

The question is one command, security find-generic-password -s <service>, found through PATH by its bare name and run with HOME set to the home directory the command was given. Its standard input, output and error are discarded, and -w, -g and -a are never passed, so the secret and the account name are never read, printed or logged. The child's environment holds only HOME, PATH, TMPDIR, USER and LOGNAME, where they are set. The exit status gives the answer:

security result Answer Kind and source
Exit status 0 An item exists subscription, with its own login: detected: oauth login in the macOS Keychain
Exit status 44 (item not found) No item Rule 3 does not apply; rules 4 to 6 follow
Any other exit status, ended by a signal, could not be started, could not be waited for, or no absolute home directory known The Keychain could not be read subscription, with no login: detected: macOS Keychain unreadable

An unreadable Keychain, for example a locked one, is never taken as proof of an API key, and it is never guessed at in a way that bills per token. It resolves as a subscription profile with no login even when the profile names ANTHROPIC_API_KEY, apiKeyHelper or primaryApiKey. The launch guard then refuses with KeychainUnreadable, which is a different message from SubscriptionNoLogin, because the remedy is different.

The same holds wherever the answer decides an outcome. A profile whose Keychain could not be read may well hold a login, so no command reports it as a profile with no login:

Where What is said
The launch guard The KeychainUnreadable refusal.
profile auto-switch status keychain unreadable in the login column.
A selection that may move a launch One line on stderr for each profile passed over: auto-switch: profile <name> was passed over: it has no login file and the macOS Keychain could not be read (<cause>).
profile overflow add <name> warning: <name> has no login file and the macOS Keychain could not be read (<cause>), so it cannot be used as overflow until the Keychain can be read: auto-switch passes it over, and the capacity file does not count it. Unlock the login Keychain; 'amplihack profile auto-switch status' then shows where its login is. The warning for a profile with no login, <name> has no login file, so it cannot be used as overflow until it has one, is not printed for it. The mark is stored either way, and the command exits 0.
The capacity file writers The selection's line, for each overflow profile left out of the count for this reason and not in the exclude list. profile usage and the status-line wrapper print it on stderr. The rotator writes it to the rotate log.

<cause> is one of the texts listed under Keychain unreadable refusal. None of these lines holds an account value or the service name.

Limits:

  • An item that exists is accepted without a validity check, as an expired login file is. A locked or expired item counts as a login, because checking it would mean unlocking the Keychain, which can raise a dialog, or reading the secret.
  • An answer of "no item" with an API-key setting named still resolves as api-key, as before. The guard cannot tell a profile that never logged in from one whose item Claude Code stored under a different name.
  • The lookup is one blocking wait for security to end. amplihack sets no time limit on it, and never sleeps, polls or kills security; the answer is the exit status security ends with. A security that is held by a Keychain dialog holds the command that asked, the rotator's cycle included, until the dialog is answered. A command that must not wait is supervised from outside, by whatever started it. No amplihack layer sets that bound yet; issue #2968 tracks which one should. Before security is started, amplihack logs the debug line starting security; the lookup waits for it to end, with no time limit with op="keychain lookup", so a command run with RUST_LOG=debug that is held by a dialog shows that line as its last one about the lookup. The line names neither the profile directory nor the service. Where nobody can answer a Keychain dialog, unlock the login Keychain before the run. Each lookup is answered by its own security, so one profile's answer never decides another's. The lookup is not retried, and a stop request to the rotator is noticed only when a lookup in progress has ended.
  • One lookup was measured at 18 to 23 ms for an absent item in an unlocked login Keychain. Each kind resolution that reaches rule 3 starts one. The check made at a usage limit and profile auto-switch status each start up to two per profile with no login file, because the kinds are resolved once for the overflow inputs and once for the logins. Nothing is cached between processes.
  • The lookup is made when the kind is resolved, which is before the launch guard asks whether the login is held elsewhere. A profile with no login file whose login is held therefore still costs a security start each time the guard runs, and its answer does not change the outcome. profile run runs the guard twice, so it starts security twice for the profile it launches.
  • Two resolutions are two lookups. If the Keychain changes between them, they can differ.
  • The naming rule belongs to Claude Code and may change between its versions. Where the name no longer matches, profiles with no API-key setting are refused at launch, and profiles with an identifiable account and an API-key setting resolve as API-key profiles, as they did before this rule existed. Nothing in that refusal says the rule changed. If every Keychain profile is refused with SubscriptionNoLogin after a Claude Code upgrade, check the service name first: printf '%s' "<profile directory>" | shasum -a 256 | cut -c1-8 prints <h> for a path in NFC (for a name with accented letters, type them composed, as printf hashes the bytes it is given), and security find-generic-password -s "Claude Code-credentials-<h>" >/dev/null 2>&1; echo $? prints 0 when the item exists and 44 when it does not. Searching the login Keychain for Claude Code-credentials in Keychain Access shows the names Claude Code now uses.
  • Only macOS runs the lookup. On Linux and other Unix systems security is never started and detection is unchanged.

The Keychain answer decides only whether a profile has a login of its own. It does not change held logins, overrides, the api-key kind or which logins the rotator may move. A Keychain login has no file to move, so the rotator's file moves and its live-profile checks do not use it.

An override of subscription keeps the kind and the override source, and the question of whether the profile has its own login is answered by the login file first and then by the Keychain, with the same three outcomes. A macOS user who has set kind=subscription for a Keychain profile is therefore launched, not refused.

Kind override

amplihack profile kind list
amplihack profile kind set <name> <subscription|api-key|auto>

The override is one kind line in <root>/.auto-switch, after the overflow line, and absent when no profile has an override:

kind=api-key:platform,spare:subscription

An override wins over detection in both directions. api-key and platform are both accepted, on the command line and in the file; the file is always written with platform. auto removes the entry. A file with no override is byte-identical to one written before kinds existed.

A kind line with an invalid profile name or a kind other than subscription, platform or api-key makes the whole file corrupt, as does a second kind line. Overrides are read only from a trusted .auto-switch, under the same rules as the other settings.

Command Behaviour
kind list Read-only. One line per profile, sorted by name: the name, the kind (subscription or api-key) and, in brackets, the source from the detection table. When .auto-switch is corrupt, first prints warning: .auto-switch is unreadable or invalid; no kind override is used on stderr. Takes no lock.
kind set <name> api-key Writes kind=<name>:platform. Prints kind: <name> is api-key (override) and the cost note below.
kind set <name> subscription Writes kind=<name>:subscription. Prints kind: <name> is subscription (override).
kind set <name> auto Removes the override. Prints kind: removed the override on <name>; detected <kind> (<source>), or kind: <name> has no override when there was none, and exits 0.

The name must pass the name rules and, except for auto, be an existing profile directory under the root; auto accepts any valid name so that a stale override can be removed. Any other kind is a usage error (status 2). kind set uses the same locked write as overflow add, with the same AutoSwitchConfig errors.

$ amplihack profile kind list
api-key   api-key       (detected: login file has no oauth login)
login-av  subscription  (detected: oauth login)
login-aw  subscription  (detected: live in ~/.claude (oauth login))
login-ay  subscription  (detected: oauth login)

Setting the API-key kind prints a cost note:

$ amplihack profile kind set api-key api-key
kind: api-key is api-key (override)
note: api-key is billed per token on the Claude Platform API key, which is stored outside the profile directory; the rotator and auto-switch use it only if you mark it with 'amplihack profile overflow add api-key', and then only after every plan and credit profile.

The override alone does not put the profile to use. An overflow= mark that is already on the profile does: it may have been given for a credit account with a spend limit, and on an API-key profile the same mark is the consent to per-token billing at tier 10. So a kind set that makes a marked profile an API-key profile also prints, on stderr:

warning: team-credits is already marked in overflow=; on an API-key profile that mark allows per-token billing on the API key, at tier 10, with no spend limit. If you did not mean that, run: amplihack profile overflow remove team-credits

When the running rotator comes from an older amplihack, kind set also prints, on stderr:

warning: the running rotator (pid 48213) is from an older amplihack and will read <root>/.auto-switch as corrupt; upgrade it, then run 'amplihack profile rotate stop' and 'amplihack profile rotate start'

profile login on an API-key profile works as before and first prints:

note: this profile uses a Claude Platform credential stored outside the profile directory, which amplihack does not manage.

A completed OAuth login gives the profile a claudeAiOauth key, so with no override it is detected as subscription from then on. Run kind set <name> auto after a login if an old override should no longer apply.

Held logins

A subscription profile's login can be away from its directory without anything being wrong. The login is held for the profile when either:

  • rotate live profile detection names the profile: the ledger and the account in ~/.claude.json agree; or
  • auto-switch records a lease or hosting record for it.

A hand-change, ambiguous or adopt result does not count. A held profile keeps the subscription kind and its launches are allowed. On macOS a held profile with no login file and an identifiable oauthAccount still has its Keychain looked up at launch, before the held check is made.

No silent billing

profile run, claude --profile, launch --profile (including a profile taken from AMPLIHACK_CLAUDE_PROFILE or the default pointer) and profile switch refuse a profile when all of these hold:

  • its kind is subscription;
  • its own login file has no OAuth login (missing, unreadable, or without a claudeAiOauth key);
  • on macOS, the login Keychain does not hold a login for the profile's directory;
  • its login is not held elsewhere.

While .auto-switch is corrupt, every profile whose own login file has no OAuth login is checked as a subscription profile; a Keychain login still counts for it. The refusal comes before any variable is set, any process is spawned, or any pointer, journal or rename is written. The command exits 1:

$ amplihack profile run old-team -- -p "reply with OK"
error: profile old-team is a subscription profile with no login of its own; launching it would bill the Claude Platform API key per token. Run 'amplihack profile login old-team', or run 'amplihack profile kind set old-team api-key' if per-token billing is intended.
hint: amplihack profile login <name>, or: amplihack profile kind set <name> api-key

The error is SubscriptionNoLogin.

Case Result
API-key profile Allowed. Work is billed per token.
Subscription profile with its own OAuth login Allowed, as before.
macOS subscription profile with no login file, an identifiable oauthAccount and a Keychain item for its directory Allowed. The login is in the Keychain; see Keychain logins.
Subscription profile whose login is the rotator's live login launch and claude are redirected to ~/.claude; switch is allowed.
Subscription profile whose login is leased to another session Refused with Leased, as before.
macOS subscription profile with no login file whose Keychain could not be read Refused with KeychainUnreadable. A profile whose login is held elsewhere is allowed, although the Keychain lookup is still made first.
Subscription profile with no login held anywhere Refused with SubscriptionNoLogin.

Plain amplihack launch with no profile, and plain claude, are not checked. For those the rotator's swap check is the safeguard: it never leaves ~/.claude without an OAuth login unless an API-key profile is moved there.

Keychain unreadable refusal

When the Keychain could not be read, the command exits 1 with a message that names the profile and says so. It gives one of five causes, and never any output from security:

$ amplihack profile run work -- -p "reply with OK"
error: profile work has no login file and the macOS Keychain could not be read (`security` exit status 51); launching it could bill the Claude Platform API key per token. Unlock the login Keychain and run again, or run 'amplihack profile kind set work api-key' if per-token billing is intended.
hint: unlock the login Keychain and run again, or: amplihack profile kind set <name> api-key

The error is KeychainUnreadable. The cause is one of:

Cause Meaning
`security` exit status <n> security answered with a status other than 0 or 44. Which status a locked Keychain gives was not measured.
`security` was ended by a signal The process was killed.
`security` could not be started No security was found on PATH, or it is not executable.
`security` could not be waited for security was started, but waiting for it failed, so it gave no exit status. It is not killed.
no home directory is known No absolute home directory was available, so nothing was started.

The refusal exists only on Unix; see API-key platform support.

API-key platform support

Kind detection, profile kind, the SubscriptionNoLogin refusal and the rotator's swap check exist only on Unix. They are compiled out on Windows and other non-Unix platforms, as are the rotator and auto-switch they build on.

The Keychain lookup exists only on macOS; Linux and the other Unix systems never start security.

On those platforms profile run, claude --profile and launch --profile start Claude with CLAUDE_CONFIG_DIR=<root>/<name> and no kind check, and profile kind is not a command. Claude Code's own fallback still applies: a profile with no OAuth login runs on the Claude Platform credential when one is configured, and that work is billed per token. On Windows, run amplihack profile login <name> before launching a profile, and do not keep a Platform credential on a machine where per-token billing is not wanted.

API-key profiles in commands

Command Behaviour for an API-key profile
list, show As for any profile.
run, claude --profile, launch --profile Launch with CLAUDE_CONFIG_DIR=<root>/<name>, so Claude uses the platform credential. No refusal.
usage Runs no /usage probe. See API-key usage.
switch See Switching onto an API-key profile.
login Unchanged apart from the note in Kind override.
overflow add Marks the profile for use as tier 10, the last tier; see API-key rotation. Prints overflow: added <name> (api-key tier, tier 10) and a cost note. --tier is refused with PlatformTierFixed; see API-key errors.
overflow remove Removes the mark. From the next cycle the profile is never moved onto; if it is live, the rotator moves off it by the exit rules.
overflow list After the marked credit profiles, one line per API-key profile: <name> api-key tier marked, or <name> api-key tier not marked (not used) when it is not named in overflow=, then blocked until <time> (<reason>) while the API-key block is active, or not used (<first> comes first) for each marked API-key profile after the first by name.
overflow clear --platform Clears the API-key block.
Duplicate-login check Skips every API-key profile: they all share one credential by design.

API-key usage

profile usage gives an API-key profile a row with no reading. Its STATE is api_key. In the bar view the cells from WEEK to S-RESET are replaced by api-key (billed per token); in --table its SESSION cell is api-key (billed per token) and the other usage cells are -. The row is marked live ((live) after the name in the bar view, live in ~/.claude in --table) when its login file is live, and has the mark blocked until <time> (<reason>) while the API-key block is active. The row never shows unparsed, timeout or failed. API-key rows sort after every usable and exhausted plan row and before the rows with no reading.

Below the rows, usage prints live: work is running on the API key (billed per token) when an API-key profile is live in ~/.claude, and blocked: the API key until <time> (<reason>) while a block is active:

$ amplihack profile usage
PROFILE         WEEK             W-RESET      SESSION           S-RESET     STATE
login-av        ██████░░░░  64%  11-01 02:00  ██████████ 100%   10-28 16:50 session_exhausted
login-ay        ███████░░░  71%  11-01 02:00  ██████████ 100%   10-28 17:20 session_exhausted
api-key (live)  api-key (billed per token)                                  api_key
live: work is running on the API key (billed per token)
times: Europe/London
order: rotator pick (most room in the worse of session and week, then name)

The same run with --table:

$ amplihack profile usage --table
PROFILE   MARKS              STATE              SESSION                     SESSION RESETS                  WEEK  WEEK RESETS                 SPEND
login-av  -                  session_exhausted  100%                        Oct 28, 4:50pm (Europe/London)  64%   Nov 1, 2am (Europe/London)  n/a
login-ay  -                  session_exhausted  100%                        Oct 28, 5:20pm (Europe/London)  71%   Nov 1, 2am (Europe/London)  n/a
api-key   live in ~/.claude  api_key            api-key (billed per token)  -                               -     -                           n/a
live: work is running on the API key (billed per token)
order: rotator pick (most room in the worse of session and week, then name)

In --json output every row gains "kind", "subscription" or "api-key", and "api_key_blocked", an object with reason and until (epoch seconds) while the block is active and null otherwise. An API-key row has "state": "api_key" and null usage windows.

Switching onto an API-key profile

profile switch <name> onto an API-key profile is allowed, because it is an explicit choice to pay per token. It runs the kind check, then the normal switch steps: the {} login file is moved into ~/.claude by the journalled rename swap, rotation is pinned to the profile and the default pointer is written. Then it prints:

note: api-key is an API-key profile; work in ~/.claude is billed per token until you run: amplihack profile switch --none

While the pin stands, the rotator does not move off the API-key profile even when a plan login has capacity, as with any pinned overflow profile. profile switch refuses an API-key profile while the API-key block is active, with PlatformBlocked. The check runs after recovery and before the live login is identified, so it also applies when ~/.claude cannot be used. The refusal writes nothing, .default included, since a launch of the default would otherwise use the blocked key directly:

error: profile api-key: the API key is blocked (key_exhausted) until 2026-12-29T10:14:03Z
hint: amplihack profile overflow clear --platform

API-key rotation

An API-key profile is used by the rotator and auto-switch only after you mark it with profile overflow add <name>. The mark is your consent to per-token billing. An API-key profile that is not marked is never moved into ~/.claude and never chosen for a launch or a rerun, whatever the readings; overflow list shows it as api-key tier not marked (not used). An API-key profile also never counts as a plan login, marked or not: it has no usage reading, so it adds no plan capacity or room, and the capacity notice can report low or exhausted with one present. A kind override of api-key does not mark a profile, and neither does its name, though it does change what a mark already on the profile allows. There is no other switch: "overflow on" means that at least one profile is named in overflow=, and the API-key profile is used only when it is one of them and the gate allows the move.

If .auto-switch cannot be read while AMPLIHACK_CLAUDE_AUTO_SWITCH=1 keeps auto-switch on, kinds are unknown. Auto-switch then selects no profile and writes no capacity file until the file is fixed; a capacity file already there is left as it is. The same holds when the profile root cannot be listed.

A session you start on an unmarked API-key profile does not count as overflow, so auto-switch never moves it onto another API-key profile. A key reports no rate limits, so the status line never moves it off the key either. Only a nested launch or a usage-limit rerun from it can move to a plan profile or a marked credit profile. Otherwise the session stays until you move it.

amplihack profile overflow add api-key

A marked API-key profile is always tier 10, below every credit overflow tier, whatever tier .auto-switch holds for it. The full order is in Rotate decision order:

  1. plan (subscription) logins with capacity;
  2. plan-room targets: plan logins with room below 100% on both windows that pass the target rule (week at or below --target-week-max, no recorded block), ranked by tier and then by room;
  3. only when no plan login has room: marked credit overflow profiles, tiers 1 to 9;
  4. then the marked API-key profile, tier 10.

overflow add stores the mark as the bare name, for example overflow=login-aw,api-key, and reads it as tier 10. A hand-written api-key:3 is read as the same mark, at tier 10. When more than one API-key profile is marked, the first by name is used and the others are listed as not used (<first> comes first). When .auto-switch is corrupt, no API-key profile counts as marked.

An unmarked API-key profile is left out of the candidates: it is never probed, never counts as plan capacity or plan room and never takes part in the headroom comparison. The rotator logs one line per process when one exists:

skip: API-key profile api-key is not marked; it is never used. To allow per-token billing, run: amplihack profile overflow add api-key

A mark given for a credit account stays in overflow= if the profile's kind later reads as API-key: from kind set, which warns, or by detection, when its login file has no OAuth login. A detected kind has no command to warn from, so the rotator logs one line per process:

warning: api-key is marked in overflow= and detected as an API-key profile; that mark allows per-token billing on the API key, at tier 10, with no spend limit. If you did not mean that, run: amplihack profile overflow remove api-key

If an unmarked API-key profile is already live in ~/.claude, for example after a hand change or an upgrade from a release that used the API key without a mark, the rotator reports it as platform_not_marked and treats it as live on the API key for the rules that move work off it, below. It moves off as soon as a plan login has capacity or is a plan-room target, never moves work back onto it, and never writes a mark for you. It does not probe the profile or give it a reading.

A marked API-key profile is never probed with /usage. Its reading is usable unless the API key is blocked. It never counts as plan capacity and never takes part in the headroom comparison. The exclude list and the candidate skip reasons apply to it, except no account.

Moving onto the API key

The rotator swaps ~/.claude onto the API-key profile, with reason=overflow-in, only when all of these hold:

  • the profile is marked in overflow= and .auto-switch can be read;
  • no plan login has room: every plan login with a measured reading, the live one included, is at 100% session or 100% week. A plan login whose probe failed, that was not measured, or that reads exhausted has no room. This is stricter than plan capacity: a plan login below 100% on both windows keeps the rotator off the API key, and the plan-room swap moves onto it when it is a target;
  • no credit overflow profile can be used: each is blocked, excluded, not a candidate or failed its probe;
  • the earliest plan reset is further away than --overflow-wait, or unknown with --overflow-unknown-reset 1;
  • the API key is not blocked;
  • the live probe did not fail;
  • the API-key login check passes.

A failed live probe never moves work onto the API key: the cycle follows the failed-probe rules as without overflow. Failed or missing probes on other plan logins count as no room, so an outage in which every probe fails could otherwise satisfy the room condition. The earliest plan reset gate prevents this: with every probe failed, no reset is known, and an unknown reset never opens per-token billing unless --overflow-unknown-reset 1 is set.

If the reset falls inside the wait, the rotator waits, as for credits. If any other condition fails, the cycle ends as it would with no API-key profile: ALERT no-capacity, or a stay.

Moving off the API key

While the API-key profile is live, these rules apply in order on every cycle. --hold, --margin and --upgrade-margin do not apply to them:

Condition Outcome
A plan candidate is a target below --session-at Swap to the plan login the ranking puts first, reason=overflow-out: the most room now, then the lower week, then the name. A plan login below 100% on both windows costs nothing, and one with its week above --target-week-max is never chosen. A failed plan probe is not a target.
No plan candidate is a target below --session-at, and a credit overflow candidate can be used Swap to the first by tier, reason=overflow-out. Credits cost less than the API key, and a move onto a login at or above --session-at would soon be followed by the move onto credits.
No credit candidate can be used, and a plan candidate at or above --session-at is a target Swap to the first-ranked one, reason=overflow-out. It costs nothing.
The API key is blocked, and nothing can be used One ALERT and stay. No swap is attempted.
Otherwise Stay on the API key.

The same rules apply to an unmarked API-key profile found live in ~/.claude.

From a credit profile the overflow rules apply unchanged; the rotator never moves from credits to the API key while a credit profile can be used, from a plan login to credits while a plan login is room, or from a plan login to the API key while a plan login has room.

API-key login check

Before every swap onto the API-key profile the rotator checks that a key is where Claude will read it after the swap. The check runs in step 6 of the cycle, under the rotate state lock, after revalidation and immediately before the journal is written. A swap moves only .credentials.json, and plain claude reads ~/.claude and ~/.claude.json, so the check reads those paths, not the profile's directory. It passes when one of these is a non-empty string after trimming:

Setting File Detail logged on success
primaryApiKey ~/.claude.json primaryApiKey set
ANTHROPIC_API_KEY under env ~/.claude/settings.json ANTHROPIC_API_KEY set
apiKeyHelper ~/.claude/settings.json apiKeyHelper set

The check reads those files with the same rules as kind detection: no symlinks, a size limit, and the file must belong to you and not be writable by group or others. An empty, whitespace, number, null or object value does not pass, and neither does a file that cannot be parsed or is not a JSON object.

A login file alone is not enough. A .credentials.json with no OAuth login, {} included, does not pass without one of the three settings, and nor does a kind override of api-key. Claude Code keeps an API key in primaryApiKey or in settings.json, not in .credentials.json, so a ~/.claude that has only that login file would start Claude as "not logged in".

A key in the profile's own .claude.json or settings.json does not pass either. The swap never copies those files or their keys, by design, so the key would be left behind in the profile's directory and the session would be "not logged in". That key is used only by a run with CLAUDE_CONFIG_DIR set to the profile, which is how auto-switch runs it. Its own check reads the profile's files for that reason.

For the rotator to use an API-key profile, the key must therefore already be in ~/.claude.json or ~/.claude/settings.json. That key is the one billed, even if the profile names a different one.

A key in those files is host-wide, and every accepted setting is used ahead of a plan login. Claude Code 2.1.316 was run in a throwaway $HOME holding a fake OAuth login and each setting in turn. The last column comes from sending a prompt to a local fake endpoint through ANTHROPIC_BASE_URL; the other columns come from runs without that variable.

Setting in $HOME claude auth status get_usage rate_limits_available claude -p /usage Credential sent with a prompt
ANTHROPIC_API_KEY under env authMethod: api_key false cost text The key, in x-api-key
apiKeyHelper authMethod: api_key_helper false cost text The key, in x-api-key and Authorization
primaryApiKey authMethod: claude.ai, apiKeySource: /login managed key true cost text The key, in x-api-key

With no setting, auth status reports authMethod: claude.ai, rate_limits_available is true and /usage prints no cost text. primaryApiKey is the case to watch: auth status and get_usage both treat the login as a subscription while the request carries the key.

The get_usage column has a limit. With a fake login no figures came back: rate_limits was null in every row, so the probe went on to /usage. Claude's schema describes rate_limits_available: false as "plan rate limits do not apply", and with true it reads the plan's usage endpoint with the OAuth login. So with a working login and primaryApiKey, figures are expected as for a plain plan login. No run with a real login has confirmed this, so both outcomes below are covered by tests.

So, while a plan login is live and one of these is present:

  • Every session bills per token. A mark does not change this, and neither does plan-first order, which is decided on plan readings.
  • What the live probe reads depends on the setting:
  • With ANTHROPIC_API_KEY under env or apiKeyHelper, get_usage gives no figures and /usage prints cost text, which is no reading. The live login reads as a failed probe on every cycle.
  • With primaryApiKey, an answer with figures is a normal reading, so the live login is treated as a plan login. The rotator moves off it at its thresholds as usual, including onto a marked API key, and the two rules below do not apply. The moves change nothing that is billed. If get_usage gives no figures, or the account has usage credits on, the probe falls back to /usage, and the login reads as a failed probe on that cycle.
  • With AMPLIHACK_PROFILE_USAGE_PROBE=text, get_usage does not run, so every setting reads as a failed probe.

On a cycle with a failed live reading:

  • The rotator does not try the per-token tier (decision order). That loses nothing: Claude is already using the key, and the move would not change what is billed.
  • The rotator makes no failed-probe swap, including one the near-threshold rule would make early. The other logins still read normally, because each is probed through its own directory and not these files. But the key applies to whichever login is live, so the login swapped in would fail its live probe the same way, and the billing would not change. The rotator stays on the live login and logs stay: live probe failed; home key (<detail>) applies to every login once live, a swap changes nothing. Swaps resume on the first cycle after the key is removed, because the live probe then reads normally.

No setting avoids this, so the rotator accepts these effects and says so. It logs ALERT: home_key (<detail>): ... once when it finds a key while a plan login is live, and again if the setting changes. The cycle carries on, because no move fixes it. profile overflow add prints the same text as a warning. A key in the rotator's own process environment gets the profile usage warning instead.

The failed-probe stay uses the check above: it needs a key in a file that check accepts. With a key only in a file the check rejects, the swap goes ahead. It may be useless, but a stay on a login that is really dead would be worse.

The ALERT and the warning do not use the check above. That check decides whether a move is allowed, so it refuses a symlink, a file others can write and a file it cannot parse. Claude may still read such a file, so a warning that money is being spent cannot depend on those rules. A separate read of the same two files follows a symlink, ignores owner and mode, and lets neither file hide the other. It decides nothing and returns only the setting's name. A file it cannot open or parse, or one over 32 MiB, counts as holding no key. It has not been shown that Claude reads a symlinked settings file: the Claude 2.1.316 results cover regular files only, so with a symlinked file the warning may be a false alarm.

A host that bills only plan logins should leave those files without a key. The rotator then refuses every move onto the API-key profile, which is the outcome such a host wants.

The check makes no network request and does not run apiKeyHelper, so it costs nothing. It shows that a key is configured, not that the key works; an invalid or unfunded key is caught later by the API-key block. The key value is never logged, printed, stored in the ledger or shown by status: the detail is one of the fixed strings above, and a failure reason names only the setting or the file.

When the check fails:

  • no swap is made, no journal is written and ~/.claude is unchanged;
  • no per-token, swap or moved line is written, and the ledger records no overflow=in for the cycle;
  • the cycle logs key_check_refused and an ALERT, and ends as alerted:
key_check_refused api-key: no primaryApiKey, ANTHROPIC_API_KEY or apiKeyHelper setting in ~/.claude.json or ~/.claude/settings.json
ALERT: API key profile api-key failed its login check (no primaryApiKey, ANTHROPIC_API_KEY or apiKeyHelper setting in ~/.claude.json or ~/.claude/settings.json); not moving onto it

The cycle does not try another profile in its place: the API-key profile is the last tier, so nothing is left to try. The ALERT is keyed by the profile, so a rotator running every 120 seconds writes it once, not every cycle. It is written again only when the stored ALERT key changes or is cleared: after a different ALERT has been written in between, or after a cycle that swaps or records stayed, since such a cycle clears the key. A stayed-unread cycle leaves the key in place. Other failure reasons are settings.json is a symlink, settings.json is writable by group or others, settings.json is not owned by you, settings.json is too large, settings.json cannot be parsed, and the same for .claude.json. Each reason is fixed text and never holds file content.

--dry-run runs the same check. The check only reads files, so the dry run needs no lock for it. A failed check prints

would_refuse api-key: no primaryApiKey, ANTHROPIC_API_KEY or apiKeyHelper setting

in place of the would swap line; a passed check prints the would swap line as usual.

The check runs moments before the swap, not at the same instant. A file changed in between is not seen until the next cycle. Only you can write those files, since a file others can write fails the check, so no second check is made.

How the swap works

The API-key profile's {} login file is moved into ~/.claude by the same journalled rename swap as any login, and the outgoing login goes back to its own profile. Nothing is copied, an interrupted swap is recovered from the journal, and ~/.claude always holds a login file. A profile with no login file cannot be swapped in; no empty file is created for it. Auto-switch passes over such a profile too, so the capacity file does not count it as usable overflow, and profile overflow add warns about it. On macOS a profile with no login file may hold its login in the Keychain; when the Keychain could not be read, the warning and the capacity file writers say that instead. A profile the rotator has already made live has its login file in ~/.claude and still counts.

Before the journal is written, the swap is refused when it would leave ~/.claude without an OAuth login and the incoming profile does not resolve as api-key. A refusal leaves no journal, renames nothing and logs:

ALERT: swap refused: login-ay has no oauth login and is not an API-key profile

Log lines for a move onto the API key

Every move onto a per-token profile writes one per-token line first. It names, in order, the rule that allowed the move, the gate result, the mark and the login check. The ordinary swap line and the moved line follow it:

per-token api-key: no measured plan login below 100%, 0 not measured; earliest reset 2026-11-01T02:14:00Z beyond overflow_wait; marked overflow tier 10; login check passed (primaryApiKey set)
swap login-ai->api-key live s=100% w=61% target s=0% w=0% reason=overflow-in
moved ~/.claude onto API key profile api-key (billed per token)

With --overflow-unknown-reset 1 and no known reset, the gate part reads reset unknown. A move onto a credit profile writes the same line, with the credit profile's tier and probe ok, no spend limit in place of the login check:

per-token team-credits: no measured plan login below 100%, 0 not measured; earliest reset 2026-11-01T02:14:00Z beyond overflow_wait; marked overflow tier 2; probe ok, no spend limit

A move off the API key onto a credit profile is tagged overflow-out, but it still bills per token, so it writes the line too. That move passes no wait gate, and the line says why it was made:

per-token team-credits: no plan login took the move; leaving the API key, credits cost less; marked overflow tier 2; probe ok, no spend limit

The line holds profile names, a time, a tier and fixed text only, never a key value or a helper command.

A swap off the API key logs:

moved ~/.claude off API key profile api-key to login-av

Several API-key profiles

All API-key profiles share one credential, so they form one pool: the rotator and auto-switch use the first marked one by name and never move from one API-key profile to another. Keep one API-key profile per root. One block covers every API-key profile, including ones added later.

When the live login in ~/.claude has no OAuth login, more than one API-key profile exists and the ledger names none of them, the live profile is ambiguous. The rotator logs once, and makes no swap until the ledger names one:

ALERT: more than one API-key profile could be live in ~/.claude; no swap

API-key block

When an agent step run under the usage-limit wait fails because the key cannot be used, the whole API-key tier is blocked. The output is checked only when the attempt ran under an API-key profile, or under ~/.claude while an API-key profile was live there. Matching ignores case. The text is matched and dropped: it is never stored, logged or printed.

Reason Matching text Block lasts
key_exhausted credit balance is too low, insufficient funds until cleared by hand
key_revoked invalid x-api-key, authentication_error until cleared by hand
key_rate_limited rate_limit_error, or 429 with rate limit until the reset or retry-after time the error gives, at most 62 days; one hour when it gives none or one in the past

Until cleared by hand is stored as 62 days after the block, the longest block a ledger may hold. When that passes, the key is tried once more and, if it still fails, blocked again.

authentication_error means "not logged in" for a subscription profile. It blocks the API key only for attempts under an API-key profile.

A block is one platform_block record in the ledger, written under the rotate state lock and only when no block is active, so two sessions failing at once record one block. Only a new block writes an ALERT:

ALERT: the API key is blocked (key_exhausted) until 2026-12-29T10:14:03Z; API-key profiles are not used

When the API-key profile is live, blocked, and no plan or credit profile can be used, the rotator stays and logs once:

ALERT: the API key is blocked (key_exhausted) and no plan or credit profile can be used; staying on api-key

If the state lock cannot be taken, the session logs platform block not recorded: <error kind> and carries on.

Clear a block once the key is funded, replaced or no longer limited:

$ amplihack profile overflow clear --platform
overflow: cleared the API-key block (key_exhausted)

With no block it prints overflow: the API key is not blocked and exits 0. overflow clear --platform cannot be combined with a profile name.

Bare claude sessions that amplihack does not supervise are not read. The rotator does not probe the key, because a probe costs tokens.

API-key status

rotate status and auto-switch status print one line while the ledger's live_kind is platform:

~/.claude is on API key profile api-key: work is billed per token (since 2026-10-28T14:02:11Z)

rotate status also prints an api key: line: the API-key profile the tier uses, followed by (marked) or (not marked), and the active block when there is one; - when there is no API-key profile. When the live login is an API-key profile that is not marked, the line ends with platform_not_marked:

api key: api-key (not marked)
api key: api-key (marked)
api key: api-key (marked) (blocked until 2026-12-29T10:14:03Z, key_exhausted)
api key: api-key (not marked) platform_not_marked

The overflow: line lists every marked profile, credit and API key, and reads overflow: - when nothing is marked.

The ledger is the only evidence; nothing is probed. The on overflow line reads yes (<name>) while an API-key profile is live. A block is shown by profile usage and overflow list.

API-key log lines

Every line the rotator writes to the rotate log about the API-key tier. Each ALERT is written once per change of state.

Line When
per-token <name>: no measured plan login below 100%, 0 not measured; <gate>; marked overflow tier 10; login check passed (<detail>) Before the swap line of a move onto the API-key profile. See Log lines for a move onto the API key.
moved ~/.claude onto API key profile <name> (billed per token) After a swap onto the API-key profile.
moved ~/.claude off API key profile <name> to <target> After a swap off it.
ALERT: the API key is blocked (<reason>) until <time>; API-key profiles are not used A new API-key block.
ALERT: the API key is blocked (<reason>) and no plan or credit profile can be used; staying on <name> The live API-key profile is blocked and there is nowhere to go.
ALERT: more than one API-key profile could be live in ~/.claude; no swap The live API-key profile is ambiguous.
ALERT: swap refused: <name> has no oauth login and is not an API-key profile The swap check refused a target.
skip: API-key profile <name> is not marked; it is never used. To allow per-token billing, run: amplihack profile overflow add <name> An API-key profile exists and is not named in overflow=; once per rotator process.
skip: API-key profile <name> is marked but not used; another comes first by name More than one API-key profile is marked; written for each one after the first by name, once per rotator process.
key_check_refused <name>: <reason> The login check failed; no swap.
ALERT: home_key (<detail>): <effect> A key in the $HOME files is billing plan sessions per token; see the login check.
ALERT: API key profile <name> failed its login check (<reason>); not moving onto it Written with the refusal, once per profile until another ALERT or a passing check.
platform block not recorded: <error kind> A session saw a key error but could not take the state lock.

API-key ledger fields

The rotate ledger keeps version: 1 and gains these optional fields. Older ledgers load unchanged.

Field Contents
live_kind "platform" while live is an API-key profile; absent means subscription. Only present with live. The rotator checks and repairs it on every cycle; it is kept for readers, such as the limit-resume hook, that cannot detect kinds.
platform_block {"reason", "at", "until"}, with reason one of key_exhausted, key_revoked or key_rate_limited, and 0 < at < until <= at + 62 days; absent when there is no block. Expired blocks are removed the next time the rotator records a cycle.
no_room {"at", "until", "profiles"}: the profiles the last measuring cycle found with no room (a reached limit, or a window at 100%), sorted, never the API-key profile and never one whose probe failed. at is when the cycle measured; until is two --intervals plus the cycle's own length after the record was written, so a slow cycle's record is still in force when the next one arrives, and at most one hour after at. It is earlier when a profile the record names has a known reset before then: the whole record ends at the earliest reset of a full window, or the later reset of a profile with both windows full, because that profile has room again. A profile no longer named is unread, so auto-switch holds the API key back until the next record. Written every measuring cycle whatever the capacity state; auto-switch reads it while at <= now <= until, for profiles it has no reading of.

The limit-resume hook reads live_kind and platform_block without failing on a missing or wrongly typed field, and treats a live API-key profile as on the API key, not as plan capacity.

API-key profiles and auto-switch

Auto-switch uses the same tier order, wait gate and move-back rules as the rotator, taken from the same function, so the two agree on which profile is the API-key candidate. An API-key profile that is not marked with overflow add is left out of that order and never chosen. Auto-switch never chooses a credit or API-key profile while any plan profile, the current one included, has room below 100% on both windows.

Before it records a move onto the API-key profile, auto-switch runs the login check against the profile's own .claude.json and settings.json, not the ~/ files, because the launch or rerun has CLAUDE_CONFIG_DIR set to that profile. When the check fails, nothing is moved, no journal entry is written, and the launch or rerun goes ahead on its current profile, or on the plan profile it would choose if the current one cannot be used. It never falls through to another credit or API-key profile in place of the refused one. A warning naming the profile and the reason is written to the auto-switch log.

The platform login is never lent to another profile's session, and an API-key profile's directory never hosts another account's login, because the credential is shared across the home directory. Auto-switch therefore uses an API-key profile only for a new nested launch or a usage-limit rerun, which runs in that profile's own directory, and never swaps it into a running session. A session started in the API-key profile's directory is not moved mid-session; once plan capacity returns, its next nested launch or rerun goes back to a plan profile. Sessions in ~/.claude leave the API key when the rotator moves the login.

Upgrading from the implicit API-key tier

This release changes two things that a running host notices.

The API key needs a mark. Earlier releases used every API-key profile as the last tier without a mark. After the upgrade an API-key profile is used only once it is marked. A host that relied on the implicit tier keeps its API-key profile unused until you run:

amplihack profile overflow add api-key

Until then overflow list shows api-key api-key tier not marked (not used), rotate status shows api key: api-key (not marked), and the rotator writes the skip: line in API-key log lines once per process. Nothing is marked automatically, no migration runs, and .auto-switch is not changed by the upgrade.

An unmarked API-key profile that is live in ~/.claude at the upgrade stays live under the exit rules, and keeps billing per token, until a plan login has capacity or is a plan-room target, or a credit overflow profile can be used. Once the rotator moves off it, it never moves back onto it. rotate status reports it as platform_not_marked meanwhile. If you do not want per-token billing in the meantime, either mark it with overflow add to accept it, or move off it by hand with profile switch to a plan login.

Credits start later. Earlier releases moved onto a credit overflow profile once every plan login had reached --session-at or --week-at. Credit profiles are billed too, so they now wait for the same condition as the API key: no plan login, the live one included, below 100% on both windows. Until then the plan-room swap uses the first-ranked plan login, and the rotator stays and writes a stay note or the ALERT when there is none.

API-key errors

Condition Message Hint
SubscriptionNoLogin: run, claude, launch or switch named a subscription profile with no OAuth login of its own that is not held profile <name> is a subscription profile with no login of its own; launching it would bill the Claude Platform API key per token. ... (in full under No silent billing) amplihack profile login <name>, or: amplihack profile kind set <name> api-key
PlatformTierFixed: overflow add --tier N named an API-key profile profile <name> is an API-key profile; the API-key tier is fixed at 10, so --tier cannot be set run `amplihack profile overflow add <name>` without --tier
PlatformBlocked: switch named an API-key profile while the API-key block is active profile <name>: the API key is blocked (<reason>) until <time> amplihack profile overflow clear --platform
AutoSwitchConfig or AutoSwitchExcludeAtRisk from kind set: .auto-switch is busy, or is corrupt, a symlink or another user's as for the other settings commands as for the other settings commands

Messages hold profile names, kinds, reasons and times only. No message, log line, ALERT or ledger field holds a byte read from a login, settings or .claude.json file.