@aistack/claude-code-proxy

中文文档
0.1.2发布于 2025/07/19MITCommonJS零依赖近 30 天下载 2548

A high-performance proxy server that translates Anthropic Claude API requests to LiteLLM format for multi-provider LLM access

原始使用文档
文档目录26 节
  1. Features
  2. Installation
  3. Quick Start
  4. Commands
  5. Available Commands
  6. Global Options
  7. Examples
  8. Usage
  9. Configuration
  10. Configuration Files
  11. Model Format
  12. Response Styles
  13. Model Mapping
  14. Configuration Options
  15. JSON Configuration
  16. Default Behavior
  17. Adding Custom Providers
  18. Platform Support
  19. Troubleshooting
  20. Binary Not Found
  21. Permission Denied
  22. API Key Issues
  23. Development
  24. License
  25. Support
  26. Changelog

@aistack/claude-code-proxy

A high-performance proxy server that translates Anthropic Claude API requests to LiteLLM format, enabling seamless integration with multiple LLM providers including OpenAI, Google Gemini, OpenRouter, and Anthropic.

Features

  • 🚀 Multi-Provider Support: Seamlessly switch between OpenAI, Gemini, OpenRouter, and Anthropic models
  • 🔄 Automatic Format Translation: Converts Anthropic API format to LiteLLM format and back
  • 🎯 Smart Model Mapping: Intelligently maps Claude models to equivalent models from other providers
  • 📡 Streaming Support: Full support for Server-Sent Events (SSE) streaming responses
  • 🛡️ Production Ready: Comprehensive error handling, logging, and graceful shutdown
  • ⚡ High Performance: Built with Go for optimal performance and low resource usage
  • 🔧 Configurable: Flexible configuration via environment variables

Installation

Install globally using npm:

npm install -g @aistack/claude-code-proxy

Quick Start

  1. Initialize configuration:
ccproxy init

This will prompt you to create a configuration file at either:

  • User level: $HOME/.ccproxy/settings.json
  • Project level: ./.ccproxy/settings.json
  1. Edit the configuration file:
{
  "server": {
    "port": 8082,
    "host": "0.0.0.0"
  },
  "providers": {
    "openai": {
      "apiKey": "sk-...",
      "baseURL": "https://api.openai.com/v1",
      "responseStyle": "openai"
    },
    "anthropic": {
      "apiKey": "sk-ant-...",
      "baseURL": "https://api.anthropic.com",
      "responseStyle": "anthropic"
    },
    "gemini": {
      "apiKey": "...",
      "baseURL": "https://generativelanguage.googleapis.com",
      "responseStyle": "openai"
    },
    "openrouter": {
      "apiKey": "sk-or-v1-...",
      "baseURL": "https://openrouter.ai/api/v1",
      "responseStyle": "openai"
    }
  },
  "models": {
    "bigModel": "gpt-4@openai",
    "smallModel": "gpt-4-mini@openai"
  },
  "logging": {
    "level": "info",
    "format": "json"
  }
}
  1. Start the proxy:
# Start proxy server and launch claude CLI (default behavior)
ccproxy

# Or start only the proxy server
ccproxy server

The server will start on http://localhost:8082 (or your configured port).

Commands

Available Commands

  • ccproxy (default) - Start proxy server (if needed) and launch claude CLI
  • ccproxy server - Start only the proxy server
  • ccproxy init - Initialize configuration file interactively
    • --scope user - Create user-level configuration
    • --scope project - Create project-level configuration
  • ccproxy help - Show help message
  • ccproxy version - Show version information

Global Options

  • --debug - Enable debug logging (applies to all commands)
  • --port - Override server port (server command only)

Examples

# Start server and launch claude CLI (default behavior)
ccproxy

# Start with debug logging enabled
ccproxy --debug

# Start only the proxy server
ccproxy server

# Start server on custom port
ccproxy server --port 8080

# Start server with debug logging
ccproxy server --debug

# Initialize configuration interactively
ccproxy init

# Create user-level configuration
ccproxy init --scope user

# Create project-level configuration
ccproxy init --scope project

Usage

Configuration

Configuration Files

The proxy loads configuration from multiple sources in priority order:

  1. Command Line Arguments (highest priority)
    • --port: Override server port
  2. JSON Configuration Files:
    • /etc/ccproxy/managed-settings.json (managed/system-wide)
    • $CWD/.ccproxy/settings.json (project-level)
    • $HOME/.ccproxy/settings.json (user-level)

Model Format

Models are specified in the format modelname@provider:

  • gpt-4@openai
  • claude-3-opus@anthropic
  • gemini-pro@gemini
  • gpt-4@openrouter

Response Styles

Providers can have different response styles:

  • "responseStyle": "anthropic" - Native Anthropic format (no transformation)
  • "responseStyle": "openai" - OpenAI format (requires transformation)

This allows the proxy to skip unnecessary transformations for providers that natively support Anthropic's API format.

Model Mapping

The proxy automatically maps Claude models to configured models:

Claude ModelMapped ToDescription
claude--haiku-smallModelMaps to the configured small model
claude--sonnet-bigModelMaps to the configured big model
Other modelsAs specifiedUses the model@provider format

Configuration Options

JSON Configuration

FieldDescriptionDefault
server.portServer port8082
server.hostServer host0.0.0.0
providers.<name>.apiKeyProvider API key-
providers.<name>.baseURLProvider base URL-
providers.<name>.responseStyleResponse format styleopenai
models.bigModelModel for large requestsgpt-4@openai
models.smallModelModel for small requestsgpt-4-mini@openai
logging.levelLog levelinfo
logging.formatLog formatjson

Default Behavior

When you run ccproxy without arguments, it will:

  1. Check if the proxy server is already running
  2. Start the server if it's not running
  3. Launch the claude CLI with ANTHROPIC_BASE_URL set to the proxy

This means you can use ccproxy as a drop-in replacement for the claude command while automatically getting multi-provider support.

Adding Custom Providers

You can add custom providers with native Anthropic support:

{
  "providers": {
    "custom-llm": {
      "baseURL": "https://your-llm-api.com",
      "apiKey": "your-api-key",
      "responseStyle": "anthropic"
    }
  }
}

Then use it with: custom-model@custom-llm

Platform Support

The CLI is available for the following platforms:

  • macOS (Intel & Apple Silicon)
  • Linux (x64 & ARM64)
  • Windows (x64)

Troubleshooting

Binary Not Found

If you see "Binary not found" error, it means your platform is not supported. Please open an issue with your platform details.

Permission Denied

On Unix systems, if you get a permission error:

sudo npm install -g @aistack/claude-code-proxy

API Key Issues

Ensure your API keys are correctly set in your settings.json file and that they have the necessary permissions.

Development

For development or contributing, visit the GitHub repository.

License

MIT License - see the LICENSE file for details.

Support

Changelog

See CHANGELOG.md for release history.

版本与发布记录

@aistack/claude-code-proxy 共发布 3 个版本,首次发布于 2025/07/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.2latest2025/07/191.3 年前
0.1.12025/07/171.3 年前
0.1.02025/07/171.3 年前

关于 @aistack/claude-code-proxy 的常见问题

@aistack/claude-code-proxy 是什么?

A high-performance proxy server that translates Anthropic Claude API requests to LiteLLM format for multi-provider LLM access

如何安装 @aistack/claude-code-proxy?

在项目目录运行 npm install @aistack/claude-code-proxy,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ccproxy,可以用 npx ccproxy 直接运行。

@aistack/claude-code-proxy 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aistack__claude-code-proxy 是否存在。

@aistack/claude-code-proxy 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aistack/claude-code-proxy 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aistack/claude-code-proxy 可以商用吗?

@aistack/claude-code-proxy 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aistack/claude-code-proxy 的下载量有多少?

根据 npm 官方下载统计,@aistack/claude-code-proxy 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,548 次,日均约 85 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aistack/claude-code-proxy 还在维护吗?

最新版本 0.1.2 发布于 2025/07/19(1.3 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/07/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。