Skip to main content

claude5

claude5 是一个 Python 包和命令行工具:启动 Claude Code 时按需启动本地 API 转发,将 Anthropic Messages API 转为任意 OpenAI-compatible Chat Completions 上游。

项目包名为 claude5,兼容以下三个命令:

claude2
claude5
cc5

三个命令完全等价,都会调用 claude5.cli:main。

特性

  • 使用 claude5、claude2 或 cc5 时才检查/启动本地代理;
  • Claude Code 退出后,由本次命令启动的本地代理也会退出;
  • 首次运行生成 ~/.claude5.json 配置模板;
  • 如果检测到旧的 ~/.claude2.json,会继续兼容读取;
  • 不会自动安装 Claude Code;
  • 文件读写和捕获的外部命令输出统一使用 UTF-8;
  • 不依赖第三方 Python 运行时库。

安装

python -m pip install claude5

安装后会提供三个命令:

claude2 --help
claude5 --help
cc5 --help

配置

首次运行任意命令:

claude5

会创建:

~/.claude5.json

配置模板包含:

{
  "base_url": "https://YOUR_OPENAI_COMPATIBLE_ENDPOINT/v1",
  "api_key": "PASTE_YOUR_API_KEY_HERE",
  "model": "YOUR_MODEL_ID",
  "host": "127.0.0.1",
  "port": 18080
}

需要修改:

  • base_url:OpenAI-compatible 上游地址;
  • api_key:上游 API Key;
  • model:模型名称。

配置文件创建时会尝试设置为 600。建议保存在 WSL Linux 文件系统中,不要提交到 Git。

兼容旧配置

新版本优先使用:

~/.claude5.json

如果该文件不存在但旧文件存在:

~/.claude2.json

程序会继续读取内测阶段的旧配置,不会强制迁移或覆盖旧文件。

用法

三个命令的参数完全相同,例如:

claude5 -p "解释当前项目的目录结构"
claude2 -p "检查这个项目的依赖"
cc5 --show-config
claude5 --show-config

-p/--prompt 现在由 claude5 显式声明并转发给 Claude Code;其他未在 Hub 帮助中列出的参数也会继续原样转发。

工作流程

  1. 读取 ~/.claude5.json,必要时兼容读取 ~/.claude2.json;
  2. 检查 claude 命令是否存在;
  3. 检查本地代理是否已监听;
  4. 没有代理时启动 claude5.proxy;
  5. 将 Claude Code 的 Anthropic 请求转换为 OpenAI-compatible Chat Completions 请求;
  6. 将上游响应转换回 Anthropic Messages 响应;
  7. Claude Code 退出后,仅关闭由本次命令启动的代理。

安全说明

  • 本地代理默认绑定 127.0.0.1;
  • ~/.claude5.json 包含 API Key,应限制文件权限;
  • 不要把 API Key 写进命令行参数、脚本、日志或版本库;
  • 不要把本地代理暴露到公网;
  • claude2 只是兼容命令名,实际加载的是 claude5 包。

Metadata

Release files for claude5 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for claude5 0.1.0
File Size Uploaded
claude5-0.1.0.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for claude5 0.1.0
File Interpreter ABI Platform
claude5-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / claude5-0.1.0.tar.gz

Download URL claude5-0.1.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3e7074ea95055943f0b7f7fd013f59292c64231242b1cc38694a904c9c1b7c2b
BLAKE2b-256 checksum
How to use checksums
3edcaa1421fb616c594ea1cf23a89478bce7ef21c20eb5e6467b54c71d1b0500
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.27.0 CPython/3.12.10 Windows/11

Release files / claude5-0.1.0-py3-none-any.whl

Download URL claude5-0.1.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
862fa056919883db2f8dfc5f68479b1e54071c81f96221977ec2d661c2ca404b
BLAKE2b-256 checksum
How to use checksums
2ed27473bc35c309eec60423c66e5cd5850dab0f71df35897f211a1b74b99f23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.27.0 CPython/3.12.10 Windows/11

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page