Codex CLI 0.146.1: PyCharm terminal + macOS Documents + subagents can lose permissions and fail with invalid cwd (EPERM)
What version of Codex CLI is running?
codex-cli 0.146.1 (npm installation)
What subscription do you have?
ChatGPT-authenticated CLI. Exact plan omitted because this appears to be a local CLI/sandbox regression.
Which model were you using?
gpt-5.6-sol
What platform is your computer?
macOS 15.7.4 (24G517), arm64
What terminal emulator and version are you using?
PyCharm 2026.1.4 integrated terminal, zsh.
Codex doctor report
Not attached because the full report contains local paths and environment metadata. The relevant sanitized results are:
- Codex version:
0.146.1 - Installation: OK
- Config load: OK after the workaround below
- State database integrity: OK
- Sandbox helper check: OK
- MCP configuration consistency: OK
What issue are you seeing?
On macOS, Codex CLI sessions launched from a PyCharm integrated terminal for a project under ~/Documents can repeatedly lose their effective permissions after subagent activity. In the latest occurrence, this happened around a task that changed Codex hook configuration. Starting a new thread/turn then failed because Codex treated the valid current working directory as invalid:
failed to refresh config before thread transition; continuing with current in-memory config
error=Failed to rebuild config for cwd /Users/REDACTED/Documents/PROJECT
action="starting a new thread"
turn/start failed in TUI
turn/start failed: invalid cwd: Operation not permitted (os error 1) (code -32600)
The directory still existed, was canonical, had normal Unix read/traverse permissions, and could be entered from another shell. PyCharm also had macOS Documents Folder access. This does not look like a missing executable or ordinary filesystem-mode problem: codex --version worked, and Codex could launch from the same directory after disabling hooks and restarting.
This pattern has occurred multiple times specifically with the combination of:
- PyCharm integrated terminal
- a project below
~/Documents - Codex subagents
The user-visible effect is broader than one denied command: the running workflow appears to lose permissions, and a subsequent thread/turn can fail at cwd validation.
What steps can reproduce the bug?
The failure is recurring but appears timing/state dependent. The repeatedly observed sequence is:
- Open a local project below
~/Documentsin PyCharm on macOS. - Start Codex CLI from PyCharm's integrated
zshterminal. - Use
gpt-5.6-soland ask Codex to delegate work to subagents. - During the session, run a task that changes Codex hook configuration.
- Start a new thread or submit the next turn.
- Observe that effective permissions have become restricted/unavailable and the TUI fails with
invalid cwd: Operation not permitted (os error 1).
Local logs show one concrete sequence:
T+00s failed to refresh config before thread transition for /Users/REDACTED/Documents/PROJECT
T+59s turn/start failed: invalid cwd: Operation not permitted (os error 1)
No earlier codex_tui::app::event_dispatch invalid cwd entry was present in the local log database before upgrading to 0.146.1.
What is the expected behavior?
- Subagents should inherit the parent session's effective sandbox/permission policy.
- Hook configuration changes should not invalidate or downgrade the current working directory.
- A valid, accessible project below
~/Documentsshould remain usable from PyCharm's terminal across subagent and new-thread transitions. - If Codex intentionally changes the effective permission profile, the new state should be explicit and should not make
thread/startfail cwd validation.
Additional information
The CLI was upgraded to 0.146.1 on the day of the latest occurrence. The 0.146.1 release contains a single permission-related backport, #37057, which changes active TUI thread permission defaults and code in event_dispatch.rs, thread_settings.rs, and app_server_session.rs. The failure is also reported from the TUI thread-start path. This correlation may be relevant, but it is not presented as a proven root cause.
Related permission-state reports include #25810 and #32763, but neither covers this exact macOS CLI + PyCharm + ~/Documents + subagent/hook path or the invalid cwd failure.
Current local workaround:
[features]
hooks = false
After restarting Codex with hooks disabled, the same cwd could be opened successfully. This is a workaround observation, not proof that hooks alone are the root cause.
For privacy, raw logs, thread/process IDs, absolute user paths, project names, MCP server names, hook command paths, and the full doctor report are intentionally omitted. I can provide additional narrowly scoped, sanitized diagnostics if maintainers identify a specific field they need.
3 Comments
Update (2026-08-12): reproduced outside PyCharm; TCC attribution-chain failure coincides with the first EPERM
I reproduced the same broader failure today from a normal iTerm2 shell, so PyCharm is not required.
Sanitized environment:
zsh~/Documents/REDACTED/PROJECTsandbox_mode = "danger-full-access", with the project trusted and no filesystem permission profile enabledExact timeline from the sanitized session log:
The relevant macOS unified-log lines, with the ephemeral PID removed, are:
Additional observations:
tccdlog from 15:00-17:00, this was the onlyproc_pidpath_audittoken/ attribution-chain failure. It is therefore not a high-frequency background warning on this machine.auth_value=2(allow) for iTerm2's Documents Folder access. The OpenAI Codex app also had an allow row. There was no directcodexCLI row. This was not a normal stored “Documents access denied” decision; TCC failed before it could construct the responsible-process chain.codex resume REDACTED_SESSION_IDfrom the same cwd at 16:34:17, now using CLI 0.147.0, immediately returnedError: Operation not permitted (os error 1). At that pointhooks = falsewas configured, so disabling hooks did not recover the already-failing cwd state.Current evidence-based hypothesis: this is a macOS TCC/responsible-process attribution race involving a short-lived Codex tool/helper process. The process had exited before
tccdresolved its audit token, so the Documents Folder request failed closed with EPERM. From the CLI side, keeping a stable responsible process/audit identity for protected-folder accesses (or avoiding a short-lived process that can disappear before TCC attribution completes) may be worth investigating.I can provide a more narrowly scoped, sanitized unified-log excerpt if a maintainer needs additional TCC fields.
Root cause confirmed and fix prepared
The short-lived-helper hypothesis in my earlier update was not the root cause.
(#2) No such file or directoryisENOENT, and the evidence points to the still-running Codex executable itself losing its filesystem path after the in-place npm upgrade:proc_pidpath(...) = 0with errno 2lsofshowed those executables mapped from npm's retired.codex-*package directory after that directory had been unlinkedproc_pidpath/ENOENTresultproc_pidpathcontinue to return that path with errno 0 after deleting the simulated installed runtimeThat explains the TCC sequence directly:
tccdcannot resolve the executable path, cannot construct the responsible-process attribution chain, and the Documents request fails closed withEPERM. PyCharm, hooks, subagents, cwd validation, and Codex sandbox policy are not required to trigger it.I prepared a focused fix that launches npm-managed macOS sessions from a per-session hard-linked native runtime under
CODEX_HOME/tmp/native-runtime, preserving the binary and bundled resources across in-place upgrades. It includes PID-based fail-safe lifecycle cleanup, concurrent-session coverage, Node 16 coverage, repo-checks integration, staged npm-package validation with the real darwin-arm64 payload, and an isolated nativeproc_pidpathprobe.Commit: https://github.com/forrestzhu/codex/commit/c0ec2ae5fe8e78dd5927c2f5610fd85cfa742fee
Compare: https://github.com/openai/codex/compare/main...forrestzhu:codex:fix/macos-npm-stable-runtime
I attempted to open the upstream PR through both the GitHub CLI/API and the signed-in browser. GitHub reports that this repository currently limits opening pull requests to collaborators, so my account cannot create it. If a maintainer can grant the required permission, I can submit the prepared PR immediately; alternatively, please feel free to take over/cherry-pick the commit.
Additional confirmation on 0.148.0 and resume-cwd UX
A separate user report still sees the exact TUI failure on the npm-distributed macOS CLI:
Sanitized environment:
codex-cli 0.148.0, npm installation~/DocumentsThe local thread inventory also contained two non-archived sessions whose saved cwd no longer existed: one deleted temporary directory and one repository that had moved to a new path. Archiving those sessions and setting:
mitigates the stale-session path, but it does not address the confirmed in-place npm upgrade/TCC attribution root cause documented above.
Two defensive improvements may help in addition to preserving a stable per-session native runtime:
codex updateshould detect or warn about active Codex processes before replacing the npm-managed runtime.EPERM, show the rejected sanitized path/source, and offer to fall back to the current cwd instead of failing the turn with onlyinvalid cwd.The pre-turn failure was not recorded in
thread_turns.error_jsonor the normal desktop log files, so preserving a sanitized diagnostic event for this path would also make future reports easier to verify.