本文记录通过 cc-connect 将微信个人号与 Claude Code Agent 打通的完整操作步骤,包括扫码登录、配置写入、权限限制和启动验证。
准备工作
环境要求
| 条件 | 说明 |
|---|---|
| cc-connect 已安装并可执行 | 无需公网 IP,ilink 由云端提供 |
| Claude Code Agent 已配置 | 指向你的工作目录 |
| 微信手机端 | 用于扫码完成 ilink 登录 |
理解 cc-connect 的工作模型
cc-connect 通过 config.toml 管理多个「项目(project)」,每个项目包含:
- agent:底层执行引擎(如
claudecode),配置工作目录和运行模式 - platforms:消息来源平台(如
feishu、weixin),配置对应的认证信息
微信个人号通道底层使用腾讯 ilink 机器人 HTTP 网关,采用 getUpdates 长轮询 + sendMessage 下发的方式收发消息。
Step 1:查看现有配置
操作前先确认你的 config.toml 路径和现有结构。以下是一个已配置飞书平台的典型示例:
language = "zh"
[log]
level = "info"
[[projects]]
name = "justgotrip"
[projects.agent]
type = "claudecode"
[projects.agent.options]
work_dir = "/Users/terry/Downloads/szjz"
mode = "default"
[[projects.platforms]]
type = "feishu"
[projects.platforms.options]
app_id = "cli_xxxxxxxxxxxx"
app_secret = "xxxxxxxxxxxxxxxxxxxxxxxx"
此时只有飞书平台。目标是新增一个 eutopian 项目,挂载微信平台,并将 Claude Code 指向 /Users/terry/Downloads/code/eutopian。
Step 2:扫码登录,自动写入 Token
微信接入需要通过 ilink 机器人网关获取 Bearer Token。cc-connect 提供了一条命令完成扫码+写入的全流程:
cc-connect weixin setup --project eutopian --config /path/to/config.toml
参数说明:
| 参数 | 作用 |
|---|---|
--project eutopian | 目标项目名;若不存在会自动创建并挂上 weixin 平台 |
--config | 指定 config.toml 路径;不填则使用默认路径 |
执行后终端会:
- 打印 ASCII 二维码(同时输出可复制的 URL)
- 等待你用手机微信扫码并确认登录
- 扫码成功后,自动将
token、base_url、account_id等写回config.toml
扫码成功后,config.toml 会自动追加类似以下内容:
[[projects]]
name = "eutopian"
[projects.agent]
type = "claudecode"
[projects.agent.options]
work_dir = "/Users/terry/.cc-connect" # 注意:此处需要手动修正
mode = "default"
[[projects.platforms]]
type = "weixin"
[projects.platforms.options]
token = "d36404f141ed@im.bot:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
base_url = "https://ilinkai.weixin.qq.com"
account_id = "d36404f141ed@im.bot"
⚠️ 注意:自动写入的
work_dir默认为 cc-connect 自身目录,需要手动修正为你的实际项目路径。
Step 3:修正 work_dir
将 work_dir 改为你希望 Claude Code 实际工作的项目目录:
[projects.agent.options]
work_dir = "/Users/terry/Downloads/code/eutopian" # ✅ 修正后
mode = "default"
直接编辑 config.toml 文件,找到 eutopian 项目下的 work_dir 行并替换即可。
Step 4:配置 allow_from 和 admin_from
启动 cc-connect 后默认不限制任何用户,日志会出现警告:
level=WARN msg="allow_from is not set — all users are permitted."
level=WARN msg="admin_from is not set — privileged commands are blocked."
生产环境强烈建议配置这两个字段。
如何获取你的微信用户 ID
启动 cc-connect 后,用微信给机器人发一条任意消息,日志中会出现:
level=INFO msg="message received" platform=weixin
user=o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat
session=weixin:dm:o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat
user 字段即为你的 ilink 用户 ID,格式为 xxxxx@im.wechat。
写入配置
[projects.platforms.options]
token = "d36404f141ed@im.bot:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
base_url = "https://ilinkai.weixin.qq.com"
account_id = "d36404f141ed@im.bot"
allow_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat" # 限制只允许此用户
admin_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat" # 允许使用管理命令
字段说明:
| 字段 | 说明 |
|---|---|
allow_from | 允许与机器人对话的用户 ID,多个用英文逗号分隔;"*" 表示不限制(不安全) |
admin_from | 允许执行 /shell、/show、/dir、/restart、/upgrade 等特权命令的用户 ID |
Step 5:完整 config.toml 示例
配置完成后,完整的 config.toml 结构如下:
language = "zh"
[log]
level = "info"
# ── 项目一:justgotrip(飞书)──────────────────────────────────
[[projects]]
name = "justgotrip"
[projects.agent]
type = "claudecode"
[projects.agent.options]
work_dir = "/Users/terry/Downloads/szjz"
mode = "default"
[[projects.platforms]]
type = "feishu"
[projects.platforms.options]
app_id = "cli_xxxxxxxxxxxx"
app_secret = "xxxxxxxxxxxxxxxxxxxxxxxx"
# ── 项目二:eutopian(微信)───────────────────────────────────
[[projects]]
name = "eutopian"
[projects.agent]
type = "claudecode"
[projects.agent.options]
work_dir = "/Users/terry/Downloads/code/eutopian"
mode = "default"
[[projects.platforms]]
type = "weixin"
[projects.platforms.options]
token = "d36404f141ed@im.bot:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
base_url = "https://ilinkai.weixin.qq.com"
account_id = "d36404f141ed@im.bot"
allow_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat"
admin_from = "o9cq807tacASJCy5LaJPqx6kbFa4@im.wechat"
Step 6:启动 cc-connect
cc-connect start --config /path/to/config.toml
正常启动日志应包含:
level=INFO msg="platform ready" project=justgotrip platform=feishu
level=INFO msg="engine started" project=justgotrip agent=claudecode platforms=1
level=INFO msg="platform ready" project=eutopian platform=weixin
level=INFO msg="engine started" project=eutopian agent=claudecode platforms=1
level=INFO msg="cc-connect is running" projects=2
两个项目均显示 platform ready 即为成功。
Step 7:触发首次 context_token 关联
微信通道有一个重要的初始化步骤:首次连接时必须先发一条消息触发 context_token 关联,之后才能正常使用 /new、/reset 等指令。
操作步骤:
- cc-connect 启动后,用微信向机器人发任意一条消息(如「你好」)
- 等待机器人回复(首次响应约需 10-15 秒)
- 关联完成后即可正常使用
常见问题 FAQ
Q1:扫码超时或无反应
# 增加超时时间重试
cc-connect weixin setup --project eutopian --timeout 600
检查网络是否能访问 https://ilinkai.weixin.qq.com,也可用 --api-url 指定其他网关地址。
Q2:已有 Token,不想重新扫码
cc-connect weixin bind --project eutopian --token '<你的_Bearer_Token>'
Q3:启动后收不到消息
按顺序排查:
- 确认
allow_from是否包含你的用户 ID - 确认进程已重启(修改配置后需要重启)
- 确认已完成首次 context_token 关联(向机器人发一条消息)
Q4:如何同时运行多个微信账号
在同一项目下添加多个 weixin 平台时,用 account_id 区分:
[[projects.platforms]]
type = "weixin"
[projects.platforms.options]
token = "账号1的token"
account_id = "account_1" # 隔离本地状态目录
[[projects.platforms]]
type = "weixin"
[projects.platforms.options]
token = "账号2的token"
account_id = "account_2"
用 --platform-index 参数指定扫码写入到哪个平台:
cc-connect weixin setup --project eutopian --platform-index 2
Q5:如何排除微信通道(精简编译)
go build -tags no_weixin ./cmd/cc-connect
微信通道能力一览
| 能力 | 支持情况 |
|---|---|
| 文字消息收发 | ✅ |
| 引用消息 | ✅ |
| 语音转写文本(STT) | ✅(需配置语音转写 + ffmpeg) |
| 图片接收(AES-128-ECB 解密) | ✅(需配置 cdn_base_url) |
| 文件接收 | ✅ |
| 视频接收 | ✅ |
| 出站图片发送 | ✅(通过 cc-connect send --image) |
| 出站文件发送 | ✅(通过 cc-connect send --file) |
可选配置项速查
[projects.platforms.options]
token = "" # 必填,Bearer Token
base_url = "https://ilinkai.weixin.qq.com" # 可选,默认同左
cdn_base_url = "https://novac2c.cdn.weixin.qq.com/c2c" # 可选,媒体 CDN
allow_from = "" # 建议填写,限制使用者
admin_from = "" # 建议填写,开启管理命令
account_id = "default" # 多账号时区分状态目录
route_tag = "" # 运营商要求时填写
long_poll_timeout_ms = 35000 # 长轮询超时,默认 35s
proxy = "" # 可选 HTTP 代理
相关资源
- cc-connect 仓库:github.com/chenhg5/cc-connect
- 微信通道文档:
docs/weixin.md - 企业微信通道(不同协议):
docs/wecom.md - 完整配置示例:
config.example.toml
3967

被折叠的 条评论
为什么被折叠?



