動かざることバグの如し

近づきたいよ 君の理想に

codexでファイル編集時にPython使うせいで遅くなってる件

環境

  • codex-cli 0.53.0

問題

最近codexの処置が遅く感じる。調べてみるとすでにGitHubのIssueが建ってた。

github.com

つまりCodexが本来のファイル編集ツールを使わずに、Pythonスクリプトを自動で生成・実行してファイルを編集してしまう現象が原因らしい。

よくよく見るとこういうPythonでなにかやってそうなログがよく出る。

▌ 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' ...

こっちとしては困るわけで

  • 本来のツールと違って変更差分(diff)がすぐに見られないため、どのような変更が加えられたのか分かりにくい。
  • 生成されるPythonスクリプトは不正確なことが多く、たった1行の修正のために何度も試行錯誤を繰り返すことがある。遅いしトークンを無駄に喰わされる。

ネイティブのパッチ機能を使ってほしい。

対応方法

使用するモデルをgpt-5-codexからgpt-5へ変更したら直ったって人もいたが私の環境では変わらなかった。

gpt-5-codexにはPythonを読み書きで使うなという指示がシステムプロンプトに追加されてた。

github.com

が、revertされてる。

github.com

そこでAGENTS.mdに以下を自分で追記する。

When editing or creating single files, you MUST use apply_patch as a standalone tool without going through ["bash", "-lc"], `Python`, `cat`, `sed`, ...Example: functions.shell({"command":["apply_patch","*** Begin Patch\nAdd File: hello.txt\n+Hello, world!\n*** End Patch"]}).

ファイル編集時に完璧に治ったわけではないが頻度は減った気がする。

参考リンク