Keep Codex model traffic on your current CC Switch provider—such as AnyRouter—while sending native Codex web search to ChatGPT.
Warning
This project relies on the observed, undocumented /v1/alpha/search behavior of current Codex builds. OpenAI may change or remove that endpoint at any time. Treat this project as an experimental compatibility layer, not an official integration.
Codex custom providers normally receive API traffic through their configured base_url. CC Switch makes that useful for switching Responses-compatible model providers, but many third-party providers do not implement Codex's separate first-party search request.
In affected setups, model calls work through AnyRouter while native web_search fails. This local router separates those two paths:
flowchart LR
A["Codex"] --> B["127.0.0.1:15722/v1"]
B -->|"/v1/alpha/search"| C["ChatGPT Codex backend"]
B -->|"all other /v1/*"| D["CC Switch route service :15721"]
D --> E["Current CC Switch provider, e.g. AnyRouter"]
The config watcher keeps config.toml pointed at port 15722 when CC Switch rewrites the active provider. CC Switch still owns provider selection and credentials.
The router is intentionally small, local, and dependency-free:
- It binds to loopback by default and refuses non-loopback listeners unless you pass an explicitly dangerous override.
- ChatGPT OAuth and identity headers are removed from every model request sent to CC Switch.
- Model requests receive only a non-secret local placeholder
Authorizationvalue. - OAuth is preserved only for standalone search, and the search upstream must be HTTPS on
chatgpt.com. - It never reads CC Switch provider API keys or the CC Switch database.
- It never logs request targets, query strings, headers, or bodies.
- Config rewrites use an atomic replace and preserve file permissions.
Prompts and model responses still pass through the CC Switch upstream you configure. You are responsible for trusting that service and its selected provider.
- macOS for the included LaunchAgent installer. The router itself uses portable Python standard-library APIs.
- Python 3.11 or newer.
- Codex logged in with ChatGPT authentication. The router does not create or refresh credentials.
- CC Switch installed, with its Codex routing service enabled and reachable at
http://127.0.0.1:15721by default. - A CC Switch provider that supports the OpenAI Responses wire format for model calls.
Codex's documented configuration supports custom model providers and web_search modes. See Advanced Configuration and Web search.
git clone https://github.com/Brady040801/codex-ccswitch-search-split.git
cd codex-ccswitch-search-split
./scripts/install-macos.shThe installer:
- Verifies Python and the CC Switch route service.
- Creates a timestamped backup beside your Codex
config.toml. - Copies the router to
~/Library/Application Support/codex-ccswitch-search-split. - Patches the active Codex provider once.
- Installs and starts a per-user LaunchAgent.
Restart Codex after installation. Continue switching providers in CC Switch normally; the watcher reapplies the local split route after each config rewrite.
From the cloned repository:
PYTHONPATH=src python3 -m codex_ccswitch_search_split --statusA healthy installation reports these values as true:
{
"cc_switch_reachable": true,
"config_routed": true,
"router_reachable": true
}Then start a new Codex task and ask it to search for a current fact. Existing Codex processes may retain old provider configuration until restarted.
To test without installing a LaunchAgent:
PYTHONPATH=src python3 -m codex_ccswitch_search_split --configure-once
PYTHONPATH=src python3 -m codex_ccswitch_search_splitBack up config.toml yourself before manual mode. Keep the second process running while using Codex.
CLI flags override the defaults shown by --help. The LaunchAgent installer captures the following environment variables when it runs:
| Variable | Default | Purpose |
|---|---|---|
CODEX_HOME |
~/.codex |
Directory containing config.toml |
CC_SWITCH_HOME |
~/.cc-switch |
CC Switch home used only for status checks |
CODEX_SPLIT_LISTEN_HOST |
127.0.0.1 |
Local listener host |
CODEX_SPLIT_LISTEN_PORT |
15722 |
Local listener port |
CODEX_SPLIT_CC_SWITCH_BASE_URL |
http://127.0.0.1:15721 |
Model-traffic upstream |
CODEX_SPLIT_CHATGPT_CODEX_BASE_URL |
https://chatgpt.com/backend-api/codex |
Search upstream; HTTPS chatgpt.com only |
CODEX_SPLIT_SEARCH_MODEL |
unset | Optional model override applied only to search JSON bodies |
CODEX_SPLIT_WEB_SEARCH_MODE |
live |
Codex search mode: cached, indexed, or live |
CODEX_SPLIT_CONFIG_POLL_SECONDS |
0.5 |
Config watcher interval |
CODEX_SPLIT_UPSTREAM_TIMEOUT_SECONDS |
600 |
Upstream request timeout |
CODEX_SPLIT_MAX_REQUEST_BYTES |
536870912 |
Maximum buffered request body |
CODEX_SPLIT_DANGEROUSLY_ALLOW_NON_LOOPBACK |
unset | Set to a true value only if you deliberately accept unauthenticated network exposure |
If the model selected in AnyRouter is not a model identifier accepted by the ChatGPT search backend, set an explicit search-only model and reinstall:
CODEX_SPLIT_SEARCH_MODEL='<chatgpt-model-id>' ./scripts/install-macos.shUse a model available to your own ChatGPT/Codex account. The project deliberately does not guess one.
For the active custom provider, the watcher sets the local base_url, enables OpenAI authentication so Codex can authenticate standalone search, and enables the currently observed standalone-search compatibility flags. It removes provider credential fields from that active Codex provider section.
This does not delete or read credentials stored inside CC Switch. CC Switch remains responsible for authenticating to AnyRouter or another selected provider.
The project also sets the documented top-level web_search mode. The standalone-search capability flags are undocumented and are the experimental part of this design.
./scripts/uninstall-macos.shThe uninstaller stops the LaunchAgent, removes installed files, and automatically restores your original provider base_url. It reads the URL that was saved during installation (sourced from CC Switch's database) so your config goes back to the provider you were using before the split router.
To explicitly restore a backup you have inspected:
./scripts/uninstall-macos.sh --restore-backup '/path/to/config.toml.pre-search-split.TIMESTAMP.bak'Add --purge-logs if you also want to remove the router's local log directory. Those logs contain service lifecycle messages only, not requests.
The router monitors the CC Switch routing service. If you disable Codex routing inside CC Switch, the router automatically restores your original provider config within a few seconds. Re-enable CC Switch routing and the split routing is re-applied automatically — no manual config edits needed.
Open CC Switch and enable its routing service. Confirm its port matches CODEX_SPLIT_CC_SWITCH_BASE_URL.
Codex did not send ChatGPT authentication. Log out and back into Codex using ChatGPT authentication, then restart Codex.
Set CODEX_SPLIT_SEARCH_MODEL to a model available to your ChatGPT/Codex account and rerun the installer.
CC Switch still selects the upstream provider, but its config.toml rewrite is quickly changed back to the local listener. Check the LaunchAgent error log and run --status. Restart Codex after changing providers if the current process has cached provider settings.
The internal search path may have changed. Please open a redacted issue with the Codex version and HTTP status only. Never attach OAuth tokens, auth.json, unredacted configs, prompts, or request dumps.
python3 -m compileall -q src tests
PYTHONPATH=src python3 -m unittest discover -s tests -v
bash -n scripts/install-macos.sh scripts/uninstall-macos.shSee CONTRIBUTING.md and SECURITY.md.
This independent project is not affiliated with, endorsed by, or sponsored by OpenAI, CC Switch, AnyRouter, or their maintainers. Product names belong to their respective owners.
MIT licensed.