Global Rules
Proxy
本页只记录“如何让 Claude Code 及其调用的外部命令在需要时使用代理”。示例地址 127.0.0.1:7897 是这台机器现有配置的记录,不代表通用默认端口;不要猜测、替换或自动改成其他端口。
Claude Code 进程自身的代理
Claude Code 官方支持通过标准 HTTP/HTTPS 代理环境变量配置网络:HTTP_PROXY / HTTPS_PROXY(小写变体也可用)。Claude Code 不支持 SOCKS 代理,因此不要把 ALL_PROXY=socks5://... 或 all_proxy=socks5://... 写成 Claude Code 自身的代理方案。
官方说明:Claude Code 网络配置
Git Bash / WSL
仅对当前 shell 会话生效:
export HTTP_PROXY=http://127.0.0.1:7897export HTTPS_PROXY=http://127.0.0.1:7897
claude如需清除当前会话中的设置:
unset HTTP_PROXY HTTPS_PROXYunset http_proxy https_proxy如果环境中另有 ALL_PROXY / all_proxy 用于其他工具,可以单独保留;但不要把它描述为 Claude Code 的 SOCKS 代理配置,也不要依赖它让 Claude Code 联网。
PowerShell
仅对当前 PowerShell 会话及其启动的子进程生效:
$env:HTTP_PROXY = "http://127.0.0.1:7897"$env:HTTPS_PROXY = "http://127.0.0.1:7897"
claude如需清除当前会话中的设置:
Remove-Item Env:HTTP_PROXY -ErrorAction SilentlyContinueRemove-Item Env:HTTPS_PROXY -ErrorAction SilentlyContinue不要为 Claude Code 设置 ALL_PROXY=socks5://127.0.0.1:7897;Claude Code 本身不支持 SOCKS 代理。
Claude 调用 Git / npm / pip 等外部工具时
Claude Code 启动的 Git、npm、pip 等命令是独立外部工具。它们通常会继承 Claude Code 进程的环境变量,因此优先在启动 Claude Code 的同一终端会话中设置 HTTP_PROXY / HTTPS_PROXY,而不是修改机器级或用户级持久配置。
不同工具的代理能力并不完全一致。某些外部工具可能另外支持 ALL_PROXY 或 SOCKS,但那属于该外部工具自身的能力,不能据此推断 Claude Code 支持 SOCKS。只有在确认具体工具支持时,才单独为该工具配置。
Git:优先使用当前会话环境变量
Git Bash / WSL:
export HTTP_PROXY=http://127.0.0.1:7897export HTTPS_PROXY=http://127.0.0.1:7897git pullPowerShell:
$env:HTTP_PROXY = "http://127.0.0.1:7897"$env:HTTPS_PROXY = "http://127.0.0.1:7897"git pullGit:一次性命令级代理
如果只希望某一次 Git 操作走代理,可使用 -c,不会写入全局配置:
git -c http.proxy=http://127.0.0.1:7897 -c https.proxy=http://127.0.0.1:7897 clone https://github.com/OWNER/REPO.git同样可用于其他 Git 子命令,例如:
git -c http.proxy=http://127.0.0.1:7897 -c https.proxy=http://127.0.0.1:7897 pullGit:可选的持久全局配置
只有明确希望当前用户以后所有 Git 仓库都默认使用该代理时,才使用 --global。这不是 Claude Code 的必要设置,也不应作为默认动作:
git config --global http.proxy http://127.0.0.1:7897git config --global https.proxy http://127.0.0.1:7897恢复全局设置:
git config --global --unset http.proxygit config --global --unset https.proxy如需先检查当前值:
git config --global --get http.proxygit config --global --get https.proxynpm / pip / yarn / pnpm / conda 等
优先让这些命令继承当前会话的 HTTP_PROXY / HTTPS_PROXY。如果某个工具不遵循这些变量,再按照该工具自己的官方文档配置工具级代理。不要为了让 Claude Code 工作而默认写入 Git 全局配置,也不要把 SOCKS ALL_PROXY 当成 Claude Code 的通用代理设置。