nikkie-ftnextの日記

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

【速報】nikkie氏、ついに Codex CLI から Responses API へのリクエストを覗くことに成功!

はじめに

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

Codex CLI と codex-rs のソースコードリーディングをする中で、ついに悲願を達成しました!

目次

コーディングエージェントは全て分かりたい

この想いで日々やっています1

https://ftnext.github.io/2025-slides/aidd-codex1/codex-rs-telemetry.html#/4 より

Codex CLI は Responses API2 を使って実装されています。
Responses API へのリクエストを見てみたいですよね?

platform.openai.com

「Tracing / verbose logging」(Advanced ドキュメント)

https://github.com/openai/codex/blob/rust-v0.63.0/docs/advanced.md#tracing--verbose-logging-tracing-verbose-logging

Because Codex is written in Rust, it honors the RUST_LOG environment variable to configure its logging behavior.

なんと環境変数RUST_LOGがあるとのこと3

the non-interactive mode (codex exec) defaults to RUST_LOG=error, but messages are printed inline,

そして、codex exec は、ログメッセージをコンソールに出力するとのこと

見たいのはこちらの箇所です。
https://github.com/openai/codex/blob/rust-v0.63.0/codex-rs/core/src/client.rs#L318-L322

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

    "shell_command",
    "list_mcp_resources",
    "list_mcp_resource_templates",
    "read_mcp_resource",
    "update_plan",
    "apply_patch",
    "view_image",

ソースコードを見て間接証拠を集めていましたが、ついに直接見ることができました。
渡されたツールは思っていたよりも少なかったです

終わりに

Codex CLI から Responses API へのリクエストを覗けました🙌

RUST_LOGすごいですね。
リクエストの JSON 本体を確認できたので、ツールの動きの解像度はぐっと高まりました。


  1. 同僚の評「束縛系
  2. 利用した過去記事
  3. env_logger crate のおかげのようです。 https://docs.rs/env_logger/latest/env_logger/