[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-dzhng--claude-agent-server":3,"tool-dzhng--claude-agent-server":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":79,"owner_twitter":75,"owner_website":80,"owner_url":81,"languages":82,"stars":91,"forks":92,"last_commit_at":93,"license":79,"difficulty_score":94,"env_os":95,"env_gpu":96,"env_ram":96,"env_deps":97,"category_tags":105,"github_topics":106,"view_count":23,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":113,"updated_at":114,"faqs":115,"releases":116},2779,"dzhng\u002Fclaude-agent-server","claude-agent-server","Run Claude Agent (Claude Code) in a sandbox, control it via websocket","claude-agent-server 是一个专为 Claude Agent（Claude Code）打造的 WebSocket 服务端工具，旨在让开发者能够在安全的沙箱环境中运行并实时控制 AI 代理。它通过将 Claude Agent SDK 封装为 WebSocket 服务，解决了本地运行复杂环境配置困难、安全性难以保障以及无法便捷集成到远程应用中的痛点。\n\n该工具特别适合后端开发者、AI 应用构建者及需要自动化代码执行能力的技术团队使用。其核心亮点在于与 E2B 云沙箱的深度集成：用户只需简单命令即可将服务部署为云端模板，获得一个预装了 Git 和 Bun 的隔离运行环境。通过配套的 TypeScript 客户端库，开发者可以轻松建立双向通信通道，实现消息的实时收发、会话管理及资源自动清理。此外，项目支持灵活的本地调试模式，允许用户在推送到云端前对服务端逻辑进行自定义修改和测试。这种“云端沙箱 + 实时通信”的架构，极大地降低了构建高安全等级 AI 编程助手的门槛，让集成过程更加标准化和高效。","![download-kg285ggv19c87syh8aebykaxk97vs261 (1)](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdzhng_claude-agent-server_readme_032c01c8ee10.png)\n\n# Claude Agent SDK WebSocket Server\n\nA WebSocket server that wraps the Claude Agent SDK, allowing real-time bidirectional communication with Claude through WebSockets. Deploy it as an E2B sandbox and connect via the TypeScript client library.\n\n[Launch tweet \u002F discussion](https:\u002F\u002Fx.com\u002Fdzhng\u002Fstatus\u002F1991154972558581889?s=20)\n\n## Overview\n\n**Typical Workflow:**\n\n1. **Build Your E2B Image** - Deploy the server as an E2B sandbox template using `bun run build:e2b`\n2. **Use the Client Library** - Install `@dzhng\u002Fclaude-agent` in your project and connect to your E2B sandbox\n3. **Modify the Server (Optional)** - If you need custom behavior, edit the server code in `packages\u002Fserver\u002F`\n4. **Test Locally** - Use `bun run start:server` and `bun run test:local` to test your changes before rebuilding\n\n## Quick Start\n\n### 1. Setup Environment\n\nCreate a `.env` file in the root directory:\n\n```bash\ncp .env.example .env\n```\n\nAdd your API keys:\n\n```bash\nANTHROPIC_API_KEY=sk-ant-your-api-key-here\nE2B_API_KEY=e2b_your-api-key-here\n```\n\nInstall dependencies:\n\n```bash\nbun install\n```\n\n### 2. Build Your E2B Image\n\nBuild and deploy the server as an E2B template:\n\n```bash\nbun run build:e2b\n```\n\nThis creates a sandbox template named `claude-agent-server` on E2B. The build process:\n\n- Creates a sandbox based on Bun 1.3\n- Installs git and clones this repository\n- Installs dependencies\n- Configures the server to start automatically on port 3000\n\nThe build may take a few minutes. Once complete, your template is ready to use.\n\n### 3. Use the Client Library\n\nInstall the client library in your project:\n\n```bash\nnpm install @dzhng\u002Fclaude-agent\n# or\nbun add @dzhng\u002Fclaude-agent\n```\n\nConnect to your E2B sandbox:\n\n```typescript\nimport { ClaudeAgentClient } from '@dzhng\u002Fclaude-agent'\n\nconst client = new ClaudeAgentClient({\n  e2bApiKey: process.env.E2B_API_KEY,\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n  template: 'claude-agent-server', \u002F\u002F Your E2B template name\n  debug: true,\n})\n\n\u002F\u002F Start the client (creates E2B sandbox and connects)\nawait client.start()\n\n\u002F\u002F Listen for messages from Claude\nclient.onMessage(message => {\n  if (message.type === 'sdk_message') {\n    console.log('Claude:', message.data)\n  }\n})\n\n\u002F\u002F Send a message to Claude\nclient.send({\n  type: 'user_message',\n  data: {\n    type: 'user',\n    session_id: 'my-session',\n    message: {\n      role: 'user',\n      content: 'Hello, Claude!',\n    },\n  },\n})\n\n\u002F\u002F Clean up when done\nawait client.stop()\n```\n\nThat's it! The client library handles:\n\n- Creating and managing E2B sandboxes\n- WebSocket connection\n- Message serialization\n- Cleanup and resource management\n\n## Modifying the Server\n\nIf you want to customize the server behavior:\n\n### 1. Edit Server Code\n\nThe server code is in `packages\u002Fserver\u002F`:\n\n- `index.ts` - Main server and WebSocket handling\n- `message-handler.ts` - Message processing logic\n- `const.ts` - Configuration constants\n\n### 2. Test Locally\n\nStart the server locally:\n\n```bash\nbun run start:server\n```\n\nIn another terminal, run the test client against localhost:\n\n```bash\nbun run test:local\n```\n\nThis runs `packages\u002Fclient\u002Fexample-client.ts` connected to `localhost:3000` instead of E2B.\n\n### 3. Rebuild E2B Image\n\nOnce you're satisfied with your changes, rebuild the E2B template:\n\n```bash\nbun run build:e2b\n```\n\nYour updated server will be deployed to E2B with the same template name.\n\n## Available Scripts\n\n### `bun run build:e2b`\n\nBuilds and deploys the server as an E2B template. This is the main way to deploy your server to the cloud.\n\n### `bun run test:client`\n\nRuns the example client (`packages\u002Fclient\u002Fexample-client.ts`) connected to an E2B sandbox. Requires both `E2B_API_KEY` and `ANTHROPIC_API_KEY` in your `.env` file.\n\n### `bun run start:server`\n\nStarts the server locally on `http:\u002F\u002Flocalhost:3000`. Use this for local development and testing.\n\n### `bun run test:local`\n\nRuns the example client connected to `localhost:3000`. Use this to test your local server changes before rebuilding the E2B image.\n\n## Client Library API\n\n### Installation\n\n```bash\nnpm install @dzhng\u002Fclaude-agent\n# or\nbun add @dzhng\u002Fclaude-agent\n```\n\n### Constructor Options\n\n```typescript\ninterface ClientOptions {\n  \u002F\u002F Required (unless using environment variables)\n  anthropicApiKey?: string\n\n  \u002F\u002F E2B Configuration (optional if using connectionUrl)\n  e2bApiKey?: string\n  template?: string \u002F\u002F E2B template name, defaults to 'claude-agent-server'\n  timeoutMs?: number \u002F\u002F Sandbox timeout, defaults to 5 minutes\n\n  \u002F\u002F Connection Configuration\n  connectionUrl?: string \u002F\u002F Use this to connect to local\u002Fcustom server instead of E2B\n\n  \u002F\u002F Other Options\n  debug?: boolean \u002F\u002F Enable debug logging\n\n  \u002F\u002F Query Configuration (passed to server)\n  agents?: Record\u003Cstring, AgentDefinition>\n  allowedTools?: string[]\n  systemPrompt?:\n    | string\n    | { type: 'preset'; preset: 'claude_code'; append?: string }\n  model?: string\n}\n```\n\n### Methods\n\n- **`async start()`** - Initialize the client and connect to the server\n- **`send(message: WSInputMessage)`** - Send a message to the agent\n- **`onMessage(handler: (message: WSOutputMessage) => void)`** - Register a message handler (returns unsubscribe function)\n- **`async stop()`** - Disconnect and clean up resources\n\n### Example: Connect to E2B\n\n```typescript\nimport { ClaudeAgentClient } from '@dzhng\u002Fclaude-agent'\n\nconst client = new ClaudeAgentClient({\n  e2bApiKey: process.env.E2B_API_KEY,\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n  template: 'claude-agent-server',\n  debug: true,\n})\n\nawait client.start()\n\nclient.onMessage(message => {\n  if (message.type === 'sdk_message') {\n    console.log('Claude:', message.data)\n  }\n})\n\nclient.send({\n  type: 'user_message',\n  data: {\n    type: 'user',\n    session_id: 'session-1',\n    message: { role: 'user', content: 'Hello' },\n  },\n})\n\nawait client.stop()\n```\n\n### Example: Connect to Local Server\n\n```typescript\nconst client = new ClaudeAgentClient({\n  connectionUrl: 'http:\u002F\u002Flocalhost:3000',\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n})\n\nawait client.start()\n```\n\nFor more details, see [`packages\u002Fclient\u002FREADME.md`](packages\u002Fclient\u002FREADME.md).\n\n## Server API Reference\n\n**Note:** If you're using the `@dzhng\u002Fclaude-agent` library, you don't need to interact with these endpoints directly. The client handles configuration and WebSocket connections for you. This section is for advanced users who want to connect to the server directly or build their own client.\n\nThe server runs on `http:\u002F\u002Flocalhost:3000` (or your E2B sandbox URL) with:\n\n- Config endpoint: `http:\u002F\u002Flocalhost:3000\u002Fconfig`\n- WebSocket endpoint: `ws:\u002F\u002Flocalhost:3000\u002Fws`\n\n### Configuration API\n\n#### POST \u002Fconfig\n\nSet the configuration for the Claude Agent SDK query:\n\n```typescript\ntype QueryConfig = {\n  agents?: Record\u003Cstring, AgentDefinition>\n  allowedTools?: string[]\n  systemPrompt?:\n    | string\n    | {\n        type: 'preset'\n        preset: 'claude_code'\n        append?: string\n      }\n  model?: string\n  anthropicApiKey?: string\n}\n```\n\n**Example:**\n\n```bash\ncurl -X POST http:\u002F\u002Flocalhost:3000\u002Fconfig \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"systemPrompt\": \"You are a helpful assistant.\",\n    \"allowedTools\": [\"read_file\", \"write_file\"],\n    \"anthropicApiKey\": \"sk-ant-...\",\n    \"model\": \"claude-3-5-sonnet-20241022\",\n    \"agents\": {\n      \"myAgent\": {\n        \"name\": \"My Custom Agent\",\n        \"description\": \"A custom agent\"\n      }\n    }\n  }'\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"config\": {\n    \"systemPrompt\": \"You are a helpful assistant.\",\n    \"allowedTools\": [\"read_file\", \"write_file\"],\n    \"agents\": { ... }\n  }\n}\n```\n\n#### GET \u002Fconfig\n\nGet the current configuration:\n\n```bash\ncurl http:\u002F\u002Flocalhost:3000\u002Fconfig\n```\n\n**Response:**\n\n```json\n{\n  \"config\": {\n    \"systemPrompt\": \"You are a helpful assistant.\",\n    \"allowedTools\": [\"read_file\", \"write_file\"]\n  }\n}\n```\n\n### WebSocket API\n\n#### Connecting\n\nConnect to the WebSocket endpoint:\n\n```javascript\nconst ws = new WebSocket('ws:\u002F\u002Flocalhost:3000\u002Fws')\n```\n\n**Note:** The server only accepts **one active connection at a time**. If another client is already connected, new connection attempts will be rejected with an error message.\n\n#### Message Format\n\n**Sending Messages (Client → Server)**\n\n```typescript\ntype WSInputMessage =\n  | {\n      type: 'user_message'\n      data: SDKUserMessage\n    }\n  | {\n      type: 'interrupt'\n    }\n```\n\n**User Message:**\n\nSend a wrapped `SDKUserMessage`:\n\n```json\n{\n  \"type\": \"user_message\",\n  \"data\": {\n    \"type\": \"user\",\n    \"session_id\": \"your-session-id\",\n    \"parent_tool_use_id\": null,\n    \"message\": {\n      \"role\": \"user\",\n      \"content\": \"Hello, Claude!\"\n    }\n  }\n}\n```\n\n**Structure:**\n\n- `type`: Must be `\"user_message\"`\n- `data`: An `SDKUserMessage` object containing:\n  - `type`: Must be `\"user\"`\n  - `session_id`: Your session identifier (string)\n  - `message`: An object with `role` and `content`\n    - `role`: Must be `\"user\"`\n    - `content`: The message content (string)\n  - `parent_tool_use_id`: Optional, for tool use responses\n  - `uuid`: Optional, message UUID (auto-generated if not provided)\n\n**Interrupt Message:**\n\nSend an interrupt to stop the current agent operation:\n\n```json\n{\n  \"type\": \"interrupt\"\n}\n```\n\n**Receiving Messages (Server → Client)**\n\n```typescript\ntype WSOutputMessage =\n  | { type: 'connected' }\n  | { type: 'sdk_message'; data: unknown }\n  | { type: 'error'; error: string }\n```\n\nConnection confirmation:\n\n```json\n{\n  \"type\": \"connected\"\n}\n```\n\nSDK messages (responses from Claude):\n\n```json\n{\n  \"type\": \"sdk_message\",\n  \"data\": {\n    \"type\": \"assistant\",\n    \"session_id\": \"...\",\n    \"message\": {\n      \u002F* Claude's response *\u002F\n    }\n  }\n}\n```\n\nError messages:\n\n```json\n{\n  \"type\": \"error\",\n  \"error\": \"Error description\"\n}\n```\n\n## Architecture\n\nThe server is a simple **1-to-1 relay** between a single WebSocket client and the Claude Agent SDK:\n\n1. **Configuration** (optional): Client can POST to `\u002Fconfig` to set agents, allowedTools, and systemPrompt\n2. **Client Connects**: A WebSocket connection is established (only one allowed at a time)\n3. **Client Sends Message**: Client sends a user message (or interrupt)\n4. **Message Queuing**: Server adds messages to the queue and processes them with the SDK\n5. **SDK Processing**: The SDK query stream processes messages using the configured options\n6. **Response Relay**: SDK responses are immediately sent back to the connected WebSocket client\n7. **Cleanup**: When the client disconnects, the server is ready to accept a new connection\n\n**Key Design Principles:**\n\n- **Pre-connection configuration**: Configure query options via `\u002Fconfig` endpoint before connecting\n- **Lazy initialization**: Query stream only starts when first WebSocket connection is made\n- **Single connection only**: Server rejects additional connection attempts while one is active\n- **Simple relay**: Server relays messages between WebSocket and SDK without session management\n- **Message queue**: Incoming messages are queued and processed by the SDK stream\n- **Interrupt support**: Clients can send interrupt messages to stop ongoing operations\n- **Direct routing**: All SDK responses go to the single active WebSocket connection\n\n## Project Structure\n\nThe codebase follows a monorepo structure:\n\n```\nclaude-agent-server\u002F\n├── packages\u002F\n│   ├── server\u002F           # Main server implementation\n│   │   ├── index.ts\n│   │   ├── message-handler.ts\n│   │   └── ...\n│   ├── client\u002F           # Client library and examples\n│   │   ├── src\u002F\n│   │   └── example-client.ts\n│   └── e2b-build\u002F        # E2B build scripts\n│       └── build.prod.ts\n├── package.json          # Root package.json (workspaces)\n└── README.md\n```\n\n## Testing\n\n### Web Test Client\n\nOpen `http:\u002F\u002Flocalhost:3000\u002F` in your browser to access the built-in test client. You can:\n\n- Send messages to Claude\n- See real-time responses\n- View the full JSON structure of SDK messages\n\n### Command Line Test Client\n\nRun the example client script:\n\n```bash\nbun run test:client\n```\n\nThis will connect to the server (or E2B sandbox), send a few test messages, and display the responses.\n\n## E2B Deployment Details\n\nThis section provides additional details about E2B deployment. For the basic setup, see the [Quick Start](#quick-start) section.\n\n### Customizing the Template Name\n\nBy default, `bun run build:e2b` creates a template named `claude-agent-server`. To use a different name, you can modify `packages\u002Fe2b-build\u002Fbuild.prod.ts` or specify it when using the client:\n\n```typescript\nimport { ClaudeAgentClient } from '@dzhng\u002Fclaude-agent'\n\nconst client = new ClaudeAgentClient({\n  template: 'my-custom-template', \u002F\u002F Use your custom template name\n  e2bApiKey: process.env.E2B_API_KEY,\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n})\n\nawait client.start()\n```\n\n### How E2B Sandboxes Work\n\nWhen you use the client library with E2B:\n\n1. **Sandbox Creation**: A fresh sandbox is created from your built template (`claude-agent-server` by default)\n2. **Automatic Startup**: The server starts automatically in the sandbox on port 3000 (configured via `setStartCmd` in `build.prod.ts`)\n3. **Secure Endpoints**: E2B provides HTTPS and WSS endpoints for your sandbox\n4. **Isolation**: Each sandbox runs in complete isolation with its own filesystem and resources\n5. **Automatic Cleanup**: Sandboxes are terminated when the client disconnects\n\nTo test with E2B, simply run:\n\n```bash\nbun run test:client\n```\n\nThis runs `packages\u002Fclient\u002Fexample-client.ts` which creates an E2B sandbox, connects to it, runs test commands, and cleans up.\n\n### E2B Template Configuration\n\nThe template is defined in `packages\u002Fe2b-build\u002Fbuild.prod.ts`:\n\n```typescript\nconst template = Template()\n  .fromBunImage('1.3')                    \u002F\u002F Use Bun 1.3 base image\n  .runCmd('sudo apt install -y git')      \u002F\u002F Install git\n  .gitClone('https:\u002F\u002Fgithub.com\u002F...', ...) \u002F\u002F Clone repository\n  .setWorkdir('\u002Fhome\u002Fuser\u002Fapp')           \u002F\u002F Set working directory\n  .runCmd('bun install')                  \u002F\u002F Install dependencies\n  .setStartCmd('bun packages\u002Fserver\u002Findex.ts', waitForPort(3000)) \u002F\u002F Start server\n```\n\nYou can customize this template to:\n\n- Install additional system packages\n- Pre-configure environment variables\n- Change resource limits (CPU, memory)\n- Modify the startup command\n\n### E2B vs Local Development\n\n**Local Development** (localhost):\n\n- Faster iteration\n- Direct access to local filesystem\n- No sandbox overhead\n- Good for development and testing\n\n**E2B Deployment**:\n\n- Isolated execution environment\n- Secure cloud sandboxes\n- Scalable infrastructure\n- Production-ready\n- No local setup required\n\n## Configuration\n\nThe server uses port 3000 by default. You can modify this in `packages\u002Fserver\u002Findex.ts`:\n\n```typescript\nconst server = Bun.serve\u003CSessionData>({\n  port: 3000, \u002F\u002F Change this\n  \u002F\u002F ...\n})\n```\n\n## Environment Variables\n\nEnvironment variables are loaded from the root `.env` file. See [Quick Start](#quick-start) for setup instructions.\n\n**API Key Priority:**\n\n- If you set `anthropicApiKey` via the Configuration API (`\u002Fconfig` endpoint), it will override the `ANTHROPIC_API_KEY` environment variable.\n- When using the client library, you can pass `anthropicApiKey` in the constructor options.\n\n## License\n\nMIT\n","![download-kg285ggv19c87syh8aebykaxk97vs261 (1)](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdzhng_claude-agent-server_readme_032c01c8ee10.png)\n\n# Claude Agent SDK WebSocket 服务器\n\n一个封装了 Claude Agent SDK 的 WebSocket 服务器，允许通过 WebSocket 与 Claude 进行实时双向通信。您可以将其部署为 E2B 沙盒，并使用 TypeScript 客户端库进行连接。\n\n[发布推文 \u002F 讨论](https:\u002F\u002Fx.com\u002Fdzhng\u002Fstatus\u002F1991154972558581889?s=20)\n\n## 概述\n\n**典型工作流程：**\n\n1. **构建您的 E2B 镜像** - 使用 `bun run build:e2b` 将服务器部署为 E2B 沙盒模板。\n2. **使用客户端库** - 在您的项目中安装 `@dzhng\u002Fclaude-agent`，并连接到您的 E2B 沙盒。\n3. **修改服务器（可选）** - 如果需要自定义行为，请编辑 `packages\u002Fserver\u002F` 中的服务器代码。\n4. **本地测试** - 使用 `bun run start:server` 和 `bun run test:local` 测试您的更改，然后再重新构建。\n\n## 快速入门\n\n### 1. 设置环境\n\n在根目录下创建一个 `.env` 文件：\n\n```bash\ncp .env.example .env\n```\n\n添加您的 API 密钥：\n\n```bash\nANTHROPIC_API_KEY=sk-ant-your-api-key-here\nE2B_API_KEY=e2b_your-api-key-here\n```\n\n安装依赖项：\n\n```bash\nbun install\n```\n\n### 2. 构建您的 E2B 镜像\n\n将服务器构建并部署为 E2B 模板：\n\n```bash\nbun run build:e2b\n```\n\n这会在 E2B 上创建一个名为 `claude-agent-server` 的沙盒模板。构建过程如下：\n\n- 基于 Bun 1.3 创建一个沙盒。\n- 安装 Git 并克隆此仓库。\n- 安装依赖项。\n- 配置服务器在端口 3000 上自动启动。\n\n构建可能需要几分钟时间。完成后，您的模板即可使用。\n\n### 3. 使用客户端库\n\n在您的项目中安装客户端库：\n\n```bash\nnpm install @dzhng\u002Fclaude-agent\n# 或者\nbun add @dzhng\u002Fclaude-agent\n```\n\n连接到您的 E2B 沙盒：\n\n```typescript\nimport { ClaudeAgentClient } from '@dzhng\u002Fclaude-agent'\n\nconst client = new ClaudeAgentClient({\n  e2bApiKey: process.env.E2B_API_KEY,\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n  template: 'claude-agent-server', \u002F\u002F 您的 E2B 模板名称\n  debug: true,\n})\n\n\u002F\u002F 启动客户端（创建 E2B 沙盒并连接）\nawait client.start()\n\n\u002F\u002F 监听来自 Claude 的消息\nclient.onMessage(message => {\n  if (message.type === 'sdk_message') {\n    console.log('Claude:', message.data)\n  }\n})\n\n\u002F\u002F 向 Claude 发送消息\nclient.send({\n  type: 'user_message',\n  data: {\n    type: 'user',\n    session_id: 'my-session',\n    message: {\n      role: 'user',\n      content: '你好，Claude！',\n    },\n  },\n})\n\n\u002F\u002F 完成后清理\nawait client.stop()\n```\n\n就是这样！客户端库负责：\n\n- 创建和管理 E2B 沙盒。\n- WebSocket 连接。\n- 消息序列化。\n- 清理和资源管理。\n\n## 修改服务器\n\n如果您想自定义服务器行为：\n\n### 1. 编辑服务器代码\n\n服务器代码位于 `packages\u002Fserver\u002F` 中：\n\n- `index.ts` - 主服务器和 WebSocket 处理。\n- `message-handler.ts` - 消息处理逻辑。\n- `const.ts` - 配置常量。\n\n### 2. 本地测试\n\n在本地启动服务器：\n\n```bash\nbun run start:server\n```\n\n在另一个终端中，运行针对本地主机的测试客户端：\n\n```bash\nbun run test:local\n```\n\n这会运行 `packages\u002Fclient\u002Fexample-client.ts`，连接到 `localhost:3000` 而不是 E2B。\n\n### 3. 重新构建 E2B 镜像\n\n当您对更改满意后，重新构建 E2B 模板：\n\n```bash\nbun run build:e2b\n```\n\n您更新后的服务器将被部署到 E2B，使用相同的模板名称。\n\n## 可用脚本\n\n### `bun run build:e2b`\n\n将服务器构建并部署为 E2B 模板。这是将服务器部署到云端的主要方式。\n\n### `bun run test:client`\n\n运行示例客户端（`packages\u002Fclient\u002Fexample-client.ts`），连接到 E2B 沙盒。需要在 `.env` 文件中同时设置 `E2B_API_KEY` 和 `ANTHROPIC_API_KEY`。\n\n### `bun run start:server`\n\n在本地 `http:\u002F\u002Flocalhost:3000` 上启动服务器。用于本地开发和测试。\n\n### `bun run test:local`\n\n运行连接到 `localhost:3000` 的示例客户端。在重新构建 E2B 镜像之前，可用于测试本地服务器的更改。\n\n## 客户端库 API\n\n### 安装\n\n```bash\nnpm install @dzhng\u002Fclaude-agent\n# 或者\nbun add @dzhng\u002Fclaude-agent\n```\n\n### 构造函数选项\n\n```typescript\ninterface ClientOptions {\n  \u002F\u002F 必需（除非使用环境变量）\n  anthropicApiKey?: string\n\n  \u002F\u002F E2B 配置（如果使用 connectionUrl 则可选）\n  e2bApiKey?: string\n  template?: string \u002F\u002F E2B 模板名称，默认为 'claude-agent-server'\n  timeoutMs?: number \u002F\u002F 沙盒超时时间，默认为 5 分钟\n\n  \u002F\u002F 连接配置\n  connectionUrl?: string \u002F\u002F 使用此选项连接到本地或自定义服务器，而不是 E2B\n\n  \u002F\u002F 其他选项\n  debug?: boolean \u002F\u002F 启用调试日志\n\n  \u002F\u002F 查询配置（传递给服务器）\n  agents?: Record\u003Cstring, AgentDefinition>\n  allowedTools?: string[]\n  systemPrompt?:\n    | string\n    | { type: 'preset'; preset: 'claude_code'; append?: string }\n  model?: string\n}\n```\n\n### 方法\n\n- **`async start()`** - 初始化客户端并连接到服务器。\n- **`send(message: WSInputMessage)`** - 向代理发送消息。\n- **`onMessage(handler: (message: WSOutputMessage) => void)`** - 注册消息处理器（返回取消注册函数）。\n- **`async stop()`** - 断开连接并清理资源。\n\n### 示例：连接到 E2B\n\n```typescript\nimport { ClaudeAgentClient } from '@dzhng\u002Fclaude-agent'\n\nconst client = new ClaudeAgentClient({\n  e2bApiKey: process.env.E2B_API_KEY,\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n  template: 'claude-agent-server',\n  debug: true,\n})\n\nawait client.start()\n\nclient.onMessage(message => {\n  if (message.type === 'sdk_message') {\n    console.log('Claude:', message.data)\n  }\n})\n\nclient.send({\n  type: 'user_message',\n  data: {\n    type: 'user',\n    session_id: 'session-1',\n    message: { role: 'user', content: '你好' },\n  },\n})\n\nawait client.stop()\n```\n\n### 示例：连接到本地服务器\n\n```typescript\nconst client = new ClaudeAgentClient({\n  connectionUrl: 'http:\u002F\u002Flocalhost:3000',\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n})\n\nawait client.start()\n```\n\n更多详细信息，请参阅 [`packages\u002Fclient\u002FREADME.md`](packages\u002Fclient\u002FREADME.md)。\n\n## 服务器 API 参考\n\n**注意：** 如果您正在使用 `@dzhng\u002Fclaude-agent` 库，则无需直接与这些端点交互。客户端会为您处理配置和 WebSocket 连接。本节适用于希望直接连接到服务器或构建自己的客户端的高级用户。\n\n服务器运行在 `http:\u002F\u002Flocalhost:3000`（或您的 E2B 沙盒 URL）上，提供以下服务：\n\n- 配置端点：`http:\u002F\u002Flocalhost:3000\u002Fconfig`\n- WebSocket 端点：`ws:\u002F\u002Flocalhost:3000\u002Fws`\n\n### 配置 API\n\n#### POST \u002Fconfig\n\n设置 Claude Agent SDK 查询的配置：\n\n```typescript\ntype QueryConfig = {\n  agents?: Record\u003Cstring, AgentDefinition>\n  allowedTools?: string[]\n  systemPrompt?:\n    | string\n    | {\n        type: 'preset'\n        preset: 'claude_code'\n        append?: string\n      }\n  model?: string\n  anthropicApiKey?: string\n}\n```\n\n**示例：**\n\n```bash\ncurl -X POST http:\u002F\u002Flocalhost:3000\u002Fconfig \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"systemPrompt\": \"You are a helpful assistant.\",\n    \"allowedTools\": [\"read_file\", \"write_file\"],\n    \"anthropicApiKey\": \"sk-ant-...\",\n    \"model\": \"claude-3-5-sonnet-20241022\",\n    \"agents\": {\n      \"myAgent\": {\n        \"name\": \"My Custom Agent\",\n        \"description\": \"A custom agent\"\n      }\n    }\n  }'\n```\n\n**响应：**\n\n```json\n{\n  \"success\": true,\n  \"config\": {\n    \"systemPrompt\": \"You are a helpful assistant.\",\n    \"allowedTools\": [\"read_file\", \"write_file\"],\n    \"agents\": { ... }\n  }\n}\n```\n\n#### GET \u002Fconfig\n\n获取当前配置：\n\n```bash\ncurl http:\u002F\u002Flocalhost:3000\u002Fconfig\n```\n\n**响应：**\n\n```json\n{\n  \"config\": {\n    \"systemPrompt\": \"You are a helpful assistant.\",\n    \"allowedTools\": [\"read_file\", \"write_file\"]\n  }\n}\n```\n\n### WebSocket API\n\n#### 连接\n\n连接到 WebSocket 端点：\n\n```javascript\nconst ws = new WebSocket('ws:\u002F\u002Flocalhost:3000\u002Fws')\n```\n\n**注意：** 服务器一次只接受 **一个活动连接**。如果已有其他客户端连接，新的连接尝试将被拒绝，并返回错误消息。\n\n#### 消息格式\n\n**发送消息（客户端 → 服务器）**\n\n```typescript\ntype WSInputMessage =\n  | {\n      type: 'user_message'\n      data: SDKUserMessage\n    }\n  | {\n      type: 'interrupt'\n    }\n```\n\n**用户消息：**\n\n发送封装的 `SDKUserMessage`：\n\n```json\n{\n  \"type\": \"user_message\",\n  \"data\": {\n    \"type\": \"user\",\n    \"session_id\": \"your-session-id\",\n    \"parent_tool_use_id\": null,\n    \"message\": {\n      \"role\": \"user\",\n      \"content\": \"Hello, Claude!\"\n    }\n  }\n}\n```\n\n**结构：**\n\n- `type`：必须为 `\"user_message\"`\n- `data`：包含以下内容的 `SDKUserMessage` 对象：\n  - `type`：必须为 `\"user\"`\n  - `session_id`：您的会话标识符（字符串）\n  - `message`：包含 `role` 和 `content` 的对象\n    - `role`：必须为 `\"user\"`\n    - `content`：消息内容（字符串）\n  - `parent_tool_use_id`：可选，用于工具使用响应\n  - `uuid`：可选，消息 UUID（未提供时自动生成）\n\n**中断消息：**\n\n发送中断以停止当前代理操作：\n\n```json\n{\n  \"type\": \"interrupt\"\n}\n```\n\n**接收消息（服务器 → 客户端）**\n\n```typescript\ntype WSOutputMessage =\n  | { type: 'connected' }\n  | { type: 'sdk_message'; data: unknown }\n  | { type: 'error'; error: string }\n```\n\n连接确认：\n\n```json\n{\n  \"type\": \"connected\"\n}\n```\n\nSDK 消息（来自 Claude 的响应）：\n\n```json\n{\n  \"type\": \"sdk_message\",\n  \"data\": {\n    \"type\": \"assistant\",\n    \"session_id\": \"...\",\n    \"message\": {\n      \u002F* Claude 的响应 *\u002F\n    }\n  }\n}\n```\n\n错误消息：\n\n```json\n{\n  \"type\": \"error\",\n  \"error\": \"Error description\"\n}\n```\n\n## 架构\n\n服务器是一个简单的 **1对1 中继**，用于在单个 WebSocket 客户端和 Claude Agent SDK 之间进行通信：\n\n1. **配置**（可选）：客户端可以通过 POST 到 `\u002Fconfig` 来设置代理、允许的工具和系统提示。\n2. **客户端连接**：建立 WebSocket 连接（一次仅允许一个连接）。\n3. **客户端发送消息**：客户端发送用户消息（或中断消息）。\n4. **消息排队**：服务器将消息加入队列，并使用 SDK 处理它们。\n5. **SDK 处理**：SDK 查询流使用配置选项处理消息。\n6. **响应中继**：SDK 响应会立即发送回已连接的 WebSocket 客户端。\n7. **清理**：当客户端断开连接时，服务器将准备好接受新的连接。\n\n**关键设计原则：**\n\n- **连接前配置**：在连接之前，通过 `\u002Fconfig` 端点配置查询选项。\n- **惰性初始化**：只有在建立第一个 WebSocket 连接时，查询流才会启动。\n- **单连接限制**：服务器会在已有连接时拒绝其他连接尝试。\n- **简单中继**：服务器在 WebSocket 和 SDK 之间中继消息，不进行会话管理。\n- **消息队列**：传入的消息会被排队，并由 SDK 流处理。\n- **中断支持**：客户端可以发送中断消息来停止正在进行的操作。\n- **直接路由**：所有 SDK 响应都会发送到唯一的活动 WebSocket 客户端。\n\n## 项目结构\n\n代码库采用 monorepo 结构：\n\n```\nclaude-agent-server\u002F\n├── packages\u002F\n│   ├── server\u002F           # 主服务器实现\n│   │   ├── index.ts\n│   │   ├── message-handler.ts\n│   │   └── ...\n│   ├── client\u002F           # 客户端库及示例\n│   │   ├── src\u002F\n│   │   └── example-client.ts\n│   └── e2b-build\u002F        # E2B 构建脚本\n│       └── build.prod.ts\n├── package.json          # 根 package.json（工作区）\n└── README.md\n```\n\n## 测试\n\n### Web 测试客户端\n\n在浏览器中打开 `http:\u002F\u002Flocalhost:3000\u002F` 即可访问内置测试客户端。您可以：\n\n- 向 Claude 发送消息\n- 查看实时响应\n- 查看 SDK 消息的完整 JSON 结构\n\n### 命令行测试客户端\n\n运行示例客户端脚本：\n\n```bash\nbun run test:client\n```\n\n这将连接到服务器（或 E2B 沙盒），发送几条测试消息，并显示响应。\n\n## E2B 部署细节\n\n本节提供了有关 E2B 部署的更多详细信息。有关基本设置，请参阅 [快速入门](#quick-start) 部分。\n\n### 自定义模板名称\n\n默认情况下，`bun run build:e2b` 会创建一个名为 `claude-agent-server` 的模板。要使用其他名称，您可以修改 `packages\u002Fe2b-build\u002Fbuild.prod.ts` 文件，或者在使用客户端时指定：\n\n```typescript\nimport { ClaudeAgentClient } from '@dzhng\u002Fclaude-agent'\n\nconst client = new ClaudeAgentClient({\n  template: 'my-custom-template', \u002F\u002F 使用您自定义的模板名称\n  e2bApiKey: process.env.E2B_API_KEY,\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n})\n\nawait client.start()\n```\n\n### E2B 沙盒的工作原理\n\n当您使用带有 E2B 的客户端库时：\n\n1. **沙盒创建**：根据您构建的模板（默认为 `claude-agent-server`）创建一个新的沙盒。\n2. **自动启动**：服务器会在沙盒内的 3000 端口上自动启动（通过 `build.prod.ts` 中的 `setStartCmd` 配置）。\n3. **安全端点**：E2B 为您的沙盒提供 HTTPS 和 WSS 端点。\n4. **隔离**：每个沙盒都在完全隔离的状态下运行，拥有独立的文件系统和资源。\n5. **自动清理**：当客户端断开连接时，沙盒会被终止。\n\n要使用 E2B 进行测试，只需运行：\n\n```bash\nbun run test:client\n```\n\n这将运行 `packages\u002Fclient\u002Fexample-client.ts`，该脚本会创建一个 E2B 沙盒，连接到它，执行测试命令，并进行清理。\n\n### E2B 模板配置\n\n模板在 `packages\u002Fe2b-build\u002Fbuild.prod.ts` 中定义：\n\n```typescript\nconst template = Template()\n  .fromBunImage('1.3')                    \u002F\u002F 使用 Bun 1.3 基础镜像\n  .runCmd('sudo apt install -y git')      \u002F\u002F 安装 git\n  .gitClone('https:\u002F\u002Fgithub.com\u002F...', ...) \u002F\u002F 克隆仓库\n  .setWorkdir('\u002Fhome\u002Fuser\u002Fapp')           \u002F\u002F 设置工作目录\n  .runCmd('bun install')                  \u002F\u002F 安装依赖\n  .setStartCmd('bun packages\u002Fserver\u002Findex.ts', waitForPort(3000)) \u002F\u002F 启动服务器\n```\n\n您可以自定义此模板以：\n\n- 安装额外的系统软件包\n- 预先配置环境变量\n- 更改资源限制（CPU、内存）\n- 修改启动命令\n\n### E2B 与本地开发\n\n**本地开发**（localhost）：\n\n- 迭代更快\n- 可直接访问本地文件系统\n- 无沙箱开销\n- 适合开发和测试\n\n**E2B 部署**：\n\n- 隔离的执行环境\n- 安全的云沙箱\n- 可扩展的基础设施\n- 生产就绪\n- 无需本地设置\n\n## 配置\n\n服务器默认使用 3000 端口。您可以在 `packages\u002Fserver\u002Findex.ts` 中修改：\n\n```typescript\nconst server = Bun.serve\u003CSessionData>({\n  port: 3000, \u002F\u002F 可更改此值\n  \u002F\u002F ...\n})\n```\n\n## 环境变量\n\n环境变量从根目录下的 `.env` 文件加载。请参阅[快速入门](#quick-start)了解设置说明。\n\n**API 密钥优先级：**\n\n- 如果您通过配置 API（`\u002Fconfig` 端点）设置了 `anthropicApiKey`，它将覆盖 `ANTHROPIC_API_KEY` 环境变量。\n- 使用客户端库时，您可以在构造函数选项中传递 `anthropicApiKey`。\n\n## 许可证\n\nMIT","# Claude Agent Server 快速上手指南\n\n`claude-agent-server` 是一个基于 WebSocket 的服务端工具，它封装了 Claude Agent SDK，允许通过 WebSocket 与 Claude 进行实时双向通信。该工具通常部署在 E2B 沙箱环境中，并通过 TypeScript 客户端库进行连接。\n\n## 环境准备\n\n在开始之前，请确保你的开发环境满足以下要求：\n\n*   **操作系统**: Linux, macOS 或 Windows (推荐 WSL2)\n*   **运行时**: [Bun](https:\u002F\u002Fbun.sh\u002F) (版本 1.3 或更高，服务器镜像基于 Bun 1.3 构建)\n*   **API 密钥**:\n    *   [Anthropic API Key](https:\u002F\u002Fconsole.anthropic.com\u002F) (用于调用 Claude 模型)\n    *   [E2B API Key](https:\u002F\u002Fe2b.dev\u002F) (用于部署和管理云端沙箱)\n\n## 安装步骤\n\n### 1. 克隆项目并安装依赖\n\n首先获取源代码并安装必要的依赖包：\n\n```bash\ngit clone \u003Crepository-url>\ncd claude-agent-server\nbun install\n```\n\n### 2. 配置环境变量\n\n在项目根目录创建 `.env` 文件并填入你的 API 密钥：\n\n```bash\ncp .env.example .env\n```\n\n编辑 `.env` 文件，内容如下：\n\n```bash\nANTHROPIC_API_KEY=sk-ant-your-api-key-here\nE2B_API_KEY=e2b_your-api-key-here\n```\n\n### 3. 构建并部署 E2B 镜像\n\n执行以下命令将服务器构建为 E2B 沙箱模板。此过程会自动创建一个基于 Bun 1.3 的沙箱，安装 git，克隆仓库并配置服务在 3000 端口自动启动。\n\n```bash\nbun run build:e2b\n```\n\n*注意：构建过程可能需要几分钟。完成后，名为 `claude-agent-server` 的模板即可在 E2B 上使用。*\n\n## 基本使用\n\n### 1. 在项目中安装客户端库\n\n在你的业务项目中安装官方提供的客户端库：\n\n```bash\nnpm install @dzhng\u002Fclaude-agent\n# 或者使用 bun\nbun add @dzhng\u002Fclaude-agent\n```\n\n### 2. 连接并交互\n\n创建一个 TypeScript 文件（例如 `index.ts`），使用以下代码连接到你刚刚部署的 E2B 沙箱并与 Claude 对话：\n\n```typescript\nimport { ClaudeAgentClient } from '@dzhng\u002Fclaude-agent'\n\nconst client = new ClaudeAgentClient({\n  e2bApiKey: process.env.E2B_API_KEY,\n  anthropicApiKey: process.env.ANTHROPIC_API_KEY,\n  template: 'claude-agent-server', \u002F\u002F 对应构建时生成的模板名称\n  debug: true,\n})\n\n\u002F\u002F 启动客户端（创建沙箱并建立 WebSocket 连接）\nawait client.start()\n\n\u002F\u002F 监听来自 Claude 的消息\nclient.onMessage(message => {\n  if (message.type === 'sdk_message') {\n    console.log('Claude:', message.data)\n  }\n})\n\n\u002F\u002F 发送消息给 Claude\nclient.send({\n  type: 'user_message',\n  data: {\n    type: 'user',\n    session_id: 'my-session',\n    message: {\n      role: 'user',\n      content: 'Hello, Claude!',\n    },\n  },\n})\n\n\u002F\u002F 任务完成后清理资源\nawait client.stop()\n```\n\n### 3. 本地开发测试（可选）\n\n如果你修改了服务端代码 (`packages\u002Fserver\u002F`)，可以在重新部署到 E2B 之前在本地进行测试：\n\n1.  启动本地服务器：\n    ```bash\n    bun run start:server\n    ```\n2.  在另一个终端运行本地测试客户端：\n    ```bash\n    bun run test:local\n    ```\n\n确认无误后，再次运行 `bun run build:e2b` 更新云端模板。","某 SaaS 初创公司的后端团队需要构建一个能自动修复生产环境代码缺陷的智能运维系统，且必须确保 AI 操作在隔离环境中运行以保障数据安全。\n\n### 没有 claude-agent-server 时\n- **安全风险高**：直接让 Claude Code 在本地或普通服务器运行，AI 生成的恶意或错误代码可能误删核心数据库或窃取敏感密钥。\n- **集成复杂度大**：开发者需手动编写复杂的容器编排脚本（如 Docker\u002FK8s）来模拟沙箱，耗时数天且难以维护双向通信逻辑。\n- **状态管理混乱**：缺乏标准化的 WebSocket 接口，前端应用难以实时获取 AI 的思考过程和执行日志，导致调试困难。\n- **资源浪费严重**：每次任务结束后需手动清理临时环境，容易遗留僵尸进程占用服务器资源。\n\n### 使用 claude-agent-server 后\n- **原生沙箱隔离**：通过 E2B 模板一键部署，将 Claude Agent 限制在独立的云端沙箱中，彻底阻断对宿主机文件的非法访问。\n- **极速集成开发**：利用官方 TypeScript 客户端库，仅需几行代码即可建立安全的 WebSocket 连接，将集成时间从数天缩短至几分钟。\n- **实时双向交互**：内置的消息处理机制支持流式传输，前端可实时展示 AI 的修复步骤并动态干预，大幅提升可观测性。\n- **自动化生命周期**：客户端自动管理沙箱的创建、连接与销毁，任务完成后资源即时释放，无需人工介入清理。\n\nclaude-agent-server 通过将复杂的沙箱编排抽象为简单的 WebSocket 服务，让开发者能以最低成本安全地将 Claude 的代码能力嵌入生产级应用。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdzhng_claude-agent-server_032c01c8.jpg","dzhng","David Zhang","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fdzhng_8363bc63.jpg","Co-founder & CEO @ Duet (duet.so)",null,"https:\u002F\u002Fduet.so","https:\u002F\u002Fgithub.com\u002Fdzhng",[83,87],{"name":84,"color":85,"percentage":86},"TypeScript","#3178c6",97.3,{"name":88,"color":89,"percentage":90},"JavaScript","#f1e05a",2.7,554,54,"2026-03-30T09:58:49",4,"Linux, macOS, Windows","未说明",{"notes":98,"python":99,"dependencies":100},"该项目基于 Bun 运行时而非 Python，主要部署在 E2B 沙箱环境中。需要配置 Anthropic API Key 和 E2B API Key。服务器默认运行在 3000 端口，且同一时间仅支持一个 WebSocket 连接。","不需要",[101,102,103,104],"Bun 1.3+","@dzhng\u002Fclaude-agent","E2B SDK","Claude Agent SDK",[13,15,14],[107,108,109,110,111,112],"agent","ai","claude","claude-agent-sdk","claude-agents","claude-code","2026-03-27T02:49:30.150509","2026-04-06T05:36:25.908453",[],[]]