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
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:
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 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.
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:
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.
Modify the base_url in Codex's configuration file config.toml, located at C:\Users\YourComputerUsername.codex\config.toml:
After modifying the base_url in config.toml and saving it successfully, restart the Codex software.
Viewing the Captured Content
Then, in a browser, visit the address provided by the mitmweb command: http://127.0.0.1:8081/?token=57cc042b500fa69a0cf2a172e39677d3:
DeepSeek's Official Response API Documentation
DeepSeek's Official Response API 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: