这是一个强大的Python版Claude Code,具有增强的实时可视化、成本管理和模型上下文协议(MCP)服务器功能。此工具提供了对多种LLM提供商支持的软件开发任务的自然语言接口。
pip install -r requirements.txt
.env文件:# 选择一个或多个提供商
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
# 可选模型选择
OPENAI_MODEL=gpt-4o
ANTHROPIC_MODEL=claude-3-opus-20240229
使用默认提供商(根据可用API密钥确定)运行CLI:
python claude.py chat
指定提供商和模型:
python claude.py chat --provider openai --model gpt-4o
设置预算限制以管理成本:
python claude.py chat --budget 5.00
作为模型上下文协议服务器运行:
python claude.py serve
在开发模式下启动并使用MCP Inspector:
python claude.py serve --dev
配置主机和端口:
python claude.py serve --host 0.0.0.0 --port 8000
指定额外的依赖项:
python claude.py serve --dependencies pandas numpy
从文件加载环境变量:
python claude.py serve --env-file .env
使用Claude作为推理引擎连接到MCP服务器:
python claude.py mcp-client path/to/server.py
指定Claude模型:
python claude.py mcp-client path/to/server.py --model claude-3-5-sonnet-20241022
尝试包含的示例服务器:
# 在终端1中 - 启动服务器
python examples/echo_server.py
# 在终端2中 - 使用客户端连接
python claude.py mcp-client examples/echo_server.py
启动带有同步代理的多代理客户端:
python claude.py mcp-multi-agent path/to/server.py
使用自定义代理配置文件:
python claude.py mcp-multi-agent path/to/server.py --config examples/agents_config.json
示例使用回声服务器:
# 在终端1中 - 启动服务器
python examples/echo_server.py
# 在终端2中 - 启动多代理客户端
python claude.py mcp-multi-agent examples/echo_server.py --config examples/agents_config.json
Claude Code Python版采用模块化架构构建:
/claude_code/
/lib/
/providers/ # LLM提供商实现
/tools/ # 工具实现
/context/ # 上下文管理
/ui/ # UI组件
/monitoring/ # 成本跟踪及指标
/commands/ # CLI命令
/config/ # 配置管理
/util/ # 工具函数
claude.py # 主CLI入口点
mcp_server.py # 模型上下文协议服务器
一旦MCP服务器运行,您可以从Claude Desktop或其他兼容MCP的客户端连接到它:
安装并运行MCP服务器:
python claude.py serve
在浏览器中打开配置页面:
http://localhost:8000
按照说明配置Claude Desktop,包括:
要使用Claude Code连接到任何MCP服务器:
python claude.py mcp-client path/to/server.py
对于复杂的任务,多代理模式允许多个专门代理协作:
python claude.py mcp-multi-agent path/to/server.py --config examples/agents_config.json
/talk Agent_Name message进行直接通信/agents查看所有可用代理/history查看对话历史MIT
该项目受到Anthropic的Claude Code CLI工具的启发,在Python中重新实现,并增加了增强的可见性、成本管理和MCP服务器功能。