Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shadowrocket-terminal-proxy

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:1082 listening): sets HTTP_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.

Requirements

  • macOS with Shadowrocket Mac
  • zsh
  • lsof or nc (built-in on macOS)

Default proxy port: 1082 (Shadowrocket Mac default). Change in ~/.config/shadowrocket/proxy.conf if yours differs.

Install

git clone https://github.com/yobo2u/shadowrocket-terminal-proxy.git
cd shadowrocket-terminal-proxy
./install.sh

Then 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-status

CLI launchers (optional)

Install wrappers that auto-detect proxy before each launch:

./install-cli-proxies.sh

Install 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 codex

All arguments are passed through (codex-proxy exec "fix tests").

Commands

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

How it works

  1. On shell start, check if 127.0.0.1:$SHADOWROCKET_PROXY_PORT is listening.
  2. In interactive zsh, precmd re-checks every ~3 seconds when you toggle Shadowrocket.
  3. 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.

Configuration

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,..."

License

MIT

About

Auto-sync terminal HTTP_PROXY with Shadowrocket Mac VPN tunnel

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages