配置Clash实现网络层流量自动拦截
Clash是一个基于规则的代理核心,可以通过配置规则来实现流量的智能路由。CC-Gateway提供了专门的Clash规则配置,可以拦截所有Claude Code相关流量并引导到CC-Gateway网关。
虽然通过设置环境变量可以让Claude Code主动使用网关,但Clash规则提供了更底层的拦截:
将以下规则添加到你的Clash配置文件中:
# CC-Gateway规则片段
# Anthropic API域名
rules:
- DOMAIN-SUFFIX,anthropic.com,cc-gateway
- DOMAIN-KEYWORD,claude,cc-gateway
- DOMAIN-KEYWORD,anthropic,cc-gateway
# CC-Gateway代理组配置
proxy-groups:
- name: cc-gateway
type: http
url: http://你的网关IP:8080
interval: 300
tls: false
sni: api.anthropic.com
# 如果需要经过代理再到达网关
- name: cc-gateway-via-proxy
type: select
proxies:
- cc-gateway
- 你的代理节点
mixed-port: 7890
allow-lan: true
mode: rule
log-level: info
proxy-groups:
- name: cc-gateway
type: http
url: http://localhost:8080
interval: 300
tls: false
- name: PROXY
type: select
proxies:
- cc-gateway
- DIRECT
rules:
- DOMAIN-SUFFIX,anthropic.com,cc-gateway
- DOMAIN-KEYWORD,claude,cc-gateway
- DOMAIN-KEYWORD,anthropic,cc-gateway
- GEOIP,CN,PROXY
- MATCH,PROXY
localhost:8080 替换为你的实际网关地址