Sometimes you need to understand what a CLI is doing or figure out what the request/response looks like, or why something isn’t working and you suspect an interaction that’s outside your control with a third-party server happening through the CLI.
While this is not strictly just for CLIs, here’s the quick setup for mitmproxy for CLIs – note that this is not guaranteed to work for all CLIs, but most python based CLIs should work. For node, you may need to add NODE_EXTRA_CA_CERTS=~/.mitmproxy/mitmproxy-ca-cert.pem:
uv venv
uv pip install mitmproxy
source venv/bin/activate
mitmproxy --listen-port 8080
# On the terminal where you run the CLI
export HTTPS_PROXY=http://127.0.0.1:8080
export HTTP_PROXY=http://127.0.0.1:8080
export SSL_CERT_FILE=~/.mitmproxy/mitmproxy-ca-cert.pem
export REQUESTS_CA_BUNDLE=~/.mitmproxy/mitmproxy-ca-cert.pem
<Run your CLI now and you should see the capture in mitmproxy>
# If you need to customize intercepts
# Create the python file with your intercepts
mitmdump -s intercept.py --listen-port 8080