Sequential codex exec runs eventually fail with token_invalidated when using ChatGPT auth
What version of Codex CLI is running?
codex-cli 0.136.0
What subscription do you have?
ChatGPT Plus (using ChatGPT authentication, not API key)
Which model were you using?
_No response_
What platform is your computer?
macOS 26 (Darwin 25.5.0)
What terminal emulator and version are you using (if applicable)?
Terminal.app
Codex doctor report
What issue are you seeing?
Single codex exec invocations work reliably.
However, when running multiple non-interactive codex exec commands sequentially from a batch process using ChatGPT authentication, the authentication session becomes invalidated after several successful runs.
In my environment, the first three invocations succeed, while the fourth consistently fails with:
- 401 Unauthorized
- token_invalidated
- Failed to refresh token
- app_session_terminated
The CLI then repeatedly attempts to reconnect and remains silent for approximately 7 minutes before exiting.
Additionally, codex login status continues to report Logged in using ChatGPT even after the server has already invalidated the session.
This behavior occurs despite having logged in only a few minutes earlier, so it does not appear to be simple token expiration.
What steps can reproduce the bug?
- Install codex-cli 0.136.0 on macOS.
- Authenticate using ChatGPT (codex login) without configuring an API key.
- Execute a non-interactive codex exec command, for example:
codex exec \
--skip-git-repo-check \
-s read-only \
--output-schema schema.json \
--output-last-message out.json \
--color never \
"<prompt>"
- Repeat the same command sequentially from an automated script (no parallel execution).
- In my environment, the first three invocations succeed, while the fourth invocation consistently fails with:
- 401 Unauthorized
- token_invalidated
- app_session_terminated
- After the failure, codex login status still reports Logged in using ChatGPT, and subsequent codex exec commands remain silent for approximately 7 minutes before exiting.
This does not appear to require concurrent execution; the issue reproduces with sequential invocations from a single process shortly after a fresh login.
What is the expected behavior?
Sequential non-interactive codex exec invocations should be able to reuse a valid ChatGPT authentication session without requiring the user to log in again.
A recently established session should remain valid across multiple sequential executions, and if the session does become invalid, the CLI should fail immediately with a clear authentication error instead of silently retrying for several minutes.
Additionally, codex login status should accurately reflect the server-side authentication state.
Additional information
Sequential non-interactive codex exec invocations should be able to reuse a valid ChatGPT authentication session without requiring the user to log in again.
A recently established session should remain valid across multiple sequential executions, and if the session does become invalid, the CLI should fail immediately with a clear authentication error instead of silently retrying for several minutes.
Additionally, codex login status should accurately reflect the server-side authentication state.