介绍
# claude-connect
**一步连接您的 Claude 订阅到 Clawdbot。**
自动: - ✅ 从钥匙串读取 Claude OAuth 令牌 - ✅ 以正确的 OAuth 格式将其写入 Clawdbot - ✅ 每 2 小时自动刷新(过期前) - ✅ 成功/失败时通知您 - ✅ 与 `clawdbot onboard` 配合使用(修复 OAuth auth-profiles 错误)
---
## 快速开始
**1. 安装技能:** ```bash clawdhub install claude-connect cd ~/clawd/skills/claude-connect ```
**2. 确保 Claude CLI 已登录:** ```bash claude auth # Follow the browser login flow ```
**3. 运行安装程序:** ```bash ./install.sh ```
就这样!令牌将每 2 小时自动刷新。
---
## 功能介绍
### 修复 `clawdbot onboard` OAuth 错误
当您运行 `clawdbot onboard --auth-choice claude-cli` 时,有时它无法正确将 OAuth 令牌写入 `auth-profiles.json`。
该技能: 1. 从 macOS 钥匙串读取 OAuth 令牌(Claude CLI 存储的位置) 2. 以**正确的 OAuth 格式**将其写入 `~/.clawdbot/agents/main/agent/auth-profiles.json`: ```json { "profiles": { "anthropic:claude-cli": { "type": "oauth", "provider": "anthropic", "access": "sk-ant-...", "refresh": "sk-ant-ort...", "expires": 1234567890 } } } ``` 3. 设置自动刷新(通过 launchd 每 2 小时运行一次) 4. 保持您的连接全天候在线
---
## 安装
### 自动(推荐)
```bash cd ~/clawd/skills/claude-connect ./install.sh ```
安装程序将: - ✅ 验证 Claude CLI 已配置 - ✅ 创建配置文件 - ✅ 设置自动刷新任务(launchd) - ✅ 运行首次刷新以进行测试
### 手动
1. 复制示例配置: ```bash cp claude-oauth-refresh-config.example.json claude-oauth-refresh-config.json ```
2. 编辑配置(可选): ```bash nano claude-oauth-refresh-config.json ```
3. 测试刷新: ```bash ./refresh-token.sh --force ```
4. 安装 launchd 任务(可选 - 用于自动刷新): ```bash cp com.clawdbot.claude-oauth-refresher.plist ~/Library/LaunchAgents/ launchctl load ~/Library/LaunchAgents/com.clawdbot.claude-oauth-refresher.plist ```
---
## 配置
编辑 `claude-oauth-refresh-config.json`:
```json { "refresh_buffer_minutes": 30, "log_file": "~/clawd/logs/claude-oauth-refresh.log", "notifications": { "on_success": true, "on_failure": true }, "notification_target": "YOUR_CHAT_ID" } ```
**选项:** - `refresh_buffer_minutes`:当令牌剩余这么多分钟时刷新(默认:30) - `log_file`:记录刷新活动的位置 - `notifications.on_success`:刷新成功时通知(默认:true) - `notifications.on_failure`:失败时通知(默认:true) - `notification_target`:您的 Telegram 聊天 ID(或留空以禁用)
---
## 使用方法
### 手动刷新
```bash # Refresh now (even if not expired) ./refresh-token.sh --force
# Refresh only if needed ./refresh-token.sh ```
### 检查状态
```bash # View recent logs tail ~/clawd/logs/claude-oauth-refresh.log
# Check auth profile cat ~/.clawdbot/agents/main/agent/auth-profiles.json | jq '.profiles."anthropic:claude-cli"'
# Check Clawdbot status clawdbot models status ```
### 禁用通知
询问 Clawdbot: ``` Disable Claude refresh success notifications ```
或编辑配置: ```json { "notifications": { "on_success": false, "on_failure": true } } ```
---
## 工作原理
### 刷新流程
1. **从钥匙串读取:** 从 `Claude Code-credentials` 获取 OAuth 令牌 2. **检查过期时间:** 仅在剩余时间 < 30 分钟时刷新(或使用 `--force`) 3. **调用 OAuth API:** 获取新的访问令牌 + 刷新令牌 4. **更新 auth-profiles.json:** 写入正确的 OAuth 格式 5. **更新钥匙串:** 将新令牌同步回去 6. **重启网关:** 获取新令牌 7. **通知:** 发送成功/失败消息(可选)
### 自动刷新(launchd)
通过 `~/Library/LaunchAgents/com.clawdbot.claude-oauth-refresher.plist` 每 2 小时运行一次
**控制命令:** ```bash # Stop auto-refresh launchctl unload ~/Library/LaunchAgents/com.clawdbot.claude-oauth-refresher.plist
# Start auto-refresh launchctl load ~/Library/LaunchAgents/com.clawdbot.claude-oauth-refresher.plist
# Check if running launchctl list | grep claude ```
---
## 故障排除
### Onboard 后 OAuth 不工作
**症状:** `clawdbot onboard --auth-choice claude-cli` 完成,但 Clawdbot 无法使用令牌
**修复:** ```bash cd ~/clawd/skills/claude-connect ./refresh-token.sh --force ```
这将以正确的 OAuth 格式写入令牌。
### 令牌不断过期
**症状:** 8 小时后认证持续失败
**修复:** 确保 launchd 任务正在运行: ```bash launchctl load ~/Library/LaunchAgents/com.clawdbot.claude-oauth-refresher.plist launchctl list | grep claude ```
### 钥匙串中没有令牌
**症状:** `No 'Claude Code-credentials' entries found`
**修复:** 使用 Claude CLI 登录: ```bash claude auth # Follow browser flow ```
然后再次运行刷新: ```bash ./refresh-token.sh --force ```
---
## 卸载
```bash cd ~/clawd/skills/claude-connect ./uninstall.sh ```
或手动操作: ```bash # Stop auto-refresh launchctl unload ~/Library/LaunchAgents/com.clawdbot.claude-oauth-refresher.plist rm ~/Library/LaunchAgents/com.clawdbot.claude-oauth-refresher.plist
# Remove skill rm -rf ~/clawd/skills/claude-connect ```
---
## 升级
如果您之前安装了旧版本:
```bash cd ~/clawd/skills/claude-connect ./validate-update.sh # Check what changed clawdhub update claude-connect # Update to latest ./install.sh # Re-run installer if needed ```
---
## 另请参阅
- [QUICKSTART.md](QUICKSTART.md) - 60 秒设置指南 - [UPGRADE.md](UPGRADE.md) - 从旧版本升级 - [Clawdbot 文档](https://docs.clawd.bot) - 模型认证
---
**版本:** 1.1.0 **作者:** TunaIssaCoding **许可证:** MIT **仓库:** https://github.com/TunaIssaCoding/claude-connect