See account launchers for daily use, first-time initialization, new-account login, and completion. Paths below use the configured <codex_home> (default ~/.codex) and <secrets_dir> (default ~/.secrets); see configuration.
codex-as ayting
codex-as work resume --last
codex-as ayting exec --json "Check the tests"Existing accounts launch directly. Missing accounts require confirmation, followed by native device login in an empty temporary CODEX_HOME; after saving complete JSON credentials, the original command continues. No sourcing or separate initialization step is needed.
Apart from -h (--help), the launcher has its own queries, none starting Codex or opening a credential: codex-as -l (--list) prints the account names (what Bash completion offers), codex-as --labels prints them with their last-seen emails (the zsh descriptions), codex-as -i NAME (--info NAME) prints the last-seen email, plan and usage of one account, and codex-as --show-config prints the configuration file in use, the codex executable, <codex_home> and <secrets_dir>. Each but -i NAME is accepted only as the single argument; the aliases --list-accounts, --account-labels and --account-info NAME are accepted too, and any other dash word before NAME is refused with a hint that Codex options go after it (see own options).
codex-as work resume SESSION_UUID
codex-as work resumeOrdinary codex resume can reuse a root daemon's loaded session. An account
launch uses an independent backend to keep authentication fixed, so the root
daemon must release a session before the account can write it; otherwise native
Codex shows "This conversation is open in another app". Before an interactive
resume starts, the launcher releases such sessions through native
archive/unarchive:
- An explicit
resume UUIDheld by the root daemon is taken over without a prompt when the session and its loaded spawned agents reportidle(orsystemError). When any of them may be running (an active turn, any other status, or a backend that reports none), the launcher asks first. The status is a snapshot: a turn that starts just before the archive is still ended. resume --lastopens one session: the most recently updated one native Codex lists (the state database first, then a scan), a top-levelcliorvscodesession of the launch directory (-C/--cdincluded) or, in a Git repository with linked worktrees, of the same place in another checkout (same common directory and prefix); any directory with--all, andexecandappServersessions too with--include-non-interactive. Native Codex opens nothing when that session's rollout file is gone. The launcher asks the root daemon'sthread/listthe same question, with native's list of directories, and takes over only that session, when the daemon holds it and it is idle; if it may be running it stays and is named, and native Codex opens it into its conflict screen.- The picker selects inside native Codex, which reports the choice nowhere
outside its process, so the launcher cannot wait for it. Before it starts, it
takes over the idle top-level sessions the root daemon holds that the picker
lists by default: the same directory and source rules, the
openaiprovider, a first message (native lists no empty session) and not ephemeral. It names them on stderr, including ones not selected afterwards. Native unarchive refreshes their modification time, so they move to the top of the picker. Sessions that may be running are left alone and named; selecting one shows the native conflict screen, andcodex-as NAME resume UUIDasks before ending it. Spawned agents follow their parent. A daemon-held session from another directory, reached by switching the picker to all sessions, also shows the conflict screen; R cannot help there, so quit and rerun with--allorcodex-as NAME resume UUID. - The directory match uses resolved paths and Git's common directory, so it can be slightly wider than native in rare layouts (a symlinked alias of the directory, bare-repository worktrees, or the Worktrees feature disabled). Linked worktrees need git 2.31 or newer on PATH; without it only the directory itself matches.
- A resume command with an option the launcher does not know takes nothing over
and says so: clap rejects a typo such as
--latsonly after the launch. Its operand may then be that option's value, so a session name is not refused. - A session held by any other process, such as another terminal or an IDE extension's own backend, is never touched; native Codex shows its conflict screen. Help, exec and fork never take over. A daemon-held session that is already archived is refused; unarchive it in the original client first.
Takeover ends the selected session and its spawned descendants in the root
daemon, so every client attached to it closes that session: Desktop, or a plain
codex TUI that attached to the daemon. Native archive/unarchive temporarily
changes their saved visibility. The launcher restores visible descendants and
keeps already archived descendants archived before starting the account backend.
Other daemon sessions remain loaded. SessionEnd hooks run, and the session's
modification time becomes the takeover time; runtime execution and hook effects
cannot be rolled back. The session UUID
and saved history remain available. Native writer locks still prevent a second
writer if shutdown is delayed or another client resumes the thread concurrently,
for example a Desktop that reopens the session right after the unarchive; native
Codex then shows its conflict screen. The lock probe briefly holds a free writer
lock, so a native client opening it at that instant also sees the conflict screen.
Before archive, a 0600 recovery journal is written and synced, including its
directory, under <codex_home>/accounts/.locks/UUID.handoff.json; a per-UUID lease
next to it serializes takeovers and is removed when one ends. A timeout,
disconnect or interruption with unknown archive completion retains the journal.
The next resume, fork or exec resume of that UUID, or the next picker or
--last launch whatever its directory, finishes the recovery without a prompt.
Recovery only restores saved visibility: resume UUID then takes that session
over as usual, and the picker and --last take it over only by their own
rules; fork and exec resume never take over. A journal that does not parse was torn
before its archive started, so it is removed, even without a running daemon.
Root unarchive serializes behind any preceding native archive before descendant
visibility is restored. An explicit UUID, and --last for the session it
opens, do not launch the account backend while that session's recovery remains
incomplete, because native Codex would open it archived or open another one;
the picker warns and launches. Both point to the preserved records in
<codex_home>/accounts/.locks when the daemon is not running. --last chooses its session after recovering the others, since
a restored session becomes the newest. Keep the journal until the helper
removes it. Declining the confirmation leaves session state untouched.
This flow accepts root daemons at 0.161.0 or newer; it needs a controlling
terminal only to confirm a session that may be running. It verifies the private
Unix socket and returned home/version without starting or stopping a daemon. A
daemon that fails these checks is not used, and native Codex shows its conflict
screen. Without a running daemon the picker and --last print nothing unless
recovery records are preserved; an explicit UUID held by another process warns
and launches.
There is no version allowlist. The launcher accepts codex-cli 0.161.0 or newer,
for a launch with a usage reserve as for any other,
including prereleases of later versions (a prerelease precedes its release, so
0.161.0-alpha.1 is refused), and refuses version output it cannot parse.
0.161.0 is the oldest release with a recorded pass of the native suite below. In
the recorded runs of older releases, 0.160.1 and 0.158.0 fail its daemon
takeover fixture, and 0.155.1 also fails the refresh writeback test and lacks
--no-daemon. The launcher relies on these runtime rules instead:
- Arguments are forwarded unchanged after the launcher's own
-c cli_auth_credentials_store="file"and-c sqlite_home=...; every command butexecalso gets-c check_for_update_on_startup=falseand--no-daemon(not repeated when the caller gives a root--no-daemon, which clap allows once). A launch with a usage reserve adds the guard's two hooks and turns goals off before the caller's arguments. Subcommands and options added by later releases pass through; the launcher never parsescodex --help. - A help or version flag before any subcommand or prompt (
NAME --help,NAME -V),help,updateandcompletionare the same for every login, so they run as plaincodexwith the rootCODEX_HOME, no added flags and no environment or configuration checks; the argument refusals below still apply first, socodex-as NAME -c chatgpt_base_url=URL --helpis refused. A help flag later in the command line may belong to a program Codex runs, so it uses the account as usual. An account's ownupdatewould install under itsCODEX_HOME, and the update prompt is turned off in account launches for the same reason. - Refused:
loginandlogout, which revoke the account's tokens (login statusand their--helppass), andapp-server --startup-sign-out, which signs the account out and revokes its tokens aslogoutdoes;agents,queue,app(a subcommand only on macOS and Windows; elsewhere a prompt word), anyremote-controlsubcommand andapp-server daemon, which need or start a daemon in the account home (foregroundremote-controland otherapp-servermodes pass, and so doesdaemonas a schema generator's word, as inapp-server generate-ts --out daemon);--remote,--remote-auth-token-env,--ossand--local-provider. Settings are checked by exact key: in-c, user and system configuration and the-pprofile file,model_providerother thanopenai, endpoint or credential keys ofmodel_providers.openai,chatgpt_base_urlandopenai_base_url; everywhere, project configuration included,forced_login_method,forced_chatgpt_workspace_idand the featureuse_agent_identity(also through--enableandfeatures enable). Native drops the provider and endpoint keys from project configuration, so they pass there.-ccannot setcli_auth_credentials_store,sqlite_homeorcheck_for_update_on_startup, which the launcher sets itself, and a-ctable or array is refused when it uses TOML 1.1 syntax (such as a trailing comma in an inline table) that this Python'stomllibcannot read. -p NAMEand--profile NAMEselect profile v2, which layers<codex_home>/NAME.config.toml: the launcher links that file into the account home, where native Codex reads it, and checks it like the user configuration (absolute paths, the sharedsqlite_home). A legacyprofilekey is a native error, and[profiles.*]tables are never applied, so neither is checked.mcp loginandmcp logoutauthenticate MCP servers and pass through. Words after a known subcommand are its own (a sandboxed command line, a review branch, a prompt), so they are never read as subcommands; before one, a root prompt does not end clap's subcommand recognition, socodex-as NAME hello logoutis refused.- Also refused, by name with values hidden: environment variables that native
Codex reads as a login, token endpoint or billing scope (
CODEX_API_KEY,CODEX_ACCESS_TOKEN,OPENAI_API_KEY, which realtime voice uses as its login,OPENAI_ORGANIZATION,OPENAI_PROJECT, the token and login URL overrides and the workload identity variables); aCODEX_HOMEother than<codex_home>or an initialized account home in<codex_home>/accounts; aCODEX_SQLITE_HOMEor projectsqlite_homeother than the shared one; relative path fields in shared configuration; and an administratorcli_auth_credentials_storeother thanfile. Variables no supported release reads as Codex's own login, such asOPENAI_ORG_ID, pass, and so doesOPENAI_BASE_URL, which only routes the user's own API key for programs Codex runs. - A future subcommand that changes authentication would also pass through; the exit repair described in account launchers detects a removed or replaced link, but a server-side revocation cannot be undone.
- That exit repair still detects an auth link replaced by a regular file and imports it only when the identity matches and secrets are unchanged. Either way the launcher warns, because the tested releases write through the link.
- Takeover accepts any backend version at or above the minimum; a protocol or semantic mismatch stops it, and once its journal is written that journal is kept until a later run recovers.
After codex update, run tests/codex-as.sh; it uses the codex on PATH, or
CODEX_NATIVE_BINARY. For usage reserves also run tests/codex-guard.sh,
whose RealCodex cases check the guard's hook contract offline against the
codex on PATH only. Recorded passing runs of tests/codex-as.sh, by the kit
release whose code and suite ran:
| Kit | Codex releases | Takeover daemon / client |
|---|---|---|
| 0.7.7 | 0.167.2 | not run |
| 0.7.5 | 0.163.0, 0.166.0, 0.167.0 | 0.163.0 / 0.167.0, 0.167.0 / 0.163.0 |
| 0.1.0 | 0.161.0, 0.162.1, 0.163.0 | 0.161.0 / 0.163.0, 0.162.1 / 0.163.0, 0.163.0 / 0.161.0 |
A root daemon at 0.166.0 or newer needs kit 0.7.5 or newer. A takeover that an older kit left pending completes when the same command runs again with the current kit.
Account launchers describe what the reserve guard does, its messages, the launch forms and refusals, the trust step and the check after a run. These are the Codex details.
A launch with a reserve on passes these values after the launcher's own -c
values (and --no-daemon, for every command but exec), before the caller's
arguments:
-c 'hooks.UserPromptSubmit=[{hooks=[{type="command",command="\"$CODING_AGENT_KIT_GUARD_PYTHON\" -I -B -S \"$CODING_AGENT_KIT_GUARD_SCRIPT\" prompt",timeout=20}]}]'
-c 'hooks.PreToolUse=[{hooks=[{type="command",command="\"$CODING_AGENT_KIT_GUARD_PYTHON\" -I -B -S \"$CODING_AGENT_KIT_GUARD_SCRIPT\" tool",timeout=20}]}]'
-c features.goals=false --disable goals
-
The tool hook has no matcher, so it sees every tool that reaches Codex's
PreToolUse, namespaced tools and calls nested in code mode included. -
The hook's shell takes both paths from the environment that codex-as exports:
CODING_AGENT_KIT_GUARD_PYTHONis the launcher's own interpreter, so anotherpython3on the hook'sPATHcannot make the hook fail, andCODING_AGENT_KIT_GUARD_SCRIPTisguard.py, in a managed install through itscurrentlink, so a session that outlives a kit update still finds a guard. WithCODING_AGENT_KIT_GUARD, which holds the launch (the account, the reserves, the start time, the paths of the account's record, of the launch's state and of the marker below), they are the launcher's channel to its guard, no interface for other programs; every codex-as launch first removes inherited ones. Of a hook event the guard reads two fields,transcript_pathandturn_id. The path of the account's record stays in the launch and the Codex guard does not read it. -
The two hook values are the same on every launch, account, host and kit release, because Codex trusts a hook by a hash of its definition. "Trust all" in "Hooks need review" writes these records into the shared
<codex_home>/config.toml, through the account home's link, which stays a link; codex-cli 0.161.0 through 0.169.0 compute the same keys and hashes:[hooks.state."/<session-flags>/config.toml:user_prompt_submit:0:0"] trusted_hash = "sha256:c80a71faf46fb72216d9c2f64df47b9d71695077111da55efa23e7add88d05b6" [hooks.state."/<session-flags>/config.toml:pre_tool_use:0:0"] trusted_hash = "sha256:3171e9d47605b7a9d46f6bbd57941f1de4cbec6880ccf75955321f963ed35733"
A hook that another program passes on Codex's command line for the same event, as its first group and first handler, has the same key and another hash, so the two replace each other's trust.
enabledset to anything but true under one of these keys turns that hook off; a guarded launch refuses that in the sharedconfig.tomland in the selected profile's files. -
The marker that lets headless launches run is
codex-hooks-90aeb3ec484a2ca6in the guard directory beside the account metadata, named by the first 16 hex digits of the SHA-256 of the two hook values. The guard creates it at a tool call, and the warning after a run removes it. -
Goals: native Codex applies
--disableafter every-cvalue and--enable, but a--disableafter a subcommand replaces clap's list, so the-cvalue has to hold on its own; a caller's--enable goalsand a-cvalue that could turn goals on are refused. In codex-cli 0.161.0 through 0.169.0goalsis a stable feature and--disable goalsis accepted without a warning. -
The hooks feature is checked off in every configuration file that Codex may load for the launch:
<codex_home>/config.toml, the selected profile's<codex_home>/NAME.config.toml(and the account home's own file of that name where it is not a link to it),/etc/codex/config.toml,/etc/codex/managed_config.toml,/etc/codex/requirements.toml, and the.codex/config.tomlof the launch directory and of every directory above it, as given and resolved, whatever Codex's trust of that project. A goal setting other than false counts in the managed files only (/etc/codex/managed_config.toml,/etc/codex/requirements.toml), which Codex applies over the command line. Cloud requirements, which only Codex fetches, and a requirement that allows managed hooks only are not read: under either Codex runs none of the guard's hooks, which the check after the run reports. -
The guard reads at most the last 1 MiB of the rollout that the event's
transcript_pathnames, and of it the lines of the launch's turns in that rollout: the event's own turn and the turns whoseturn_idan earlier hook event of this launch carried with this rollout's path, which the launch'sturnsfile in the guard directory keeps. The guard adds a turn there at the turn's first event in a rollout while the file holds less than 1 MiB; a turn that it could not add (a full disk) counts at that turn's own events only, and at a later turn's event or after the run it is none of the launch's turns. Once the file holds 1 MiB, an event whose turn is not in it is read by time (below). A line belongs to the turn that the lasttask_started,turn_contextortoken_usage_recordline up to it names, until atask_completeorturn_abortedline ends that turn; only an id in UUID form names a turn, and anitem_completedline, which can follow its turn's end, names none. Lines a sub-agent inherited from its parent never count, and the turn lines that Codex copies into a sub-agent's rollout name the parent's turns, which are the launch's in the parent's rollout only. A snapshot is the newesttoken_countline of those turns with at least one usable window (a finite percentage of 0 or more, above 100 counting as 100) that a model response of its turn precedes; it carries the time, to the second, of the turn's lasttoken_usage_recordline before it (its own time when the turn has none), and its limit family is its ownlimit_id,codexbeing the general one. A snapshot of the general family takes from the account's attested usage the windows it does not name, and is recorded there; one of another family stands alone, as the limit the session's requests count against, and is never recorded. A line longer than the part read, such as a tool output of more than 1 MiB, can leave a turn's newest token count before the first line of the tail that names a turn. When the tail starts within the file, its first naming line names one of the launch's turns and is notask_started, and notask_started,task_completeorturn_abortedline stands before that line, the newest token count before it with a usable window and a readable time is read as that turn's: while the launch's turns hold no snapshot, the guard decides on that reading as on a snapshot, but it is never recorded, neither in the attested usage nor after the run. While the launch's turns hold no snapshot that names a window of a known length, nor such a reading, a token count without a usable window in them makes the session blind unless it is a compaction's (at a prompt, a model response in them does too); a model response is a reasoning item, an assistant message, a_callitem or atoken_usage_recordline. A format change fails closed: a snapshot that names no window of a known length counts as none, and a token count whose time cannot be read counts as one without rate limits, as does, where the guard reads by time, a model response whose time cannot be read. The guard reads by time instead, the lines stamped from 5 seconds before the launch started, each snapshot with its own line's time and no model response needed before it, and records nothing, when the launch has noturnsfile or one it cannot read (coding-agent-kit 0.9.0 or 0.9.1 started the launch), when the event carries no turn id in UUID form or a path that is no rollout belowsessions/, when theturnsfile holds 1 MiB and the event's turn is not in it, when the tail names no turn at all, and at a tool call whose turn is not among the turns the tail names. A prompt whose turn the tail does not name, while it names others, is judged by the launch's earlier turns there and the attested usage. When the rollout cannot be read, the guard uses the account's attested usage, and the session is never blind. -
The account's attested usage is
codex-usage-NAME.jsonin the guard directory, a 0600 file replaced atomically:owner,usagein the shape of the account record's, and therolloutandlaunchthe reading came from. The guard writes it at an event whose view holds a general-family snapshot of the launch's own turns, and codex-as after a run from the turns its hooks named, when the login after the run is the one the launch started with. The newest reading byseen_atwins; a window that the newest snapshot does not name stays while its reset lies ahead; unchanged windows (reset times up to 120 seconds apart count as unchanged) are written again only 300 seconds apart; a reading stamped more than 5 seconds ahead of this host's clock is never stored, and one stored that way gives way to the next reading.owneris the first 16 hex digits of the SHA-256 of the login's ChatGPT user and workspace: a launch reads the file only when it names the launch's login, or whatever it names when the launch has no readableturnsfile, and a write replaces another login's reading. The file has no lock, so two hooks that write it at the same instant can let the older reading stand until the next event. Nothing else writes it, a launch without a reserve never opens it, and removing it is always safe, though a session of the account that still holds the old reading in its own turns writes that reading back at its next prompt or tool call, so such sessions are closed, or relaunched with that window's reserve off, first (account launchers). -
After Codex exits, codex-as reads the last 1 MiB of each rollout that the launch's
turnsfile names, at most 64 of them, the newest file time first, and in each the turns noted for it, as the guard reads them. When that part of one of these rollouts names a turn, noted or not, the record that--infoshows takes from each rollout the newest snapshot of its noted turns, when that snapshot is of the general family, and of these the newest, whoever created the thread, and nothing else: in that part a turn of another client in the same thread never counts. When the noted turns give no such snapshot there, the record keeps its stored usage. When no such part names a turn (hook events without a turn id in UUID form, rollouts without turn ids in that form, rollouts that are gone) and the guard ran at a prompt or a tool call of the launch, codex-as reads the run by creator and time, as it reads a launch without a reserve (account launchers), and writes no attested usage; when the guard ran at neither, the record keeps its stored usage. -
After a headless run (
exec,review), codex-as prints the guard's latest refusal of that run on stderr, sincecodex execexits 0 after a refused prompt or tool call and, for a refused prompt, shows no reason (for a refused tool call Codex logs the reason on stderr, and the model reports it).
After Codex exits, codex-as reads the rollouts under <codex_home>/sessions
whose file time is at most 300 seconds before the run began (on a network home
directory the file times come from the server's clock): at most 1024
session_meta lines, those of the sessions it resumed by id first, then the
oldest start first. It keeps the sessions of this account's ChatGPT user and
workspace, as Codex records each session's creator, and groups each sub-agent with its parent; guardian reviews run no
user hook and never count. The evidence is in the rollout lines stamped during
the run: a model request is a line of a model response or a usable rate-limit
snapshot, and a tool call one that the tool hook sees (a code-mode exec
counts as one, although only the calls nested in it reach the hook).
- The run's own, which give the warning and remove the marker: the sessions
it resumed by id (a fork's source is not one); for a headless run, the exec sessions started in
its directory during the run and, for
exec resumewithout an id, the older sessions in which it began a turn in its directory, where several (other headless runs of the account) count only for what all of them show; and for an interactive run that is alone, the sessions it started in its directory or in a worktree that Codex manages under<codex_home>/worktrees, afork's new session, the sessions its/cdforks moved to, and every older session of the account written during it. - Perhaps another client's, which give the notice and keep the marker: a new
interactive session of the account in another directory that does not come
from the run's own, also for a run that is alone; any session an
interactive run wrote when it was not alone; during
exec resume --lastwhose own session is not found, an older session written without a turn; and the sessions started in the directory of a headless run when only some of them show it.
An interactive run is alone when no other codex-as launch of the account held
the lease at its start or at its end and none arrived during it. Every launch
that can write sessions, with reserves or without, appends one byte to the
lease file <codex_home>/accounts/.locks/NAME.lock, so a launch that starts
and ends during the run shows too; a launch that holds the lease alone empties
the file once it reaches 4096 bytes. A client that takes no codex-as lease
(plain codex in the root home or started with the account's CODEX_HOME,
the desktop app or an IDE extension, logged in as the same ChatGPT user and
workspace) is not seen this way: an older session of the account that it
continues during an interactive run that is otherwise alone, or a TUI session
it starts in the run's directory, counts as the run's own, so its tool calls
there give that run the warning when the run made none. --worktree is refused with a
reserve on because Codex creates that worktree under its home, whose project
configuration the launch checks do not read and where the check after a
headless run does not look for its session; the TUI's own /worktree is
followed.
codex-as NAME ARGS... aims to behave like logging in natively as NAME and
running codex ARGS.... What still differs:
- The refusals above, and the update prompt turned off in account launches.
- With a usage reserve on, the guard's hooks, goals turned off, and the refusals of usage reserves.
- Account launches never use a daemon, so
queueandagents, which need one, are refused. Commands that act on a session the root daemon holds, such asarchive,deleteorunarchive, act through a separate backend, so for a held session they meet its writer lock instead of reaching the running session. Only interactive resume takes sessions over. - Taking a session over closes it in the root daemon and in Desktop, and moves it to the top of session lists.
- Session names are refused for resume, fork and exec resume; use a UUID,
--lastor the picker. Native name lookup filters by the account's path. - Tools that Codex runs see
CODEX_HOMEandCODEX_SQLITE_HOMEof the account view, which codex-as must set, so a nested plaincodexuses that account. - While native Codex runs, a SIGINT sent to the launcher alone is ignored: a terminal's Ctrl-C reaches native Codex directly, and forwarding would deliver it twice. Send it to the process group instead. Before native Codex starts, Ctrl-C cancels the launch. SIGTERM and SIGHUP are forwarded; one that arrives after native Codex exited takes effect once the exit repair is done. When native Codex dies of SIGINT, SIGTERM, SIGHUP, SIGKILL or SIGPIPE, the launcher dies of the same signal; other signals exit with 128 plus the signal number.
- Codex's own hint at exit,
To continue this session, run: codex resume ID, names plaincodex; continue the session withcodex-as NAME resume ID. - A logout inside Codex (
/logout) is native and revokes the account's tokens in<secrets_dir>/codex-NAME.json; the launcher cannot stop it, and warns at exit with the steps to log in again. A write through the link that names another ChatGPT user is kept and reported.
The source audit below starts from codex-cli 0.162.1, official tag rust-v0.162.1 and commit 092d3acd6bec3e3a14bdc7e7a2810ab628ab759d; the bullets name the later releases that change it. In rust-v0.163.0, login/src/auth/manager.rs and login/src/auth/storage.rs are unchanged; the native refresh test checks the behavior for every release it runs against.
- storage.rs opens auth.json with OpenOptions write/truncate/create, then writes and flushes. This path uses neither rename/atomic replacement nor O_NOFOLLOW, so it follows symlinks to update the target.
- AuthManager saves refreshes through this storage.save. Imports and backups preserve all original bytes; Codex manages the actual refresh format. The wrapper does not implement OAuth refresh.
- From 0.167.0 (#58251) the save is atomic instead. It resolves the link chain to the target, writes a private (0600)
.auth-*temporary file in the target's directory and renames it over the target. The link is kept and the secret's inode changes. It stays an owned 0600 regular file with one link, which is all the launcher checks. A file that is read-only or hard-linked is refused rather than split. Since 0.166.0 a commit holdsauth.lockin the account home. Since 0.167.0 it also holdscodex-NAME.json.lock, a lock file that stays beside the secret, and it saves a refresh only while the stored credentials are unchanged. Neither lock name matchescodex-NAME.json, so neither is listed as an account. - Each account's link stays fixed in its own home, and the root
auth.jsonis never read or changed. Account repair leases do not serialize native cross-process OAuth refresh. Before 0.167.0 the native refresh semaphore is in-process only and file saves use truncate/write; newer releases serialize their own commits through the locks above. Native multiple-client behavior and its limitations remain. - Native
thread-writer-lockstake cross-process exclusive locks by UUID. This directory and.tmp/rollout-maintenance.lockare shared. Compaction scheduling markers using create-new/unlink remain separate for each account; the shared lock still serializes maintenance. - New threads are paginated by default, with actual history in
thread_history_1.sqlite; the complete SQLite home must therefore be shared. Sharing only sessions JSONL is insufficient. The wrapper fixes the explicit database directory override while preserving an existing absolutesqlite_home. - Native configuration editing resolves the symlink writeback path, so config/value/write preserves the shared config link. Relative paths read from configuration instead resolve against the account home, so the wrapper rejects relative path fields in shared user configuration.
- Session-name lookup uses lexical prefix filtering by account path; cross-account resume is limited to UUIDs,
--last, and the picker. Native remote plugin sync removes bundles not installed by the current account, so remote caches are isolated. - The CLI supports a one-time
-c 'cli_auth_credentials_store="file"'override. Every command but exec adds--no-daemonto avoid reusing stale authentication in a persistent app-server; exec remains a separate invocation. - Native login clears existing authentication and may revoke it. Login therefore runs only in a temporary home without old credentials, never through logout/login in the shared home.
- Native subcommands can still appear after the root command's prompt; the wrapper also rejects login and logout in those positions. Prompts, option values and words after a known subcommand are preserved.
- Complete credentials are checked against the native JSON format before switching: NaN/Infinity, invalid non-null tokens, and any supplied but invalid last_refresh are rejected.
Static verification is combined with real offline app-server tests of each tested release. Fictitious fixtures verify legacy/paginated history resume across homes, SQLite list order, concurrent different UUIDs within/across accounts, rejection/release of writes to the same UUID, and shared config editing. There are no login or turn/start requests, and no HTTP requests besides the local token endpoint of the refresh test. thread/list checks discovery and ordering without directly operating the terminal picker/--last. A native refresh test sends getAuthStatus with refreshToken to a local token endpoint (CODEX_REFRESH_TOKEN_URL_OVERRIDE) and checks four things: the rotated tokens land in the linked secret (in place before 0.167.0, by atomic replacement since), the account link is intact, the secret is still an owned 0600 file with one link, and no credential copy is left beside either one, apart from the native lock files. Fake Codex atomic replacement tests prove only wrapper logic; real-account authorization, quotas and server-side token lifetimes remain unverified.
Takeover also relies on these native protocol semantics: thread/unsubscribe only removes
the requesting client's subscription; thread/archive ends the selected runtime
and spawned subtree; thread/unarchive restores one saved thread before 0.166.0.
Since 0.166.0 (#57635) it also
restores the thread's archived spawned descendants, even one archived on its own.
Restore therefore works the same under either behavior. After unarchiving the
session, it re-reads the subtree before each request and archives or unarchives each
spawned agent whose state differs from the journal. It repeats until the subtree
matches; the spawn depth bounds the passes. It never archives an agent that the
root daemon has loaded, together with any of its agents. A stale record must not
end running work, so that agent stays visible and the launcher warns. Native delete
removes a thread together with its spawned subtree. A saved agent that has left the
session's subtree and passes the deletion test below has nothing to restore, so
recovery skips it. One merely missing from the listing keeps the record. A rollout
removed by hand, or by a native delete interrupted after removing it, leaves the
thread's metadata behind: the subtree listing still names the thread, and archive and
unarchive, which move the rollout, refuse it. When one of them refuses an agent that
passes the deletion test, recovery leaves that agent as it is and warns. A record
whose session passes the test is removed with a warning, after the spawned agents
still listed under it (a rollout removed by hand leaves them) get their saved
visibility back. The test needs no rollout of the thread left under sessions/ or
archived_sessions/, linked folders below them included, and a daemon that
either refuses to read it (native delete removes the rollouts before it succeeds) or
reads it from metadata whose rollout path no longer exists. Native refusals all
share one error code, so a refusal alone keeps the record, and so does a path or
folder that cannot be checked, which the recovery message then names. The
search covers sessions/ both before and after archived_sessions/, so a rollout
that a concurrent unarchive moves is still found.
A fresh helper
cannot force unsubscribe another client. The takeover's Unix WebSocket management
client uses the native management identity and does not modify daemon login.
thread/read reports each loaded thread's status (idle, active, notLoaded,
systemError); anything but idle or systemError counts as possibly running.
Offline native fixtures exercise idle handoff without a prompt, the scoped picker
release, the root daemon naming the session an account backend's --last opens,
both history formats, visible children, archived grandchildren, a loaded spawned
agent and an unrelated loaded writer. Wrapper tests cover running and
status-less sessions, refusal, consent, partial errors, unknown completion, private
recovery metadata and retries. To check a root daemon binary that differs from the client, for
example one still running from before an update:
CODEX_NATIVE_DAEMON_BINARY=/path/to/codex-0.162.1 \
python3 -I -B tests/test_codex_sharing_native.py \
NativeSharingTests.test_daemon_takeover_preserves_uuid_history_and_other_threadsManual repair requires closing that account's clients; native CLI/desktop/IDE clients do not participate in wrapper leases. codex-as never reads or changes the root auth.json.