____ _ _ _ _
/ ___|___ __| | ___| | | (_)_ _____
| | / _ \ / _` |/ _ \ |_| | \ \ / / _ \
| |__| (_) | (_| | __/ _ | |\ V / __/
\____\___/ \__,_|\___|_| |_|_| \_/ \___|Claude Code的实时多开发人员协作
查看队友的变化。锁定文件。获取冲突警告。共享终端输出。 Git分支意识。活动时间表。电报通知。Webhook集成。
 ](https://nodejs.org)  
______________________________________________________________________
问题
你和你的队友都在同一个项目上使用Claude Code。但克劳德·科德不知道对方在做什么。您编辑了同一个文件。你们覆盖了彼此的工作。你们在合并冲突上浪费时间。
CodeHive修复了这个问题。
______________________________________________________________________
它的作用
┌─────────────────────────────────────────────────────────────────────────┐
│ │
│ You: "Who's in the room?" │
│ │
│ Claude: Room HIVE-A3K7XY — 3 members: │
│ │
│ Alice (active) [main] │
│ Working on: src/auth.ts, src/middleware.ts │
│ Cursor: src/auth.ts:42:10 │
│ Last seen: 14:32:01 │
│ │
│ Bob (active) [feature/api] │
│ Working on: src/api/routes.ts │
│ Last seen: 14:32:05 │
│ │
│ Charlie (idle) │
│ Working on: none declared │
│ Last seen: 14:28:12 │
│ │
│ Locked files: │
│ 🔒 src/config.ts (by Alice) │
│ │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ You: "What did my teammates change?" │
│ │
│ Claude: Recent changes: │
│ [14:31:42] Alice changed src/auth.ts (+8 -2) │
│ + export function hashPassword(pwd: string): string { │
│ + return bcrypt.hashSync(pwd, 12); │
│ + } │
│ [14:32:01] Bob changed src/api/routes.ts (+15 -0) │
│ + router.post('/login', validateBody, loginHandler); │
│ │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ [!] CONFLICT WARNING │
│ File "src/auth.ts" is being edited by Alice and You. │
│ Coordinate to avoid conflicts. │
│ │
└─────────────────────────────────────────────────────────────────────────┘______________________________________________________________________
运作原理
THE BIG PICTURE
═══════════════════════════════════════════════════════
Dev A (Paris) Dev B (Tokyo)
┌──────────────────┐ ┌──────────────────┐
│ │ │ │
│ Claude Code │ │ Claude Code │
│ ┌──────────┐ │ │ ┌──────────┐ │
│ │ CodeHive │ │ │ │ CodeHive │ │
│ │ MCP │ │ │ │ MCP │ │
│ │ Server │ │ │ │ Server │ │
│ └────┬─────┘ │ │ └────┬─────┘ │
│ │ │ │ │ │
│ ┌────┴─────┐ │ │ ┌────┴─────┐ │
│ │ File │ │ │ │ File │ │
│ │ Watcher │ │ │ │ Watcher │ │
│ └──────────┘ │ │ └──────────┘ │
│ │ │ │
└───────┬──────────┘ └───────┬──────────┘
│ │
│ WebSocket (real-time) │
│ │
└──────────────┐ ┌────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌────────────────┐
│ │ │ Telegram Bot │
│ CodeHive Relay │◄──────►│ (optional) │
│ (server) │ │ Mobile notifs │
│ │ └────────────────┘
│ ┌───────────┐ │
│ │ Rooms │ │ ┌────────────────┐
│ │ HIVE-A3K7 │ │───────►│ Webhooks │
│ │ HIVE-9FMN │ │ │ Slack/Discord │
│ └───────────┘ │ └────────────────┘
│ │
│ ┌───────────┐ │
│ │ Conflict │ │
│ │ Detection │ │
│ └───────────┘ │
│ │
└─────────────────┘
Cloud / Local / VPS______________________________________________________________________
快速开始
1分钟设置(同一网络)
# Both developers run this:
npm install -g codehive && codehive init
# In Claude Code:
# Dev A → "Create a CodeHive room" → gets HIVE-A3K7XY
# Dev B → "Join CodeHive room HIVE-A3K7XY" → connected!远程团队(通过互联网)
# ── ONE-TIME: Deploy a relay server (pick one) ──────────────
# Option A: Fly.io (free)
cd codehive && fly launch --name my-relay && fly deploy
# Option B: Docker
docker run -d -p 4819:4819 ghcr.io/CodeHiveAPP/codehive-relay
# Option C: Any VPS
npm install -g codehive && codehive relay --public
# ── EVERY DEVELOPER ─────────────────────────────────────────
npm install -g codehive
codehive init --relay ws://my-relay.fly.dev:4819
# ── IN CLAUDE CODE ──────────────────────────────────────────
# Dev A → "Create a CodeHive room" → HIVE-A3K7XY
# Dev B → "Join CodeHive room HIVE-A3K7XY" → connected!在任何现有项目上工作
cd my-react-app # or Python, Rust, Go, Java, anything
codehive init # adds .mcp.json (60 bytes), touches nothing else______________________________________________________________________
特性
14个MCP工具+2个实时资源
这些是您的AI编辑器(Claude Code、Cursor、Windsurf、VS Code+Copilot)可以调用的工具:
| 工具 | 参数 | 功能 |
|---|---|---|
create_room | password?, is_public?, expires_in_hours? | 创建一个具有可选密码、公共可见性和自动过期的房间 |
join_room | code, password? | 使用以下代码加入一个房间 HIVE-A3K7XY |
leave_room | -- | 离开当前房间并停止查看文件 |
get_team_status | -- | 查看成员、git分支、光标位置、键入状态、工作文件、锁 |
get_recent_changes | -- | 使用逐行差异查看队友的文件更改 |
send_message | message | 向房间里的所有队友发送聊天消息 |
declare_working | files (逗号分隔) | 声明您正在编辑的文件——如果其他人触摸了它们,会触发冲突警报 |
get_notifications | -- | 检查未读:文件更改、聊天消息、冲突警告、锁定事件、分支警告 |
lock_file | file | 锁定一个文件,这样只有你可以编辑它——队友被阻止修改它 |
unlock_file | file | 解锁之前锁定的文件,允许队友再次编辑 |
get_timeline | limit? (默认值:30) | 按时间顺序查看活动:加入、离开、文件更改、聊天、锁定、冲突 |
share_terminal | command, output, exit_code? | 与队友共享终端输出(测试结果、构建日志) |
browse_rooms | -- | 发现中继服务器上可用的公共房间 |
set_webhook | url, events? | 为房间事件(Slack、Discord或自定义)配置webhook URL |
MCP资源 (实时可订阅数据):
codehive://room/status--实时房间状态(成员、更改、锁定)codehive://notifications--未读通知源
客房特色
密码 --使用密码保护房间。只有拥有密码的人才能加入。
You: "Create a password-protected room with password secret123"
Claude: Room HIVE-A3K7XY created! Password protected: yes
Invite link: codehive://127.0.0.1:4819/join/HIVE-A3K7XY?p=secret123公共房间 --使同一中继上的其他开发人员可以发现房间。
You: "Create a public room"
Claude: Room HIVE-B5N9QR created! Visibility: PUBLIC (discoverable)
# Others can find it:
You: "Browse public CodeHive rooms"
Claude: 2 public room(s) found:
HIVE-B5N9QR — 3 members
Created by: Alice
Members: Alice, Bob, Charlie房间到期 --房间在可配置的不活动时间后自动删除。
You: "Create a room that expires after 24 hours"
Claude: Room HIVE-C7P2KM created! Expires: after 24h of inactivity邀请链接 --创建房间时自动生成。
codehive://127.0.0.1:4819/join/HIVE-A3K7XY
codehive://my-relay.fly.dev:4819/join/HIVE-A3K7XY?p=secret123冲突检测
Dev A declares: "I'm working on auth.ts"
Dev B declares: "I'm working on auth.ts"
│
▼
┌─────────────────────────┐
│ ⚠ CONFLICT WARNING │
│ │
│ File: auth.ts │
│ Edited by: Dev A, Dev B│
│ │
│ Coordinate to avoid │
│ merge conflicts! │
└─────────────────────────┘
(sent to BOTH developers)文件锁定
You: "Lock src/config.ts so nobody else changes it"
Claude: Locked src/config.ts. Only you can edit it now. Use unlock_file when done.
# If a teammate tries to edit it:
# ⚠ File "src/config.ts" is locked by Alice
# When you're done:
You: "Unlock src/config.ts"
Claude: Unlocked src/config.ts. Teammates can now edit it.Git分支意识
自动检测你的git分支,并在队友位于不同分支时发出警告:
Room HIVE-A3K7XY — 2 members:
Alice (active) [main]
Working on: src/auth.ts
Bob (active) [feature/api]
Working on: src/routes.ts
⚠ BRANCH WARNING: Team members are on different branches:
Alice: main, Bob: feature/api. Coordinate before merging.分支每30秒自动刷新一次。
活动时间表
You: "Show me the room timeline"
Activity timeline:
+ [14:20:01] Zeus joined the room
+ [14:21:15] Alice joined the room
~ [14:22:03] Zeus changed src/auth.ts
# [14:23:11] Alice locked src/config.ts
> [14:24:02] Zeus: "Done with auth module"
. [14:25:30] Alice unlocked src/config.ts
! [14:26:00] CONFLICT: src/api.ts edited by Zeus and Alice终端输出共享
You: "Share the test results with the team"
Claude: Shared terminal output: `npm test` (1200 chars)
# Teammates see:
# [Terminal] Alice shared: `npm test` (exit 0)键入指示器和光标共享
查看你的队友实时输入的内容:
Alice is typing in src/auth.ts
Bob's cursor: src/routes.ts:42:10Webhook通知
将房间事件发送到Slack、Discord或任何HTTP端点:
You: "Set a webhook to https://hooks.slack.com/services/xxx"
Claude: Webhook configured: https://hooks.slack.com/services/xxx
Events: all
# Every room event is POSTed as JSON:
{
"event": "file_change",
"room": "HIVE-A3K7XY",
"timestamp": 1706123456789,
"file": "src/auth.ts",
"author": "Alice",
"type": "change"
}支持的webhook事件: all, join, leave, chat, file_change, conflict
实时文件查看
CodeHive会监视您的项目文件,并在您保存时自动通知队友:
- 检测文件的添加、修改和删除
- 计算轻量级差异(仅更改行,不计算完整文件)
- 报告二进制文件大小(图像、字体等)
- 忽略
node_modules,.git,dist,二进制文件,锁定文件 - 每文件去抖动以避免快速保存时出现洪水
团队聊天
You: "Tell the team I'm done with the auth module"
Claude: Message sent to HIVE-A3K7XY: "I'm done with the auth module"
# All teammates see:
# [Chat] Alice: I'm done with the auth module______________________________________________________________________
电报机器人(可选)
监控您的房间,并通过Telegram从您的手机发送命令。 100%可选 --如果你不配置它,一切都是一样的。
设置
# Step 1: Create a bot on Telegram
# → Open Telegram, search for @BotFather
# → Send /newbot, follow the prompts
# → Copy the token (e.g. 123456:ABC-DEF1234...)
# Step 2: Configure the token (pick one method)
# Method A: Environment variable
export CODEHIVE_TELEGRAM_TOKEN="123456:ABC-DEF1234..."
codehive telegram
# Method B: codehive.json
echo '{ "telegramToken": "123456:ABC-DEF1234..." }' > codehive.json
codehive telegram
# Step 3: Send /start to your bot in Telegram
# → The bot will auto-detect your chat电报命令
| 命令 | 它的作用 |
|---|---|
/start | 欢迎信息+命令列表 |
/join HIVE-XXXXXX | 加入房间(无密码) |
/join HIVE-XXXXXX mypassword | 加入受密码保护的房间 |
/leave | 离开当前房间 |
/status | 显示房间成员、分支、锁、工作文件 |
/chat Hello team! | 向所有房间成员发送消息 |
/files | 使用差异显示最近的文件更改 |
/timeline | 显示活动时间线(加入、离开、更改、锁定) |
/locks | 显示当前锁定的文件 |
/help | 列出所有可用命令 |
事件转发到Telegram
当你在房间里时,机器人会向你发送实时通知:
| 事件 | 电报消息示例 |
|---|---|
| 会员加入 | 爱丽丝 加入了房间\[主\] |
| 会员离开 | 鲍勃 离开了房间 |
| 文件已更改 | 爱丽丝 改变 src/auth.ts (+8 -2) |
| 聊天信息 | 鲍勃:“使用API完成” |
| 冲突 | 冲突警告 — src/auth.ts 编辑爱丽丝和鲍勃 |
| 文件已锁定 | 爱丽丝 锁定的 src/config.ts |
| 文件已解锁 | 爱丽丝 解锁 src/config.ts |
| 终端共享 | 爱丽丝 共享终端(退出0): npm test |
| 分支警告 | 分支警告 --Alice:main,Bob:feature/api |
在后台运行
codehive telegram --background # Run as a detached process______________________________________________________________________
CLI参考
codehive init --设置CodeHive
codehive init # Auto-detect editor, start local relay
codehive init --relay ws://host:4819 # Use a remote relay server
codehive init --name "Alice" # Set your display name
codehive init --port 5000 # Custom local relay port
codehive init --global # Install globally (~/.claude.json)
codehive init --editor claude-code # Force a specific editor
codehive init --editor cursor # Supported: claude-code, cursor, windsurf, copilot
codehive init --no-auto-relay # Don't auto-start local relaycodehive relay --中继服务器
codehive relay # Start relay (foreground, localhost:4819)
codehive relay --public # Bind to 0.0.0.0 (accessible from network)
codehive relay --port 5000 # Custom port
codehive relay --host 192.168.1.100 # Custom host
codehive relay --background # Run in background (detached)codehive telegram --电报机器人桥
codehive telegram # Start Telegram bot (foreground)
codehive telegram --background # Run in background (detached)
# Requires CODEHIVE_TELEGRAM_TOKEN env var or telegramToken in codehive.json
# Get a token from @BotFather on Telegram: https://t.me/BotFathercodehive deploy --云部署指南
codehive deploy # Show Fly.io, Docker, and VPS instructionscodehive status --检查配置
codehive status # Show configured editors + relay connectivitycodehive doctor --完整诊断
codehive doctor # Check Node.js version, editors, relay, gitcodehive uninstall --删除CodeHive
codehive uninstall # Remove from all editors (project config)
codehive uninstall --global # Remove from global configs
codehive uninstall --editor cursor # Remove from a specific editor only______________________________________________________________________
适用于所有情况
CodeHive是 语言不可知论 和 框架无关。它监视文件——它不在乎里面有什么。
┌─────────────────────────────────────────────────────────┐
│ Compatible with │
├─────────────────────────────────────────────────────────┤
│ │
│ AI Editors Languages Frameworks │
│ ────────── ────────── ────────── │
│ Claude Code JavaScript React / Next.js │
│ Cursor TypeScript Vue / Nuxt │
│ Windsurf Python Angular │
│ VS Code + Copilot Rust Django / Flask │
│ Go Express / Fastify │
│ Java Spring Boot │
│ C# / .NET Rails / Laravel │
│ Swift / Kotlin Any framework │
│ Any language Any project │
│ │
└─────────────────────────────────────────────────────────┘CodeHive为您的项目添加了什么
your-project/
├── .mcp.json ← CodeHive config (60 bytes, commit this!)
├── codehive.json ← Optional: relay host, dev name, telegram token
├── src/ ← untouched
├── package.json ← untouched
└── ... ← everything untouched______________________________________________________________________
建筑
src/
├── shared/ Shared across all modules
│ ├── types.ts 30+ TypeScript interfaces (fully typed protocol)
│ ├── protocol.ts Message encoding, constants, type guards
│ └── utils.ts Room codes, debounce, diff computation
│
├── relay/ WebSocket relay server
│ ├── room.ts Room class (members, locks, timeline, conflicts)
│ └── server.ts Server (routing, heartbeat, persistence, webhooks)
│
├── mcp/ Claude Code integration
│ ├── client.ts WebSocket client (auto-reconnect, heartbeat, queuing)
│ ├── tools.ts 14 MCP tools + 2 resources
│ └── index.ts MCP server entry point (stdio transport)
│
├── watcher/ File system monitoring
│ └── index.ts chokidar-based watcher with diff computation
│
├── telegram/ Telegram bot bridge (optional)
│ ├── bot.ts TelegramBot class (long polling + relay bridge)
│ ├── api.ts Telegram Bot API wrapper (native fetch, zero deps)
│ ├── formatter.ts HTML message formatting for Telegram
│ └── types.ts Telegram API type definitions
│
├── cli/ Command-line interface
│ └── index.ts All commands (init, relay, telegram, deploy, doctor...)
│
└── index.ts Public API for programmatic usage技术栈
| 组件 | 技术 | 为什么 |
|---|---|---|
| 运行时 | Node.js>=20 | 通用,快速启动,本机获取 |
| 语言 | TypeScript 5.9(严格) | 整个协议的类型安全 |
| MCP SDK | @modelcontextprotocol/SDK 1.26 | 官方克劳德代码集成 |
| WebSocket | ws 8.19 | 经过实战测试,零依赖 |
| 文件观看 | chokidar 4 | 跨平台,高性能 |
| CLI | commander 14 | 行业标准 |
| 验证 | zod 3.25 | MCP工具的模式验证 |
| Telegram | Native fetch() | 零依赖项,Telegram Bot API |
| 构建 | tsup 8.5 | 使用声明文件快速构建ESM |
______________________________________________________________________
部署
Fly.io(免费版)
git clone https://github.com/CodeHiveAPP/codehive.git
cd codehive
fly launch --name my-codehive-relay
fly deploy
# → ws://my-codehive-relay.fly.dev:4819码头工人
docker build -t codehive-relay .
docker run -d -p 4819:4819 --name codehive codehive-relay
# → ws://YOUR_SERVER_IP:4819PM2(任何VPS)
npm install -g codehive pm2
pm2 start codehive -- relay --public
pm2 save
# → ws://YOUR_SERVER_IP:4819______________________________________________________________________
配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
CODEHIVE_RELAY_HOST | 127.0.0.1 | 中继服务器主机 |
CODEHIVE_RELAY_PORT | 4819 | 中继服务器端口 |
CODEHIVE_DEV_NAME | 系统用户名 | 您在房间中的显示名称 |
CODEHIVE_PROJECT | cwd | 项目根路径 |
CODEHIVE_HOST | 127.0.0.1 | 中继绑定主机(服务器端) |
CODEHIVE_PORT | 4819 | 中继绑定端口(服务器端) |
CODEHIVE_TELEGRAM_TOKEN | -- | 电报机器人令牌(来自@BotFather) |
.mcp.json (项目配置--提交这个!)
{
"mcpServers": {
"codehive": {
"command": "codehive-mcp",
"env": {
"CODEHIVE_RELAY_HOST": "my-relay.fly.dev",
"CODEHIVE_RELAY_PORT": "4819",
"CODEHIVE_DEV_NAME": "Alice"
}
}
}
}此文件由自动生成 codehive init提交它——当队友克隆项目时,CodeHive是预先配置的。
codehive.json (可选项目配置)
{
"relayHost": "my-relay.fly.dev",
"relayPort": 4819,
"devName": "Alice",
"telegramToken": "123456:ABC-DEF...",
"telegramChatId": 987654321
}| 字段 | 必填 | 描述 |
|---|---|---|
relayHost | 否 | 中继服务器主机名(覆盖环境变量) |
relayPort | 否 | 中继服务器端口(覆盖env var) |
devName | 否 | 您在房间中的显示名称 |
telegramToken | 否 | 用于移动通知的Telegram机器人令牌 |
telegramChatId | 否 | 电报聊天ID(从第一个开始自动检测 /start 如果省略) |
放在项目根目录中。配置优先级:环境变量>codehive.json>默认值。
______________________________________________________________________
测试
# Run all tests (builds, starts relay, runs all suites)
npm test
# 64 tests total:
# 29 E2E tests — full WebSocket protocol testing
# 13 edge case tests — invalid input, limits, error handling
# 22 Telegram tests — formatter, API wrapper, command parsing______________________________________________________________________
贡献
看 贡献.md 用于开发设置和指南。
许可证
麻省理工学院——见 许可证.
______________________________________________________________________
专为一起发货的开发人员而设计。
