はじめに
七尾百合子さん、お誕生日 252日目 おめでとうございます! nikkieです。
Codex CLI と codex-rs のソースコードリーディングをする中で、ついに悲願を達成しました!
目次
- はじめに
- 目次
- コーディングエージェントは全て分かりたい
- 「Tracing / verbose logging」(Advanced ドキュメント)
- Responses API へのリクエストを見る
- 終わりに
コーディングエージェントは全て分かりたい
この想いで日々やっています1
Codex CLI は Responses API2 を使って実装されています。
Responses API へのリクエストを見てみたいですよね?
「Tracing / verbose logging」(Advanced ドキュメント)
Because Codex is written in Rust, it honors the
RUST_LOGenvironment variable to configure its logging behavior.
the non-interactive mode (
codex exec) defaults toRUST_LOG=error, but messages are printed inline,
そして、codex exec は、ログメッセージをコンソールに出力するとのこと
trace!( "POST to {}: {}", self.provider.get_full_url(&auth), payload_json.to_string() );
Responses API へのリクエストを見る
RUST_LOG=codex_core=trace codex exec "print hello" --skip-git-repo-check 2> codex-core-trace.log
Git リポジトリの外でやったので--skip-git-repo-checkを付けました。
codex-core-trace.logから見たい箇所を取り出したのがこちら:
https://gist.github.com/ftnext/7b0caeec056188da387e8333e30be749
- デフォルトモデル gpt-5.1-codex で、プロンプトは https://github.com/openai/codex/blob/rust-v0.63.0/codex-rs/core/gpt_5_codex_prompt.md
- toolは7つ
"shell_command",
"list_mcp_resources",
"list_mcp_resource_templates",
"read_mcp_resource",
"update_plan",
"apply_patch",
"view_image",
- ユーザ入力の前にカレントディレクトリのパスが送られている
- temperatureは指定していないので、1
ソースコードを見て間接証拠を集めていましたが、ついに直接見ることができました。
渡されたツールは思っていたよりも少なかったです
終わりに
Codex CLI から Responses API へのリクエストを覗けました🙌
RUST_LOGすごいですね。
リクエストの JSON 本体を確認できたので、ツールの動きの解像度はぐっと高まりました。
え、RUST_LOG環境変数、神かhttps://t.co/CbcFxnQXlL
— nikkie(にっきー) / にっP (@ftnext) 2025年11月24日
この環境変数を指定するだけで、例えばCodex CLIからResponses APIへのPOSTリクエスト覗けちゃったんですが!!(ソースからのビルドなんて不要)
Pythonはこんなに簡単じゃないと感じます(断ち切りたい悲劇の連鎖...)
- 同僚の評「束縛系」↩
- 利用した過去記事 ↩
- env_logger crate のおかげのようです。 https://docs.rs/env_logger/latest/env_logger/↩
