{
  "markdown": "# WeCom Channel 插件 — Claude Code 企业微信通道\n\n一个 [Claude Code Channel](https://code.claude.com/docs/en/channels) 插件，通过 MCP 协议将企业微信消息桥接到 Claude Code 会话中。\n\n从企业微信给 Claude Code 发消息，获取 AI 回复（支持流式输出），还能发送图片和文件让 Claude 分析。\n\n## 功能特性\n\n- **双模式** — 智能机器人（最简配置）或自建应用（完整控制）\n- **流式回复** — 实时显示\"正在思考...\"，打字机效果展示回复\n- **媒体支持** — 从企业微信发送图片和文件，Claude 可以下载并分析\n- **访问控制** — 基于配对码的用户授权\n- **Markdown** — 智能机器人模式支持富文本格式\n\n## 架构\n\n```\n企业微信用户\n    ↓ 发送消息\nWeCom 服务器\n    ↓ HTTPS 回调\n反向代理（nginx）\n    ↓ proxy_pass\n插件 HTTP Server (:8788)\n    ↓ 解密 + 解析\nMCP Server (stdio)\n    ↓ notification\nClaude Code 会话\n    ↓ 调用 reply tool\n企业微信用户 ← 流式回复\n```\n\n## 快速开始\n\n### 前置条件\n\n- [Bun](https://bun.sh) 运行时\n- [Claude Code](https://claude.ai/code) v2.1.80+\n- 企业微信账号（智能机器人或自建应用）\n\n### 1. 克隆并安装\n\n```bash\ngit clone https://github.com/yangsjt/claude-channel-wecom.git\ncd claude-channel-wecom\nnpm install\n```\n\n### 2. 配置凭据\n\n创建 `mcp-dev.json`（已在 .gitignore 中排除）：\n\n```json\n{\n  \"mcpServers\": {\n    \"wecom-channel\": {\n      \"command\": \"bun\",\n      \"args\": [\"run\", \"/绝对路径/claude-channel-wecom/server.ts\"],\n      \"env\": {\n        \"WECOM_MODE\": \"aibot\",\n        \"WECOM_TOKEN\": \"<你的 Token>\",\n        \"WECOM_ENCODING_AES_KEY\": \"<43位密钥>\",\n        \"WECOM_CALLBACK_PORT\": \"8788\"\n      }\n    }\n  }\n}\n```\n\n完整配置项参考 `.env.example`。\n\n### 3. 配置反向代理\n\n企业微信要求 HTTPS 回调 URL。配置 nginx 反向代理到插件：\n\n```nginx\n# 示例：将 /app/cc 转发到插件 HTTP 服务\nlocation /app/cc {\n    proxy_pass         http://<你的机器IP>:8788/callback;\n    proxy_http_version 1.1;\n    proxy_set_header   Host $host;\n    proxy_set_header   X-Real-IP $remote_addr;\n    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_connect_timeout 10s;\n    proxy_read_timeout    60s;\n    proxy_buffering       off;\n    client_max_body_size  5m;\n}\n```\n\n然后在企业微信管理后台设置回调 URL：`https://<你的域名>/app/cc`\n\n### 4. 启动\n\n用 tmux 保持会话后台运行：\n\n```bash\ntmux new -s wecom\n```\n\n选择权限级别：\n\n```bash\n# Level 1: 只读（安全）— 只能读文件、搜索代码\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --allowedTools \"Read Glob Grep\"\n\n# Level 2: 读写（推荐日常）— 可编辑文件、执行 git\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --allowedTools \"Read Glob Grep Edit Write Bash(git:*)\"\n\n# Level 3: 自动模式（高信任）— 大部分操作自动执行\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --permission-mode auto\n\n# Level 4: 全放开（谨慎使用）— 跳过所有权限检查\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --dangerously-skip-permissions\n```\n\n`Ctrl+B D` 脱离 tmux，`tmux attach -t wecom` 重新连接。\n\n### 5. 测试\n\n从企业微信给机器人发一条消息 — Claude Code 应收到消息并自动回复。\n\n## 两种模式对比\n\n| | 智能机器人 (AI Bot) | 自建应用 (Agent) |\n|---|---|---|\n| 配置 | Token + EncodingAESKey | + corpId, corpSecret, agentId |\n| 入站格式 | JSON | XML |\n| 回复方式 | Stream + response_url | Agent REST API |\n| 媒体下载 | 加密 URL 下载 | `/cgi-bin/media/get` |\n| 搭建难度 | 最简 | 需完整凭据 |\n\n## MCP 工具\n\n| 工具 | 说明 |\n|------|------|\n| `reply` | 发送文本/Markdown 回复给企业微信用户 |\n| `download_attachment` | 下载企业微信消息中的图片/文件 |\n| `manage_access` | 管理访问控制：生成配对码、添加/移除用户、切换模式 |\n\n## 访问控制\n\n默认阻止所有用户（`paired` 模式）。授权企业微信用户的流程：\n\n### 配对流程\n\n1. 在运行插件的 Claude Code 会话中输入：\n   ```\n   wecom 配对码\n   ```\n2. Claude 调用 `manage_access` 生成 6 位配对码（15 分钟有效）\n3. 将配对码分享给企业微信用户\n4. 用户在企业微信中发送配对码\n5. 插件返回\"配对成功\"— 用户获得授权\n\n### 快速设置（测试用）\n\n在 Claude Code 中输入：\n```\n把 wecom access 模式设为 open\n```\n\n或直接编辑 `~/.claude/channels/wecom/access.json`：\n```json\n{ \"mode\": \"open\" }\n```\n\n详见 `ACCESS.md`。\n\n## 防火墙注意\n\n如果你的机器有防火墙（如 macOS `pf`），确保端口 `8788` 对反向代理的入站连接开放。\n\n## 许可证\n\nMIT\n\n---\n\n# WeCom Channel Plugin for Claude Code\n\nA [Claude Code Channel](https://code.claude.com/docs/en/channels) plugin that bridges WeCom (Enterprise WeChat / 企业微信) messages into Claude Code sessions via MCP.\n\nSend messages to Claude Code from WeCom, receive AI-powered replies with streaming support, and share images/files — all through your enterprise WeChat.\n\n## Features\n\n- **Dual Mode** — AI Bot (智能机器人) for minimal setup, or Agent (自建应用) for full control\n- **Stream Reply** — Real-time \"thinking...\" indicator with typewriter-effect delivery\n- **Media Support** — Send images and files from WeCom, Claude can download and analyze them\n- **Access Control** — Pairing-based user authorization\n- **Markdown** — Rich text formatting in AI Bot mode replies\n\n## Architecture\n\n```\nWeCom User\n    ↓ sends message\nWeCom Server\n    ↓ HTTPS callback\nReverse Proxy (nginx)\n    ↓ proxy_pass\nPlugin HTTP Server (:8788)\n    ↓ decrypt + parse\nMCP Server (stdio)\n    ↓ notification\nClaude Code Session\n    ↓ calls reply tool\nWeCom User ← stream response\n```\n\n## Quick Start\n\n### Prerequisites\n\n- [Bun](https://bun.sh) runtime\n- [Claude Code](https://claude.ai/code) v2.1.80+\n- A WeCom enterprise account with AI Bot or Self-built App\n\n### 1. Clone and Install\n\n```bash\ngit clone https://github.com/yangsjt/claude-channel-wecom.git\ncd claude-channel-wecom\nnpm install\n```\n\n### 2. Configure Credentials\n\nCreate `mcp-dev.json` (this file is gitignored):\n\n```json\n{\n  \"mcpServers\": {\n    \"wecom-channel\": {\n      \"command\": \"bun\",\n      \"args\": [\"run\", \"/absolute/path/to/claude-channel-wecom/server.ts\"],\n      \"env\": {\n        \"WECOM_MODE\": \"aibot\",\n        \"WECOM_TOKEN\": \"<your-token>\",\n        \"WECOM_ENCODING_AES_KEY\": \"<your-43-char-key>\",\n        \"WECOM_CALLBACK_PORT\": \"8788\"\n      }\n    }\n  }\n}\n```\n\nSee `.env.example` for all available options.\n\n### 3. Set Up Reverse Proxy\n\nWeCom requires an HTTPS callback URL. Configure your reverse proxy (e.g., nginx) to forward to the plugin:\n\n```nginx\n# Example: forward /app/cc to the plugin's HTTP server\nlocation /app/cc {\n    proxy_pass         http://<YOUR_MACHINE_IP>:8788/callback;\n    proxy_http_version 1.1;\n    proxy_set_header   Host $host;\n    proxy_set_header   X-Real-IP $remote_addr;\n    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_connect_timeout 10s;\n    proxy_read_timeout    60s;\n    proxy_buffering       off;\n    client_max_body_size  5m;\n}\n```\n\nThen set the Callback URL in WeCom admin console to `https://<YOUR_DOMAIN>/app/cc`.\n\n### 4. Start\n\nUse tmux to keep the session alive in the background:\n\n```bash\ntmux new -s wecom\n```\n\nThen choose a permission level:\n\n```bash\n# Level 1: Read-only (safe) — Claude can only read files and search code\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --allowedTools \"Read Glob Grep\"\n\n# Level 2: Read-write (recommended) — Claude can edit files and run git\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --allowedTools \"Read Glob Grep Edit Write Bash(git:*)\"\n\n# Level 3: Auto mode (high trust) — Claude auto-executes most operations\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --permission-mode auto\n\n# Level 4: Full access (use with caution) — no permission checks at all\nclaude --mcp-config ./mcp-dev.json \\\n       --dangerously-load-development-channels server:wecom-channel \\\n       --dangerously-skip-permissions\n```\n\nDetach tmux with `Ctrl+B D`, reattach with `tmux attach -t wecom`.\n\n### 5. Test\n\nSend a message from WeCom to your bot — Claude Code should receive it and reply.\n\n## Modes\n\n| | AI Bot (智能机器人) | Agent (自建应用) |\n|---|---|---|\n| Config | Token + EncodingAESKey | + corpId, corpSecret, agentId |\n| Inbound | JSON | XML |\n| Reply | Stream + response_url | Agent REST API |\n| Media | Encrypted URL download | `/cgi-bin/media/get` |\n| Setup | Minimal | Full credentials |\n\n## MCP Tools\n\n| Tool | Description |\n|------|-------------|\n| `reply` | Send text/Markdown reply to the WeCom user |\n| `download_attachment` | Download images/files from WeCom messages |\n| `manage_access` | Manage access control: generate pairing codes, add/remove users, switch mode |\n\n## Access Control\n\nBy default, all users are blocked (`paired` mode). To authorize a WeCom user:\n\n### Pairing Flow\n\n1. In the Claude Code session (where the plugin is running), type:\n   ```\n   wecom 配对码\n   ```\n2. Claude calls `manage_access(action: \"pair\")` and generates a 6-character code (valid 15 min)\n3. Share the code with the WeCom user\n4. The user sends the code as a message in WeCom\n5. Plugin responds with \"配对成功\" — the user is now authorized\n\n### Quick Setup (Testing)\n\nFor testing, you can set open mode in Claude Code:\n```\n把 wecom access 模式设为 open\n```\n\nOr edit `~/.claude/channels/wecom/access.json` directly:\n```json\n{ \"mode\": \"open\" }\n```\n\nSee `ACCESS.md` for full details.\n\n## Firewall Note\n\nIf your machine has a firewall (e.g., macOS `pf`), ensure port `8788` is open for inbound connections from your reverse proxy.\n\n## License\n\nMIT\n",
  "bytes": 8725,
  "sha": "6bd8e929ca46709dbfbd4719a8bd2fa52f3561d4e2164112d8d3031c4b8a81d8",
  "repo_slug": "yangsjt/claude-channel-wecom",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/plg_yangsjt_claude_channel_wecom_wecom_7edba9fb/readme"
}