Why do I have to "teach" codex that it can use 'apply_patch'?

Resolved 💬 7 comments Opened Sep 29, 2025 by eddyg Closed Oct 1, 2025

What version of Codex is running?

codex-cli 0.42.0

Which model were you using?

gpt-5-codex

What platform is your computer?

Darwin 24.6.0 arm64 arm

What steps can reproduce the bug?

This is the kind of thing I have to do as of late:

<img width="1690" height="1414" alt="Image" src="https://github.com/user-attachments/assets/781751d8-0fdd-4e9b-93fc-a73758ea7920" />

Just like in the screenshot above, far too often lately, codex tries to do crazy stuff like this:

▌ Please increment the number on the last of test-file by 1.

• Ran zsh -lc "rg --files -g '*test*'"
  └ TESTPLAN.md
    test-file

• Ran zsh -lc 'tail -n 5 test-file'
  └ Increment the number on this line: 2

• Proposed Command
  └ zsh -lc "python - <<'PY'
    from pathlib import Path
    path = Path('test-file')
    text = path.read_text()
    old = 'Increment the number on this line: 2'
    new = 'Increment the number on this line: 3'
    if old not in text:
        raise SystemExit('expected line not found')
    path.write_text(text.replace(old, new, 1))
    PY"

✗ You canceled the request to run zsh -lc "python - <<'PY' ...

Usually I can cajole it (e.g., see highlight in above screenshot) into realizing it has better ways to accomplish things.

What is the expected behavior?

codex-cli should _always_ be aware of its internal tools and use them.

What do you see instead?

Verbose command execution via zsh -lc instead of Proposed Change, _prompt to review and approve_, Change Approved, etc.

Additional information

I always run codex -s read-only so I can review plans, proposed changes, interrupt to provide additional details, etc.

View original on GitHub ↗

7 Comments

ppamment · 9 months ago
eddyg · 9 months ago

#4201 is about the VSCode extension; this seems like a much more endemic issue which is why I thought it deserved its own bug.

ppamment · 9 months ago

Perhaps I should have said related, and it wasn't intended to be dismissive of this issue. The opposite in fact, I was trying to add more voices to the problem as more voices = higher priority,

My thought when I saw this was that 4201 is just people (myself included) encountering this same issue but we happened to be using vscode. It's using bash or python or sed or whatever other tool to make code changes rather than apply_patch, which albeit in a different environment, is fundamentally the same behavior you're seeing here.

Incidentally I asked GPT-5 why it wasn't using apply_patch consistently as a default, and it indicated it believed it could be because earlier in the conversation it had attempted to use apply_patch when it did not have write permission and it failed (it was in chat mode). Even though write permissions had been enabled later on, it still saw those previous failures and avoided apply_patch as a result.
Take that with a grain of salt, I'd need to check more instances where this happened to verify

Alfredo-Sandoval · 9 months ago

I've had several issues open on apply_patch. In the end I patched it on my local build and it works well. Tons of time saved.

@tibo-openai tells me they are aware and working on it.

OilProducts · 9 months ago
eddyg · 9 months ago

Thanks for the link to that issue. The suggested prompt addition definitely seems worth trying in AGENTS.md.

Aqualie · 9 months ago

Still does not work on 0.44.0...

Got it—if we were making edits I’d stick to apply_patch per the workflow. At the moment I’m only inspecting files because this sandbox is read‑only (per the session config), so no writes are happening. As soon as we’re ready to modify things in a writable session, I’ll use apply_patch for the changes.