跪拜 Guibai
← All articles
Frontend · Backend · JavaScript

Reverse-Engineering Codex's System Prompts with mitmproxy

By 四千岁 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Agent tools like Codex are black boxes whose behavior is dictated by hidden system prompts. Intercepting those prompts gives developers a concrete baseline to study, critique, or replicate the prompt engineering that drives an agent's output quality.

Summary

Codex is an agent that relies entirely on the quality of its system prompts to direct a large model. Capturing its traffic with mitmproxy exposes those prompts in full detail. The setup routes Codex through a local reverse proxy pointed at DeepSeek's API, then inspects every request and response in a browser-based dashboard.

The process uses CC Switch to redirect Codex from OpenAI to a domestic model, then mitmweb in reverse-proxy mode to intercept the chat completion calls. The captured payloads show the system prompt, the user message, and the model's reply side by side. After inspection, restoring the original base_url in Codex's config.toml returns everything to normal.

Takeaways
mitmproxy in reverse mode can intercept Codex's API calls by pointing its base_url at a local proxy.
CC Switch redirects Codex from OpenAI to alternative providers like DeepSeek without modifying the client itself.
The captured request body contains the full system prompt Codex prepends to every user message.
DeepSeek's Response API follows the same structure as OpenAI's, making the interception method broadly applicable.
After capture, restoring the original base_url in config.toml and restarting Codex reverts the setup cleanly.
Conclusions

System prompts are the entire differentiator for an agent like Codex; the model underneath is interchangeable, which is why the proxy swap to DeepSeek works at all.

Using a domestic model through CC Switch is not just a cost play — it also makes traffic inspection easier when the API format matches OpenAI's.

The mitmweb dashboard turns a normally opaque agent interaction into a transparent three-part view: system prompt, user input, model output.

Concepts & terms
mitmproxy
An open-source interactive HTTPS proxy that can intercept, inspect, and modify network traffic, often used for debugging APIs and reverse-engineering client-server communication.
System Prompt
A hidden instruction prepended to every user message sent to an LLM, defining the model's role, behavior, and constraints before it sees any user input.
Reverse Proxy Mode (mitmweb)
A mitmproxy mode where the proxy forwards requests to a fixed upstream server, allowing transparent interception of traffic between a client and a specific API endpoint.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗