GUIDE · HARDENING 10 min ·

Codex CLI's background daemon and the env it inheritsOne shell's variables, every later session

Codex CLI 0.157.0 made a persistent, self-updating app-server daemon the default for interactive sessions, and the daemon keeps the environment of whichever terminal started it. A token you exported for one repository stays readable to every later Codex session on the machine until you stop the daemon or reboot. Disable the feature, kill the updater, and if you run a team, pin the flag off in requirements.toml.

TL;DR· the answer, in twenty seconds

What happened: Codex CLI 0.157.0 (September 25, 2026) turned on daemon_auto_start by default. An interactive session now starts a detached app-server and an hourly self-updater that outlive the terminal, and OpenAI's own README says every client shares the environment the daemon started with. It was still on by default in 0.167.0 and on main as of November 10.

The minimum fix: Run codex features disable daemon_auto_start, stop the daemon, kill the pid-update-loop process, and delete ~/.codex/packages/app-server-daemon. Teams can pin the flag off in /etc/codex/requirements.toml.

The lesson: An agent's process lifetime is part of its credential boundary. A secret exported for one task now lives as long as the longest-running process that inherited it.

Codex CLI 0.157.0, released September 25, 2026, starts a persistent background server the first time you open an interactive session, and that server keeps the environment of the terminal that launched it for as long as it runs.

The release note gives the change one line: "Enabled automatic background-server startup for eligible interactive sessions." The pull request behind it, #47179, promoted the daemon_auto_start feature to stable and set it on by default. The same day, GitHub user Yihua-Liu-1997 opened openai/codex#48195 asking for it to be opt-in. On October 12 that issue reached the Hacker News front page as "Codex CLI installs a persistent, self-updating background daemon by default", with 610 points and 294 comments. A day later, openai/codex#53547 showed a variable exported in one terminal turning up in a Codex session started from another.

As of today the default has not moved. The feature table on Codex's main branch still lists daemon_auto_start as stable with default_enabled: true, and codex features list on a current 0.167.0 install reports it on. This guide covers what the daemon does, why its environment handling is a credential problem, how to see what is running on your machine, and how to turn it off or keep it with less exposure.

What starts when you type codex

Before 0.157.0, the interactive CLI ran an embedded backend by default. Close the terminal and the backend died with it. Since 0.157.0, an eligible interactive launch does four things, as described in #48195 and confirmed against the daemon's README:

  1. It starts codex app-server as a detached process in its own session, with no TTY. The process keeps running after every Codex window closes. On Linux, PID 1 adopts it. It stops when you run codex app-server daemon stop or reboot.
  2. It copies the whole platform package into ~/.codex/packages/app-server-daemon/releases/<version>/ and runs the daemon from that copy. The reporter measured about 374 MB for the Linux package, byte-identical to what npm had installed. From that point the backend's version no longer tracks the version your package manager thinks you have.
  3. It starts a second detached process, codex app-server daemon pid-update-loop, which checks for a new release five minutes after start and then hourly, downloads it, and restarts the backend.
  4. It pins the environment of the session that started it. Every later client that attaches to the shared socket gets the daemon's environment, whatever the new terminal had set.

The README is explicit about the last point: "Shared clients use the environment inherited when the daemon started. Opening a new terminal or clearing variables there does not clear the running daemon's environment; per-client environment isolation is not provided."

Eligibility has exceptions. Startup code on main skips the daemon when you pass --no-daemon, when you connect to an explicit --remote endpoint, and when CODEX_HOME sits on a Windows-mounted WSL drive, an exclusion added in 0.162.0. Windows also refuses to start it from an elevated terminal. A normal macOS or Linux terminal session is eligible.

The updater has caused its own trouble. openai/codex#40969, filed August 26 after a 0.149.0 to 0.150.0 update, documented the updater giving the backend 60 seconds to drain before sending SIGKILL, which killed in-flight agent turns running long test suites on every update. The README now documents a shutdownGraceSeconds setting, from 0 to 300 with a default of 60, and an autoUpdateEnabled switch. Both live in a daemon-managed settings.json, separate from config.toml. Version 0.161.0 added one more default: daemon-launched app servers start with --analytics-default-enabled, per pull request #49426, unless you set analytics.enabled = false in config.toml.

None of this appeared in the public configuration reference. On October 12, a commenter on #48195 noted that the reference listed check_for_update_on_startup but had no row for daemon_auto_start. I fetched the current config reference on November 10 and it still has none. The opt-out exists. You have to find it in an issue thread or the source.

Why the inherited environment is a credential problem

Most developers who use environment variables for secrets rely on one property: the variable lives in the shell that exported it and in that shell's children. Close the terminal, or unset the variable, and it is gone. Per-project tools such as direnv depend on the same property. They load a project's variables when you enter the directory and unload them when you leave.

The daemon breaks that property. Here is the sequence from #53547, filed October 13 by GitHub user alexklibisz on codex-cli 0.162.1 under macOS:

  • Stop the daemon. In terminal one, make a new directory, export CODEX_ISSUE=FOO123, and start Codex. Ask the agent which variables it can see. It lists CODEX_ISSUE.
  • In terminal two, make a different directory. Do not export anything. printenv | grep CODEX_ISSUE returns nothing. Start Codex and ask the same question. The agent still reports CODEX_ISSUE=FOO123.

Swap CODEX_ISSUE for AWS_SECRET_ACCESS_KEY, STRIPE_SECRET_KEY, or a DATABASE_URL with a production password embedded in it. Terminal one was the payments service, where you loaded a scoped key to debug a webhook. Terminal two is a third-party repository you cloned to evaluate, the kind of repository whose README or AGENTS.md might carry a prompt injection. The agent in terminal two runs commands through a server that holds terminal one's key. Every command it spawns starts from that environment.

The reporter called it "somewhere between a bug and a security issue." I would put it closer to the second. On November 3, a second user commented that the leak broke automation keyed on a per-pane variable, HERDR_PANE_ID, which shows that the pinning reaches more than secrets. The original #48195 report found the same effect with proxies: the reporter set HTTPS_PROXY per invocation through a wrapper, and the daemon kept routing every later session's traffic through the first session's proxy.

Codex has a filter for what reaches spawned commands, shell_environment_policy, and its defaults will not save you. The advanced configuration docs state that ignore_default_excludes defaults to true, which means Codex does not strip variables whose names contain KEY, SECRET, or TOKEN unless you set it to false. Even with it set, the filter matches names. DATABASE_URL, REDIS_URL, and GITHUB_PAT all pass a name filter for those three words while carrying a live credential in the value.

Lifetime is the other half of the problem. A shell you close takes its exported key with it. A daemon started on Monday morning from a terminal that held a production key still holds it on Friday. On the machine I checked for this guide, a Homebrew-managed npm install of codex-cli 0.167.0 on macOS, the app-server had been running for five days and carried 58 inherited variables from whichever shell started it. None had a credential-shaped name on that machine. That outcome depended on what someone had exported in that shell on November 5. Nobody chose it as a control.

Check what is running on your machine

Run these before you change anything. They print variable names, never values. Paste the output into a ticket without leaking the secrets themselves.

# 1. Is the daemon on, and is it running?
codex features list | grep daemon_auto_start
pgrep -fl 'codex app-server'

# 2. Which variables did the running app-server inherit? Names only.
pid=$(pgrep -f 'codex app-server --listen' | head -1)
# macOS (works for processes you own)
ps eww -o command= -p "$pid" | tr ' ' '\n' \
  | grep -E '^[A-Za-z_][A-Za-z0-9_]*=' | cut -d= -f1 | sort -u
# Linux
tr '\0' '\n' < "/proc/$pid/environ" | cut -d= -f1 | sort -u

# 3. Flag credential-shaped names, including URLs that may embed passwords
#    (append to either command above)
#   | grep -i -E 'key|secret|token|pass|cred|auth|_url$|dsn'

# 4. When did it start, and how much disk do the managed copies use?
ps -o lstart= -p "$pid"
du -sh ~/.codex/packages/app-server-daemon/releases/*
ls ~/.codex/app-server-daemon/

On the macOS machine above, step 1 printed daemon_auto_start stable true and three processes: the app-server, the pid-update-loop updater, and codex-code-mode-host, all running from ~/.codex/packages/app-server-daemon/releases/0.167.0-aarch64-apple-darwin/. The app-server's command line included --analytics-default-enabled. Step 4 showed two release directories, 0.166.0 at 407 MB and 0.167.0 at 408 MB, or 815 MB on top of the npm install. The release pruning added in 0.164.0 had left the previous version in place. Your numbers will differ by platform.

If step 2 or 3 shows a name you recognize as a secret, assume every Codex session since the daemon's start time could read it. That includes sessions in repositories you did not write. Rotate on that basis. Do not reason backward from which sessions you think asked for it.

codex doctor reports the same state from the CLI's side. The doctor output pasted into #53547 lists the control socket at ~/.codex/app-server-control/app-server-control.sock, the daemon state directory, and the pid files for the server and the updater.

Turn it off and keep it off

On a single machine, this sequence comes from the workaround posted in #48195. I checked each codex subcommand against the 0.167.0 help output:

# Persist the opt-out in ~/.codex/config.toml ([features] daemon_auto_start = false)
codex features disable daemon_auto_start

# Stop the running server
codex app-server daemon stop

# The 0.157.0 report found the updater survived "daemon stop". Check, then kill it.
pgrep -fl 'app-server daemon pid-update-loop' \
  && pkill -f 'app-server daemon pid-update-loop'

# Remove the managed package copies the daemon ran from
rm -rf ~/.codex/packages/app-server-daemon

# Confirm: nothing should print
pgrep -fl 'codex app-server'

codex features disable writes the setting to config.toml, so it survives upgrades. The reporter confirmed that with the flag off, a new interactive session no longer spawns a daemon. For a single run without changing config, codex --no-daemon skips the shared server even when one is already running. Since 0.167.0, codex agents --no-daemon opens the agent command center the same way.

A per-user setting is the wrong control for a team. Anyone can flip it back on, and a fresh install starts with it on. Codex's managed configuration supports admin-enforced requirements that users cannot override. The local file sits at /etc/codex/requirements.toml on macOS and Linux, and macOS MDM can deliver the same TOML through com.openai.codex:requirements_toml_base64. The docs say a [features] table in requirements accepts the canonical feature keys from config.toml. The local runtime normalizes recognized features to match those pins and rejects conflicting writes.

# /etc/codex/requirements.toml
[features]
daemon_auto_start = false

OpenAI's examples for feature pins name hooks, unified_exec, browser_use and others. They do not name daemon_auto_start. The requirements parser on main reads [features] as a map of arbitrary keys to booleans, so the pin should apply. Roll it out to one machine first. Then run codex features list and open a plain interactive session to confirm no app-server appears before you push it fleet-wide.

Tighten the environment filter on every machine, daemon or not. A process started by codex --no-daemon still inherits your whole shell:

# ~/.codex/config.toml
[features]
daemon_auto_start = false

[analytics]
enabled = false

[shell_environment_policy]
inherit = "core"
ignore_default_excludes = false

[shell_environment_policy.filters]
"AWS_*" = "exclude"
"*_URL" = "exclude"
"*PASSWORD*" = "exclude"

inherit = "core" starts spawned commands from a minimal baseline instead of everything you exported. ignore_default_excludes = false turns on the KEY, SECRET, and TOKEN stripping that is off by default. The filters catch names the defaults miss. Patterns are case-insensitive and accept * and ?. Expect to add include entries for whatever your build needs. That friction is how you learn which variables the agent's commands use.

If you keep the daemon

The daemon exists for remote control and the desktop and mobile clients, which need a server that outlives a terminal. If you use those, a long-lived server is the point. Reduce what it holds and how much it changes under you.

Start it from a clean environment. The daemon keeps whatever environment it started with, so give it a deliberate one instead of whatever shell you happened to type codex in first:

codex app-server daemon stop
env -i HOME="$HOME" PATH="$PATH" TERM="${TERM:-xterm-256color}" \
  codex app-server daemon start

Then rerun the name check from the previous section. I have not tested this on every platform, and the README does not document env -i launches. The check tells you whether it worked.

Disable automatic updates and widen the drain window in ~/.codex/app-server-daemon/settings.json, using the shape from the README:

{
  "remoteControlEnabled": false,
  "shutdownGraceSeconds": 300,
  "updater": { "autoUpdateEnabled": false, "updateIntervalMinutes": 120 }
}

codex app-server daemon restart applies the change. With the updater off, codex app-server daemon update still pulls the latest stable release when you ask for it, so upgrades become an action you choose. The README notes that the updater uses saved network settings and ignores -c overrides. If you route Codex through a proxy, set it in config, not on the command line.

Restart the daemon whenever your environment changes in a way that matters: after you rotate a credential, after you leave a project whose variables you loaded, and before you log off. Since 0.163.0, /daemon inside the TUI can restart a managed server and warns about work the restart would interrupt.

Do not run the daemon on a shared dev box where more than one person's work goes through the same CODEX_HOME. The environment pinning that crosses repositories on a laptop crosses people on a shared host.

What this means for your stack

Today: run the name check. If the daemon holds a credential-shaped variable, rotate that credential, then disable daemon_auto_start, stop the server, kill the updater, and delete the package copies. If you manage more than a handful of machines, put the pin in requirements.toml and verify it on one host before rolling out. Set ignore_default_excludes = false everywhere, because its default passes secret-named variables to every command the agent runs.

The underlying mistake is treating the shell environment as a scope. It has never been a security boundary, and the daemon shows how little it takes to break the assumption. One vendor changed one default, and a variable's lifetime went from one terminal to the life of a background process. The pattern that holds up keeps standing credentials out of the environment of anything long-lived. A broker hands each command the secret it needs, at the moment it runs, and the value dies with that process.

hasp is one working implementation of that runtime brokering. Install with curl -fsSL https://gethasp.com/install.sh | sh, run hasp setup, and the broker injects secrets into the agent's commands at run time instead of leaving them exported in the shell that starts the daemon. Source-available (FCL-1.0), local-first, macOS and Linux, no account.

Whatever you use, put Codex's process lifetime on your list of things to check after each upgrade. A minor version changed it once without a line in the configuration docs. Keep codex features list and the pgrep check in your post-upgrade routine.

Sources· cited above, in one place

NEXT STEP~90 seconds

Stop handing the agent your real keys.

hasp keeps secrets in one local encrypted vault, brokers them into the child process at exec, and never lets the agent read the value.

  • Local, encrypted vault — no account, no cloud, no telemetry by default.
  • Brokered run — agent gets a reference, the child process gets the value.
  • Pre-commit + pre-push hooks catch managed values before they ship.
  • Append-only HMAC audit log answers "did the agent touch the prod token?" in seconds.
→ okvault unlocked · binding ./api
→ okgrant once · pid 88421
→ okagent never read

macOS & Linux. Source-available (FCL-1.0, converts to Apache 2.0). No account.

Browse all clusters· eight threads, one index