Token导航 LogoToken导航

Agent Skill · 研究检索

claude-code-proxy-patterns(Claude 代码 proxy 模式)

claude-code-proxy-patterns 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

claude-code-proxy-patterns 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证信息还不明确,第三方扫描有未通过项,按安装量在研究检索类的 73,675 个 Skill 里排第 39,700。

总安装 1,374周安装 59GitHub Stars 38下载 481核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:claude-code-proxy-patterns(Claude 代码 proxy 模式)
来源仓库:https://github.com/terrylica/cc-skills
仓库路径:skills/claude-code-proxy-patterns
安装命令:
npx skills add https://github.com/terrylica/cc-skills --skill claude-code-proxy-patterns
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/terrylica/cc-skills --skill claude-code-proxy-patterns

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

claude-code-proxy-patterns 实现基于模型类型的智能路由代理,优化成本与性能平衡。适用于 Claude Max/Pro 订阅用户,将 Haiku 请求转发至 MiniMax,Sonnet/Opus 保留给 Anthropic。

包含 Go 语言实现的本地反向代理,支持 launchd 自启和故障转移机制。部署前需配置 OAuth 订阅信息,并确保本地端口未被占用或防火墙放行。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/claude-code-proxy-patterns

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/terrylica/cc-skills --skill claude-code-proxy-…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

claude-code-proxy-patterns 怎么安装?

在终端执行 npx skills add https://github.com/terrylica/cc-skills --skill claude-code-proxy-patterns。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

claude-code-proxy-patterns 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

claude-code-proxy-patterns 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

claude-code-proxy-patterns 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

claude-code-proxy-patterns 用的人多吗?

公开数据是累计安装 1,374 次,近一周安装 59 次,下载 481 次,GitHub 38 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

claude-code-proxy-patterns 安全吗?

第三方扫描有未通过项,风险较高。除非你确认过源码,否则不建议直接安装到常用环境。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方扫描存在提醒项或未通过项,需要人工逐条确认。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
claude-code-proxy-patterns

Claude 代码 proxy 模式 · 本页

1,37438接触敏感数据未明确未通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Claude Code Proxy Patterns

Multi-provider proxy that routes Claude Code model tiers to different backends. Haiku to MiniMax (cost/speed), Sonnet/Opus to Anthropic (native OAuth passthrough). Includes Go binary proxy with launchd auto-restart and failover wrapper for resilience.

Scope: Local reverse proxy for Claude Code with OAuth subscription (Max plan). Routes based on model name in request body.

Reference implementations:

  • Go proxy binary: /usr/local/bin/claude-proxy (port 8082)

Self-Evolving Skill: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.

When to Use This Skill

  • Building or debugging a Claude Code multi-provider proxy
  • Setting up ANTHROPIC_BASE_URL with OAuth subscription mode
  • Integrating Anthropic-compatible providers (MiniMax, etc.)
  • Diagnosing "OAuth not supported" or auth failures through a proxy
  • Understanding how Claude Code stores and transmits OAuth tokens

Do NOT use for: Claude API key-only setups (no proxy needed), MCP server development, Claude Code hooks (operate at tool level, not API level), or corporate HTTPS proxy traversal.


Architecture

Claude Code (OAuth/Max subscription)
    |
    |  ANTHROPIC_BASE_URL=http://127.0.0.1:8082 (Go proxy)
    |  (unset ANTHROPIC_API_KEY to avoid auth conflict)
    v
+----------------------------------+
| Go proxy (:8082)                 |
| launchd managed, auto-restart   |
+----------------------------------+
    |
    | model =
    | claude-haiku-
    | 4-5-20251001
    v
+-----------+
| MiniMax   |
| highspeed |
+-----------+

Port Configuration:

  • :8082 - Go proxy (entry point, launchd-managed, auto-restart)

The Go proxy uses cenkalti/backoff/v4 for built-in retry logic.

The proxy reads the model field from each /v1/messages request body. If it matches the configured Haiku model ID, the request goes to MiniMax. Everything else falls through to real Anthropic with OAuth passthrough.


Working Patterns

WP-01: Keychain OAuth Token Reading

Read OAuth tokens from macOS Keychain where Claude Code stores them.

Service: "Claude Code-credentials" (note the space before the hyphen) Account: Current username via getpass.getuser()

import subprocess, json, getpass

result = subprocess.run(
    ["security", "find-generic-password",
     "-s", "Claude Code-credentials",
     "-a", getpass.getuser(), "-w"],
    capture_output=True, text=True, timeout=5, check=False,
)
if result.returncode == 0:
    data = json.loads(result.stdout.strip())
    oauth = data.get("claudeAiOauth")

See references/oauth-internals.md for the full deep dive.

WP-02: Token JSON Structure

The Keychain stores a JSON envelope with the claudeAiOauth key.

{
  "claudeAiOauth": {
    "accessToken": "eyJhbG...",
    "refreshToken": "rt_...",
    "expiresAt": 1740268800000,
    "subscriptionType": "claude_pro_2025"
  }
}

Note: expiresAt is in milliseconds (Unix epoch _ 1000). Compare with time.time() _ 1000 or divide by 1000 for seconds.

WP-03: OAuth Beta Header

The anthropic-beta: oauth-2025-04-20 header is required for OAuth token authentication. Without it, Anthropic rejects the Bearer token.

Critical: APPEND to existing beta headers, do not replace them.

# proxy.py:304-308
existing_beta = original_headers.get("anthropic-beta", "")
beta_parts = [b.strip() for b in existing_beta.split(",") if b.strip()] if existing_beta else []
if "oauth-2025-04-20" not in beta_parts:
    beta_parts.append("oauth-2025-04-20")
target_headers["anthropic-beta"] = ",".join(beta_parts)

WP-04: ANTHROPIC_API_KEY=proxy-managed

Setting ANTHROPIC_BASE_URL alone is insufficient in OAuth mode. Claude Code must also see ANTHROPIC_API_KEY set to switch from OAuth-only mode to API-key mode, which then honors ANTHROPIC_BASE_URL.

# In .zshenv (managed by proxy-toggle)
export ANTHROPIC_BASE_URL="http://127.0.0.1:8082"
export ANTHROPIC_API_KEY="proxy-managed"

The value "proxy-managed" is a dummy sentinel. The proxy intercepts it (line 324) and never forwards it to providers.

WP-05: OAuth Token Cache with TTL

Avoid repeated Keychain subprocess calls by caching the token for 5 minutes.

# proxy.py:117-118
_oauth_cache: dict = {"token": None, "expires_at": 0.0, "fetched_at": 0.0}
_OAUTH_CACHE_TTL = 300  # Re-read from Keychain every 5 minutes

Cache invalidation triggers:

  • TTL expired (5 minutes since last fetch)
  • Token's expiresAt has passed
  • Proxy restart

WP-06: Auth Priority Chain

The proxy tries multiple auth sources in order for Anthropic-bound requests.

1. REAL_ANTHROPIC_API_KEY env var   -> x-api-key header (explicit config)
2. Keychain OAuth token             -> Authorization: Bearer + anthropic-beta
3. ~/.claude/.credentials.json      -> Authorization: Bearer (plaintext fallback)
4. Forward client Authorization     -> Pass through whatever Claude Code sent
5. No auth                          -> Will 401 (expected)

See proxy.py:293-314 for the implementation.

WP-07: count_tokens Endpoint Auth

The /v1/messages/count_tokens endpoint needs the same auth as /v1/messages. Claude Code calls this for preflight token counting. Missing auth here causes silent failures. Returns 501 for non-Anthropic providers (MiniMax doesn't support it).

WP-08: Anthropic-Compatible Provider URLs

Third-party providers that support the Anthropic /v1/messages API format.

ProviderBase URLNotes
MiniMax highspeedhttps://api.minimax.io/anthropicReturns base_resp field, extra thinking block

See references/provider-compatibility.md for the full matrix.

WP-09: Concurrency Semaphore

Per-provider rate limiting prevents overwhelming third-party APIs. No semaphore for Anthropic (they handle their own rate limiting).

# proxy.py:207-209
MAX_CONCURRENT_REQUESTS = int(os.getenv("MAX_CONCURRENT_REQUESTS", "5"))
haiku_semaphore = asyncio.Semaphore(MAX_CONCURRENT_REQUESTS)
opus_semaphore = asyncio.Semaphore(MAX_CONCURRENT_REQUESTS)
sonnet_semaphore = asyncio.Semaphore(MAX_CONCURRENT_REQUESTS)

WP-10: proxy-toggle Enable/Disable

The proxy-toggle script manages .zshenv entries and a flag file atomically.

~/.claude/bin/proxy-toggle enable    # Adds env vars, creates flag file, checks health
~/.claude/bin/proxy-toggle disable   # Removes env vars, removes flag file
~/.claude/bin/proxy-toggle status    # Shows routing flag, proxy process, .zshenv state

Important: Claude Code must be restarted after toggling because ANTHROPIC_BASE_URL is read at startup.

WP-11: Health Endpoint

The /health endpoint returns provider configuration state for monitoring.

curl -s http://127.0.0.1:8082/health | jq .

WP-12: Go Proxy with Retry

Go proxy with built-in retry using cenkalti/backoff/v4 (exponential backoff: 500ms -> 1s -> 2s, max 5s elapsed).

import "github.com/cenkalti/backoff/v4"

backoffConfig := backoff.NewExponentialBackOff(
    backoff.WithInitialInterval(500 * time.Millisecond),
    backoff.WithMultiplier(2),
    backoff.WithMaxInterval(2 * time.Second),
    backoff.WithMaxElapsedTime(5 * time.Second),
)
err := backoff.Retry(operation, backoffConfig)

Location: /usr/local/bin/claude-proxy | Environment: ANTHROPIC_BASE_URL=http://127.0.0.1:8082 in .zshenv

WP-13: Launchd Service Configuration

The Go proxy runs as a macOS launchd daemon for auto-restart on crash and boot persistence.

Plist: /Library/LaunchDaemons/com.terryli.claude-proxy.plist

Full plist configuration, commands, verification checklist, and debugging: references/launchd-configuration.md

WP-14: OAuth Token Auto-Refresh

Background goroutine refreshes OAuth tokens every 30 minutes, 5 minutes before expiry. Falls back to Keychain if API refresh fails.

Full implementation and refresh logic: references/oauth-auto-refresh.md


Anti-Patterns Summary

Full details with code examples: references/anti-patterns.md

IDSeverityGotchaFix
CCP-01HIGHANTHROPIC_BASE_URL alone without ANTHROPIC_API_KEYSet ANTHROPIC_API_KEY=proxy-managed
CCP-02HIGHMissing anthropic-beta: oauth-2025-04-20 headerAppend to existing beta headers
CCP-03MEDIUMUsing /api/oauth/claude_cli/create_api_key endpointRequires org:create_api_key scope (users only have user:inference)
CCP-04HIGHLowercase keychain service "claude-code-credentials"Actual name has space: "Claude Code-credentials"
CCP-05MEDIUMReading ~/.claude/.credentials.json as primaryKeychain is SSoT; credential file is stale fallback
CCP-06HIGHHardcoding OAuth tokensTokens expire; read dynamically with cache
CCP-07HIGHUsing gh auth token in proxy/hooksCauses process storms (recursive spawning)
CCP-08HIGHANTHROPIC_API_KEY set in env while having OAuth tokenAuth conflict warning in Claude Code; unset it
CCP-09MEDIUMcache_control param sent to MiniMaxMiniMax doesn't support it; remove from allowedParams
CCP-10MEDIUMSetting ANTHROPIC_API_KEY to real key while proxy runsProxy forwards it to all providers, leaking key
CCP-11MEDIUMNot handling /v1/messages/count_tokensCauses auth failures on preflight requests
CCP-12LOWRunning proxy on 0.0.0.0Bind to 127.0.0.1 for security

TodoWrite Task Templates

Setup, provider addition, diagnostics, and disable templates: references/task-templates.md


Reference Implementation

The working production deployment (Go proxy is primary):

FilePurpose
/usr/local/bin/claude-proxyGo proxy binary (~960 lines)
~/.claude/tools/claude-code-proxy-go/main.goGo proxy source
~/.claude/tools/claude-code-proxy-go/oauth_refresh.goOAuth auto-refresh (80 lines)
~/.claude/tools/claude-code-proxy-go/.envProvider config (chmod 600)
/Library/LaunchDaemons/com.terryli.claude-proxy.plistlaunchd config
~/.zshenvEnvironment (ANTHROPIC_BASE_URL)

Post-Change Checklist

After modifying this skill:

  1. Anti-patterns table matches references/anti-patterns.md
  2. Working patterns verified against proxy.py source
  3. No hardcoded OAuth tokens in examples
  4. Beta header version current (oauth-2025-04-20)
  5. All internal links use relative paths (./references/...)
  6. Link validator passes
  7. Skill validator passes
  8. Append changes to references/evolution-log.md

Troubleshooting

IssueCauseSolution
Claude Code ignores ANTHROPIC_BASE_URLMissing ANTHROPIC_API_KEY (CCP-01)Set ANTHROPIC_API_KEY=proxy-managed in.zshenv
401 Unauthorized from AnthropicMissing anthropic-beta header (CCP-02)Ensure proxy appends oauth-2025-04-20
Keychain read returns emptyWrong service name (CCP-04)Use "Claude Code-credentials" (with space)
Proxy forwards real API keyANTHROPIC_API_KEY set to real key (CCP-10)Use proxy-managed sentinel value
count_tokens auth failureMissing endpoint handler (CCP-11)Proxy must handle /v1/messages/count_tokens
Proxy accessible from networkBound to 0.0.0.0 (CCP-12)Bind to 127.0.0.1 only
Process storms on enablegh auth token in hooks (CCP-07)Never call gh CLI from hooks/credential helpers
MiniMax returns wrong model nameMiniMax quirkCosmetic only; Claude Code handles it
Token expired after 5 minCache TTL (WP-05)Normal behavior; proxy re-reads from Keychain
Auth conflict warning in Claude CodeANTHROPIC_API_KEY set (CCP-08)Unset ANTHROPIC_API_KEY in.zshenv
cache_control.ephemeral.scope errorMiniMax doesn't support cache_control (CCP-09)Remove cache_control from allowedParams

Post-Execution Reflection

After this skill completes, check before closing:

  1. Did the command succeed? — If not, fix the instruction or error table that caused the failure.
  2. Did parameters or output change? — If the underlying tool's interface drifted, update Usage examples and Parameters table to match.
  3. Was a workaround needed? — If you had to improvise (different flags, extra steps), update this SKILL.md so the next invocation doesn't need the same workaround.

Only update if the issue is real and reproducible — not speculative.

平台分布

Codex

32.28%
按下载量换算155

Claude

28.48%
按下载量换算137

Cursor

19.02%
按下载量换算91

Gemini CLI

10.24%
按下载量换算49

安全审计

Gen Agent Trust Hub

未通过

Socket

可疑

Snyk

可疑

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在提醒或未通过项,安装前请自行复核。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills