How to use the Headroom compression proxy with cc-switch when it overwrites ANTHROPIC_BASE_URL?
I use cc-switch to manage provider switching for Claude Code and Codex and want to insert the Headroom context-compression proxy between the client and the provider. On every provider switch or restart, cc-switch overwrites ANTHROPIC_BASE_URL / OPENAI_BASE_URL in ~/.claude/settings.json to point at its own local proxy, so any manual change that routes to Headroom gets reverted. Its outbound proxy uses an HTTPS CONNECT tunnel, so an intermediate proxy cannot read request bodies. Is there a way to make cc-switch and Headroom work together today?
Originally asked on GitHub: https://github.com/farion1231/cc-switch/issues/3943
6 answers
Still open as of the thread's last activity (August 2026): cc-switch has no upstream-proxy feature and no maintainer response in the thread. Two workarounds were shared by users.
- Port split + config monitor (comment 2): run cc-switch on port 15722 and Headroom on 15721, then keep a script that restores the client config after cc-switch rewrites it:
bashmkdir -p ~/.local/bin curl -fsSL https://raw.githubusercontent.com/duanluan/shell-scripts/main/codex-headroom-port-monitor.sh -o ~/.local/bin/codex-headroom-port-monitor chmod +x ~/.local/bin/codex-headroom-port-monitor ./codex-headroom-port-monitor.sh --once # single repair ./codex-headroom-port-monitor.sh # keep runningIt can also run as a systemd user service (create ~/.config/systemd/user/codex-headroom-port-monitor.service with ExecStart=/bin/bash %h/.local/bin/codex-headroom-port-monitor, then systemctl --user daemon-reload and systemctl --user enable --now ...). The same comment suggests cc-switch should distinguish the listening port from the port written into client config and should stop deleting non-custom model_providers; it shows this Codex entry:
ini[model_providers.headroom] name = "OpenAI via Headroom proxy" base_url = "http://127.0.0.1:15721/v1" supports_websockets = true env_http_headers = { "X-Headroom-Project" = "HEADROOM_PROJECT" }- Headroom-side PR (comment 11): a commenter says they submitted a PR to Headroom that makes it coexist with cc-switch, and it works on their machine; details are in a blog post linked in the comment.
A design under discussion (comment 1) proposes a client_facing_url field so cc-switch writes the external proxy's address into client settings while still handling auth injection, routing and failover; with cc-switch's PROXY_MANAGED placeholder, the intermediate proxy would not see real API keys.
Security note: the monitor script automatically rewrites your local client config files — review what it modifies before running it.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Moved cc-switch to a different port and put Headroom on the original port so clients would reach Headroom first; cc-switch rewrites the client config on every restart or provider switch, so Headroom gets bypassed.
Source: https://github.com/farion1231/cc-switch/issues/3943 (opens external site)
Did this work for you?What a GitHub user tried on GitHub (Partly worked)
Used a shell alias (claude-hr) to route Claude through Headroom; it works but has poor UX and bypasses cc-switch's management of config and providers.
Source: https://github.com/farion1231/cc-switch/issues/3943 (opens external site)
Did this work for you?What a GitHub user tried on GitHub (Partly worked)
Pointed each provider's endpoint directly at Headroom; this required per-provider configuration and manual edits on every provider switch, so it is not practical for regular switching.
Source: https://github.com/farion1231/cc-switch/issues/3943 (opens external site)
Did this work for you?What @duanluan tried on GitHub (Outcome unclear)
Described running cc-switch on port 15722 with Headroom on 15721 and a monitor script (codex-headroom-port-monitor.sh) that restores the client config after cc-switch overwrites it, run once, continuously, or as a systemd user service; the comment reports this as their current setup.
Source: https://github.com/farion1231/cc-switch/issues/3943#issuecomment-4797703655 (opens external site)
Did this work for you?What @lifeodyssey tried on GitHub (Worked)
Submitted a PR to Headroom to make it coexist with cc-switch; the commenter says it works normally on their machine.
Source: https://github.com/farion1231/cc-switch/issues/3943#issuecomment-5105269467 (opens external site)
Did this work for you?
Related questions
- Does the latest cc-switch support opencode for managing AI providers?
- Does cc-switch support GitHub Copilot and multiple Copilot accounts?
- Does cc-switch support switching providers for Claude Desktop?
- cc-switch on a headless server: is there a CLI or web UI?
- cc-switch: how to switch between multiple official OAuth accounts (Codex, Copilot, Grok)?