Expand description
One refresh at a time per Claude config dir (#6081).
The Claude CLI refreshes its own OAuth token, and the refresh token rotates: a refresh spends
the old one. Two CLIs that start on the same CLAUDE_CONFIG_DIR while its access token has
expired both refresh; the second presents the token the first just spent, is refused, and
can leave the dir signed out. A boot does exactly that: every pane that shares an identity
resumes within milliseconds, and an ambient side call (Haiku) joins them.
So while a dir’s token is expired, one process goes first and the rest wait:
- the first spawn finds no entry and an expired token, and takes the dir (
Entry::owneris its block). It runs at once; its CLI does the refresh; - a later spawn, or an ambient call, on that dir waits until the token is fresh again, the
owner’s first turn has ended or its process is gone, or the owner’s hold runs out:
GATE_GRACEuntil its process is up,WARM_MAXafter. Those that waited startSTAGGERapart, so a dozen panes do not all hit the API in the same millisecond; - an ambient call takes the dir itself when the token is expired and nobody has it.
An owner whose hold runs out (a resumed CLI that waits for its first prompt before it
refreshes, or a refresh that failed) does not hand the dir to the next waiter: the dir is
unclaimed for SETTLED_FOR, so the panes behind it go together rather than one by one.
This never refreshes a token itself and never blocks for good: a dead refresh token or an
owner that never reports back costs one hold. The wait comes before the account is resolved
(inject_after_warmup), so the status the spawn gate reads is the one after the refresh, not
before it.
Structs§
- Ambient
Guard - Holds a dir for an ambient call while its token is expired; frees it when dropped.
Constants§
- GATE_
GRACE - The longest it stays taken by a spawn whose process has not started: the time the gate and the env take. A spawn that fails after the dir was taken (a gate refusal, a deleted agent) holds it no longer than this.
- SETTLED_
FOR - How long a dir stays unclaimed after an owner’s hold ran out.
- STAGGER
- The gap between spawns that waited on the same dir.
- WARM_
MAX - The longest a dir stays taken once its owner’s process is up and its first turn has not ended. A CLI that refreshes does so in its first seconds; one that waits for a prompt first (a resumed pane) must not hold the panes behind it for long.
Functions§
- ambient_
gate - Wait before an ambient CLI runs on
config_dir(itsCLAUDE_CONFIG_DIR) while a spawn on it is refreshing the expired token. No dir, or a blank one: the call has none of its own to protect. - inject_
after_ warmup inject_identity_env_async, after waiting for this block’s dir: the single-flight comes first, so the account the gate resolves and the status it probes are the ones after the refresh. A block with no bound Claude dir goes straight through.- release
- A spawn on
block_id’s bound Claude dir is over, or its first turn is: whoever waited on it may go. Cheap and safe to call on every turn end and every process exit. - started
- The CLI process for
block_idis running: its first turn may takeWARM_MAXto end.