nikkie-ftnextの日記

イベントレポートや読書メモを発信

Codex CLI、気になる2点 〜対応モデル増加、仕組みはdiff〜

はじめに

七尾百合子さん、お誕生日 36日目 おめでとうございます! nikkieです。

先週リリースされたOpenAIのCodex CLI、オープンゆえに展開が速いと感じており、気になるところを書き留めます。
まだ触れていなくて、触るときに見返す用スクラップです

目次

Codex CLI

ちなみにOpenAI.fmも公開されました

対応するモデル、広がる

対応するモデルはFAQより、OpenAIのモデルです。
https://github.com/openai/codex/blob/2cb8355968f3f9ae7432aeb56dab08f89707705b/README.md#faq

Which models are supported?
Any model available with Responses API. The default is o4-mini, but pass --model gpt-4.1 or set model: gpt-4.1 in your config file to override.

ymichael/open-codex

Twitterで見かけた1対応モデル拡張の動き

Uses the Chat Completion API instead of the Responses API which allows us to support any openai compatible provider and model.

LiteLLMによるサポート!

OpenAIのCodex CLIはResponses APIのみサポートですが、LiteLLMが多数のLLM APIをResponses APIとして扱えるようにアダプタになるってことですかね?
ref: https://docs.litellm.ai/docs/response_api

OpenAI側のドキュメントにも!

仕組みは、diff!?

プロンプトはこちらと知ります
https://github.com/openai/codex/blob/c00ae2dcc158e6a80565182a737e95508fc17ed8/codex-cli/src/utils/agent/agent-loop.ts#L1243-L1288

laisoさん記事より引用

toolは「shell」のみ

Codex CLIソースコードをファイルに保存する仕組みは、apply_patchと呼ばれています。

プロンプトより

Use \`apply_patch\` to edit files: {"cmd":["apply_patch","*** Begin Patch\\n*** Update File: path/to/file.py\\n@@ def example():\\n-  pass\\n+  return 123\\n*** End Patch"]}

OpenAIのモデルはdiffを扱える!?
事前にAnthropicのブログを読んでいたので意外でした。

Anthropic「Building effective agents」

Appendix 2です。

you can specify a file edit by writing a diff, or by rewriting the entire file.

LLMでファイルを編集する場合、diffを書く方法やファイル全体を書き直す方法があります。

However, some formats are much more difficult for an LLM to write than others.
Writing a diff requires knowing how many lines are changing in the chunk header before the new code is written.

LLMにとってはdiffを書く方が難しい(ファイル全体を書き直させたほうが簡単)と言っていると理解しました。
実際、GitHub Copilot Agentなどはファイルをまるまる書き換えますよね。

GPT-4.1 Prompting Guide

GPT-4.1のプロンプトガイド Appendixより
https://cookbook.openai.com/examples/gpt4-1_prompting_guide#appendix-generating-and-applying-file-diffs

the GPT-4.1 family features substantially improved diff capabilities relative to previous GPT models.

(Anthropicのドキュメントでは)LLMには難しいとされるdiff、OpenAIのモデル(特に4.1)は扱えるの!?

なおAppendixではdiffが公開されていて(「we open-source here one recommended diff format」)、私は「これ、需要ある?」と思っていたのですが、Codex CLIで使っている仕組みだったとは。
Codex CLIを公開している理由も、他のLLMにはdiffが難しいから公開しても優位は維持できるということかもしれませんね(※推測です)

終わりに

Codex CLIの展開を見る中で気になる点を書き出しました。
いろんなLLMを試せたり、仕組みはdiffだったり。
早く触りたいですね。うずうず

P.S. Claude Codeのベストプラクティス

Codex CLIは用途としてはClaude Codeと同じだと思っているので、ベストプラクティスは参考になりそうです。


  1. おそらくご本人