Local Models (gpt-oss:20b etc.) Unable to Make Edits to Files

Resolved 💬 11 comments Opened Aug 9, 2025 by ShawnBurnham Closed Aug 21, 2025
💡 Likely answer: A maintainer (bolinfest, collaborator) responded on this thread — see the highlighted reply below.

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.

Issue Example.txt

View original on GitHub ↗

11 Comments

ShawnBurnham · 11 months ago

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.

ShawnBurnham · 11 months ago

Potential fixes:

  • Add an alias in Codex CLI so apply_patch calls are translated to applypatch.
  • Intercept model output and rewrite apply_patch → applypatch before sending to the CLI.
nguyendk270996 · 11 months ago

Same issue for me

bolinfest collaborator · 11 months ago

We have this existing option to tweak apply_patch instructions 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.

luckystoned · 11 months ago

@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):

projects = { "/your-path/codex-test" = { trust_level = "trusted" } }

[model_providers.ollama]
base_url = "http://localhost:11434/v1"
name = "Ollama"

[profiles.ollama]
model_provider = "ollama"
model = "gpt-oss:20b"

Then I launch Codex with:

codex --profile ollama

With 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.

ShawnBurnham · 11 months ago
So

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

luckystoned · 11 months ago
> So 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

ShawnBurnham · 11 months ago
> > So > > > 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?

dylan-hurd-oai contributor · 11 months ago

@luckystoned @InnerWerks I believe this should be fixed by #2303 - or at least partially improved. Are you still seeing issues on recent versions?

teekuningas · 11 months ago

Worked for me in 0.22.0 (which should be the first release to include the fix) when started with:

codex --oss -m "gpt-oss:120b"
DreamCats · 9 months ago

调研总结:

问题概述
该 issue 报告了在使用本地开源模型(如 gpt-oss:20b)时,Codex 无法对文件进行编辑操作的问题。用户发现,本地模型尝试使用虚假的 apply_patch 工具,而非实际的 CLI 命令或标准的 git diff,导致无法成功修改代码文件。

影响范围

  • 仅影响本地开源模型(如通过 Ollama 运行的模型)
  • OpenAI 提供的模型(API 或 Plus 订阅)工作正常
  • 用户尝试通过创建 AGENTS.md 文件指导模型使用正确工具,但效果有限

问题状态

  • 状态:已关闭(closed)
  • 关闭时间:2025年8月21日
  • 关闭者:问题提交者本人(ShawnBurnham)

可能原因

  1. 本地开源模型可能未正确识别或适配 Codex 的实际工具集
  2. 模型输出格式不符合 Codex 预期的 POSIX shell 命令或 git diff 格式
  3. 缺乏针对本地模型的工具使用指导或上下文提示

建议后续行动

  1. 验证本地模型是否正确加载工具使用指南
  2. 检查模型输出格式是否与 Codex 预期格式匹配
  3. 考虑为本地模型提供更明确的工具使用提示或系统提示词优化
  4. 如果问题仍存在,建议重新打开 issue 并附加更多调试信息(如模型输出示例)