Auto-detect Shadowrocket for Mac tunnel state and set terminal proxy environment variables for CLI tools (Codex, Claude Code, Gemini CLI, curl, npm, etc.).
- Tunnel on (
127.0.0.1:1082listening): setsHTTP_PROXY,HTTPS_PROXY,ALL_PROXY,NO_PROXY - Tunnel off: clears proxy env vars (direct connection)
Detection uses the local proxy port (MacPacketTunnel), not only whether the app process is running.
- macOS with Shadowrocket Mac
- zsh
lsofornc(built-in on macOS)
Default proxy port: 1082 (Shadowrocket Mac default). Change in ~/.config/shadowrocket/proxy.conf if yours differs.
git clone https://github.com/yobo2u/shadowrocket-terminal-proxy.git
cd shadowrocket-terminal-proxy
./install.shThen add the snippets printed by install.sh to ~/.zprofile and ~/.zshrc, or copy from docs/shell-setup.md.
Open a new terminal and run:
proxy-statusInstall wrappers that auto-detect proxy before each launch:
./install-cli-proxies.shInstall locations (final):
| Path | Required |
|---|---|
~/.local/bin |
Yes — always installed, first in typical PATH |
/usr/local/bin |
Optional — system-wide, needs admin password |
Do not use /usr/bin on macOS: SIP prevents adding custom scripts there.
Then use:
gemini-proxy # instead of gemini
claude-proxy # instead of claude
codex-proxy # instead of codexAll arguments are passed through (codex-proxy exec "fix tests").
| Command | Description |
|---|---|
proxy-status |
Show tunnel and env state |
proxy-sync |
Force re-detect |
shadowrocket-proxy-sync on |
Force proxy env on |
shadowrocket-proxy-sync off |
Force proxy env off |
- On shell start, check if
127.0.0.1:$SHADOWROCKET_PROXY_PORTis listening. - In interactive zsh,
precmdre-checks every ~3 seconds when you toggle Shadowrocket. - Child processes started from that terminal inherit
HTTP_PROXY/HTTPS_PROXY.
Note: Already-running CLI sessions do not pick up env changes until restarted. GUI apps launched outside the shell do not use these variables.
Edit ~/.config/shadowrocket/proxy.conf:
SHADOWROCKET_PROXY_HOST=127.0.0.1
SHADOWROCKET_PROXY_PORT=1082
SHADOWROCKET_NO_PROXY="localhost,127.0.0.1,::1,*.local,10.0.0.0/8,..."MIT