Local Models (gpt-oss:20b etc.) Unable to Make Edits to Files
What version of Codex is running?
codex-cli 0.20.0
Which model were you using?
gpt-oss:20b from ollama
What platform is your computer?
Darwin 24.6.0 arm64 arm
What steps can reproduce the bug?
Running command "codex --oss -m gpt-oss:20b" is how I discovered the issue, but I've had the same issue with every other local model as well. Then simply ask it to complete any task that requires editing a file.
What is the expected behavior?
I expect the model to be able to make edits to the files in the codebase as requested.
What do you see instead?
Instead, from what I've gathered from ChatGPT 5, it’s using a fake tool invocation. For edits, it uses apply_patch which "is not a real CLI command in Codex, so nothing gets applied" according to ChatGPT 5. It says "The model is not outputting a valid POSIX shell command or a standard unified git diff".
Additional information
Using models sourced from OpenAI such as ones from the API or my Plus subscription plan works fine. They're not only able to read all files in the codebase, but they're also able to make edits to the codebase to accomplish action based prompts. I swapped to open source models to cut down on spending with the API and when I did none of the models I tried were able to make any changes to the codebase.
I shared the interactions with ChatGPT 5 and after some troubleshooting we concluded that the open source models were trying to use tools that didn't actually exist. So we made an AGENTS.md file directing the models on the tools it had and how to use them and only have explicitly directing the model to read the AGENTS.md file was it able to make changes to the codebase.
I'm almost certain this is user error since this makes the tool practically useless for development and I cant find anyone else with the same issue even using ChatGPT's research mode hasn't been able to find anyone with the same issue, but im not sure what im doing wrong. I've even tried creating an AGENTS.md file with explicit instructions on what tools to use and not to use fake tools, but it still struggles and will sometimes fail.
11 Comments
OpenAI models use applypatch, which works. Local OSS models use apply_patch, which is not recognized by the Codex CLI, so edits are never applied.
Potential fixes:
Same issue for me
We have this existing option to tweak
apply_patchinstructions for GPT 4.1, though it sounds like we need something a bit different in this case:https://github.com/openai/codex/blob/a191945ed696c2e0a61d33995a474e5fd9446b24/codex-rs/core/src/model_family.rs#L12-L14
In any event, we should fix this through
ModelFamily.@InnerWerks I ran into this exact issue when trying to use gpt-oss:20b from Ollama with codex --oss.
In OSS mode, Codex only loads the update_plan tool and doesn’t actually have apply_patch available, so any edit attempt ends up being a “fake” patch invocation that never applies.
The workaround that worked for me was to define a profile in the Codex config that uses the Ollama provider directly, instead of launching with --oss. That way Codex runs in a “trusted” workspace with apply_patch enabled and can actually write to the codebase.
Here’s the config I used (~/.config/codex/config.toml):
Then I launch Codex with:
codex --profile ollamaWith this setup:
•/status shows Provider: Ollama (not “Oss”)
•Tools include apply_patch, git, etc.
•File edits work as expected, no need to manually craft diffs.
•You still get to run your local Ollama model, but with proper tool access.
So if you’re running into the “can’t edit files” problem with local models, try skipping --oss and using a profile like the above to point to your Ollama model.
Have you had success in using it? I just tried that and the model seemed to continuously forget the prompt. Is this an issue with the model, codex, or user error?
interaction.txt
Mmmm not sure, but is working good for me. Maybe in the debug log you can see whats is happening
I'll take a look since you haven't had this issue. Out of curiosity, How does gpt-oss:20b perform? Pretty happy with its coding ability?
@luckystoned @InnerWerks I believe this should be fixed by #2303 - or at least partially improved. Are you still seeing issues on recent versions?
Worked for me in 0.22.0 (which should be the first release to include the fix) when started with:
调研总结:
问题概述:
该 issue 报告了在使用本地开源模型(如 gpt-oss:20b)时,Codex 无法对文件进行编辑操作的问题。用户发现,本地模型尝试使用虚假的
apply_patch工具,而非实际的 CLI 命令或标准的 git diff,导致无法成功修改代码文件。影响范围:
问题状态:
可能原因:
建议后续行动: