跪拜 Guibai
← Back to the summary

Reverse-Engineering Codex's System Prompts with mitmproxy

Capturing Codex - Checking How Codex's Prompts Are Written

Codex is just an Agent. Without a large model, Codex can't do anything. To make a large model perform at its best, it mainly depends on prompts. So this time, we are capturing Codex's traffic to see how Codex writes the system prompts for the large model.

The main tool we use for capturing Codex traffic this time is mitmproxy. I installed it via Python's package manager uv.

Installing uv

uv Official Documentation

Installing uv

On Windows, open a PowerShell command window with administrator privileges, then execute the following command:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

On Linux, execute the following command in the terminal:

curl -LsSf https://astral.sh/uv/install.sh | sh

To install a specific version of uv, execute the following command:

Windows:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/0.12.5/install.ps1 | iex"

Linux:

curl -LsSf https://astral.sh/uv/0.12.5/install.sh | sh

After installation, execute the uv self version command to check the installed uv version:

uv self version check installed uv version

Installing the packet capture tool mitmproxy

# Install mitmproxy globally
uv tool install mitmproxy

# Check which directory uv tool install installed the tool mitmproxy into
uv tool dir

# Check which directory the executable command for the tool mitmproxy is in
uv tool dir --bin

# Uninstall mitmproxy
uv tool uninstall mitmproxy

Installing mitmproxy via uv

Installing CC Switch

Codex only supports using large models from OpenAI. We can install the software CC Switch to let CC Switch proxy Codex's network requests, thereby sending all of Codex's requests to domestic large models. Then we can smoothly use domestic large models through Codex.

Visit the CC Switch official website, then download and install CC Switch.

Installing CC Switch

Configuring the DeepSeek domestic large model in CC Switch

After installing CC Switch, click the + button on the main interface of CC Switch, as shown below:

Clicking the + button in CC Switch

Selecting DeepSeek as the provider

Filling in the DeepSeek API Key

Checking the baseurl

Enabling the DeepSeek configuration

Restarting the Codex software

Using Codex

Capturing Codex Traffic

Open a PowerShell window with administrator privileges and execute the following command:

mitmweb --mode reverse:https://api.deepseek.com -p 8889

Note: Do not close the PowerShell window running the mitmweb command until you have finished capturing traffic.

Executing the mitmweb command

Modify the base_url in Codex's configuration file config.toml, located at C:\Users\YourComputerUsername.codex\config.toml:

Modifying the base_url in the config.toml file

After modifying the base_url in config.toml and saving it successfully, restart the Codex software.

Sending a message to Codex after reopening it

Viewing the Captured Content

Then, in a browser, visit the address provided by the mitmweb command: http://127.0.0.1:8081/?token=57cc042b500fa69a0cf2a172e39677d3:

Visiting http127.0.0.18081

Clicking the request here

Viewing the system prompt Codex sends to the large model

The message we ourselves sent to the large model

Viewing the large model's reply to Codex

DeepSeek's Official Response API Documentation

DeepSeek's Official Response API Documentation:

DeepSeek's Official Response API Documentation

DeepSeek request message field input

For complete Response API usage, please refer to OpenAI's official documentation

After Capturing Traffic

After capturing traffic, please restore the base_url in Codex's configuration file config.toml to https://api.deepseek.com, then restart Codex. The path is C:\Users\YourComputerUsername.codex\config.toml:

Restoring Codex's base_url