Can touch files and dirs, and run npm commands but will not write to files - macOS
Resolved 💬 11 comments Opened Apr 18, 2025 by jason-murray Closed Aug 7, 2025
💡 Likely answer: A maintainer (shutootaki, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
v0.1.2504172351
Which model were you using?
gpt-4.1-mini
What platform is your computer?
Darwin 24.3.0 x86_64 i386
What steps can reproduce the bug?
Codex just seems to get stuck and not write anything out like the below example. Sometimes it does not get stuck and all the steps look correct - it will tell me that it has written out the files but all the files are empty.
➜ codex-reforge-test (main) ✔ codex --full-auto
╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2504172351 │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: fafca48d45334cd7b88a817b7cb29d88 │
│ ↳ workdir: ~/projects/codex-reforge-test │
│ ↳ model: gpt-4.1-mini │
│ ↳ approval: full-auto │
╰──────────────────────────────────────────────────────────────╯
user
create a simple express hello world app
codex
*** Begin Patch
*** Update File: hello-world-express.js
@@
+const express = require('express');
+const app = express();
+const port = 3000;
+
+app.get('/', (req, res) => {
* res.send('Hello World!');
+});
*
+app.listen(port, () => {
* console.log(`Example app listening at http://localhost:${port}`);
+});
*** End Patch
╭────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ send a message │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
send q or ctrl+c to exit | send "/clear" to reset | send "/help" for commands | press enter to send
What is the expected behavior?
Codex should be able to write out changes to disk, via apply_patch or echo (neither work).
What do you see instead?
The correct file/folder structure but any files that contain logic that codex would produce are zero bytes with no contents.
Additional information
_No response_
11 Comments
Ok actually
o4-miniwas able to complete the task. But I have found this model sometimes gets stuck listing folder contents and moving around the project rather than actually doing anything.I still don't understand why the other models would produce output that looks sane but not actually write to the project folder.
Trying
o3-miniand I keep getting thisInvalid Add File Line:errorI'm guessing most of the issues are to do with different models not being able to produce patches to the spec:
Also encountering nearly persistent
apply_patchfailures.Could it be a permissions issue?
This is what I see in the Codex CLI output when I ask it to create a test file and write some content:
It tries this command:
In stdout I get:
and no content is actually written to the file.
---
Expected behavior:
so that the file ends up containing "This is test content".
---
macOS 15.4
Codex v0.1.2504172351
Same on Linux/Ubuntu. o4-mini model tries constantly apply changes with "apply_patch" which I don't have.
I encountered the same bug in my environment.
Error Overview
When using relatively inexpensive models such as gpt-4o, file changes are not applied to local files.
Reproduction Steps
.vscode/launch.jsonand start debugging:``
json
``{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Codex CLI Debug",
"program": "${workspaceFolder}/codex-cli/dist/cli-dev.js",
"outFiles": ["${workspaceFolder}/codex-cli/dist/**/*.js"],
"sourceMaps": true,
"args": [
"-m",
"gpt-4o",
"hw.pyにhellow worldを出力するためのスクリプトを作成して"
],
"console": "integratedTerminal",
"env": {
"OPENAI_API_KEY": "sk-xxx"
}
}
]
}
Actual Output
Despite this, no file is actually created.
Spawn Invocation Details
When calling:
the parameter values are:
prog = "echo"adaptedCommand = ["print('Hello World!')" >> hw.py]fullOptions = { timeout: 500, stdio: Array(3), detached: true }And the debug console shows:
Models Tested
gpt-3.5-turbogpt-4ogpt-4.1gpt-4.1-minigpt-4.1-nanoo4-miniSo far, only
o4-minihas successfully applied the file changes (testing limited by API costs).Probable Cause
When running Codex, if
applyPatchCommandisundefined, it falls back to executing thisexec. Ultimately, it uses thespawnmethod in [raw-exec.ts](https://github.com/openai/codex/blob/3a71175236cae47a2950266a0d7888e4f76227c4/codex-cli/src/utils/agent/sandbox/raw-exec.ts#L90) to run the file-modification command, but becauseshell: trueis not enabled inoptions, shell features like redirection, pipes, and backticks aren’t interpreted, so the command silently fails.Proposed Fix
Enabling
shell: truein the spawn options fixes the issue—after this change, the file is created successfully. See [PR #391](https://github.com/openai/codex/pull/391) for the diff. If there’s a more appropriate approach, I’d appreciate your feedback.I was hoping there would be a fix for this. I first asked the bot to go ahead and check files after it writes them to avoid the assumption of it working and moving forward. I next asked the bot to find an alternative solution to writing to files and explain its findings. Here is what gpt-4.1-mini said:
That being said, I'll adjust my
~/.codex/instructions.mdto include this workaround moving forward.Instructions for
~/.codex/instructions.md:Add the following lines to ensure reliable file writes and verification:
IDK why the content -> tempFile -> targetFile works but seems to do the job
@angelxmoreno , you described has the same issue I'm observing right now with the latest revision. In my case (#489 ) it won't create files and won't update them. During a bare bones test ( "Oh, The Great Big Brother, create a file and add a "blah" line") it succeeded after a few tries.
Difference:
$ "echo 'BLAH BLAH' >> old.txt" -> FAILED
$ /bin/sh -c "echo 'BLAH BLAH' >> old.txt" --> WORKED
It is getting better and better ... (facepalm)
previous broken version:
● OpenAI Codex (research preview) v0.1.2504172351
Today, after "npm update.. "
Thank you for the feedback! Please try again with the latest version of Codex CLI. If the issue persists, we'd appreciate it if you could report it for the
codex-rs/implementation. You can find more details about our project update here.