/install claude-oauth-renewal
Claude Code OAuth Auto-Renewal
Automatically detect and renew expired Claude Code OAuth tokens during OpenClaw heartbeat cycles. Prevents agent downtime caused by token expiration.
When to Use
✅ USE this skill when:
- Your OpenClaw agent uses Claude Code as the AI provider
- You want uninterrupted agent operation without manual token renewal
- You're running OpenClaw on macOS with Chrome browser
How It Works
3-Tier Renewal Strategy
Heartbeat triggers check-claude-oauth.sh
│
├─ Token healthy (>6h remaining) → silent exit ✓
│
├─ Tier 1: claude auth status (refresh token)
│ ├─ Success → silent exit ✓
│ └─ Fail ↓
│
├─ Tier 2: Browser automation (osascript + Chrome JXA)
│ ├─ Start claude auth login
│ ├─ Auto-click "Authorize" on claude.ai
│ ├─ Extract auth code from callback page
│ ├─ Feed code back to CLI via expect
│ ├─ Success → silent exit ✓
│ └─ Fail ↓
│
└─ Tier 3: Alert user → agent notifies via configured channel
Token Storage
Claude Code stores OAuth tokens in macOS Keychain under the service name Claude Code-credentials. The token JSON includes:
accessToken— API access token (prefixsk-ant-oat01-)refreshToken— Used for automatic renewal (prefixsk-ant-ort01-)expiresAt— Unix timestamp in milliseconds
Prerequisites
- macOS with
securityCLI (Keychain access) - Claude Code installed and previously authenticated
- Google Chrome with
View → Developer → Allow JavaScript from Apple Eventsenabled (for Tier 2) - python3 available in PATH
- expect available (ships with macOS)
Setup
1. Copy the script
cp skills/claude-oauth-renewal/scripts/check-claude-oauth.sh scripts/check-claude-oauth.sh
chmod +x scripts/check-claude-oauth.sh
2. Add to HEARTBEAT.md
Add as the first step in your heartbeat execution:
## Execution Order
0. Run `bash scripts/check-claude-oauth.sh` — if output exists, relay as highest priority alert
1. (your other heartbeat checks...)
3. Test
# Normal check (silent if token healthy)
bash scripts/check-claude-oauth.sh
# Force trigger by setting high threshold
WARN_HOURS=24 bash scripts/check-claude-oauth.sh
Configuration
| Environment Variable | Default | Description |
|---|---|---|
WARN_HOURS |
6 |
Hours before expiry to start renewal attempts |
Troubleshooting
"无法读取 Claude Code token"
- Run
claude auth loginmanually to establish initial credentials - Verify keychain access:
security find-generic-password -s "Claude Code-credentials" -a "$(whoami)" -g
Tier 2 (browser automation) not working
- Enable Chrome JXA:
View → Developer → Allow JavaScript from Apple Events - Or via CLI:
defaults write com.google.Chrome AppleScriptEnabled -bool true(restart Chrome) - Ensure you're logged into claude.ai in Chrome
JSON parsing errors
- The script uses regex extraction (not
json.loads) to handle truncated keychain output - If
security -wtruncates long values, the-gflag is used as fallback
Notes
- Tier 1 (refresh token) handles most cases silently
- Tier 2 (browser) is only needed when refresh token itself expires (typically weeks)
- Tier 3 (alert) is the last resort when no automated renewal is possible
- The script never stores or logs actual token values
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install claude-oauth-renewal - 安装完成后,直接呼叫该 Skill 的名称或使用
/claude-oauth-renewal触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
Claude OAuth Auto-Renewal 是什么?
Automatically detect and renew expired Claude Code OAuth tokens via heartbeat. 3-tier renewal: refresh token → Chrome browser automation → user alert. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 416 次。
如何安装 Claude OAuth Auto-Renewal?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install claude-oauth-renewal」即可一键安装,无需额外配置。
Claude OAuth Auto-Renewal 是免费的吗?
是的,Claude OAuth Auto-Renewal 完全免费(开源免费),可自由下载、安装和使用。
Claude OAuth Auto-Renewal 支持哪些平台?
Claude OAuth Auto-Renewal 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Claude OAuth Auto-Renewal?
由 chenhab03(@chenhab03)开发并维护,当前版本 v1.0.0。