Automatically detect and renew expired Claude Code OAuth tokens via heartbeat. 3-tier renewal: refresh token → Chrome browser automation → user alert.
Automatically detect and renew expired Claude Code OAuth tokens during OpenClaw heartbeat cycles. Prevents agent downtime caused by token expiration.
✅ USE this skill when:
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
Claude Code stores OAuth tokens in macOS Keychain under the service name Claude Code-credentials. The token JSON includes:
accessToken — API access token (prefix sk-ant-oat01-)refreshToken — Used for automatic renewal (prefix sk-ant-ort01-)expiresAt — Unix timestamp in millisecondssecurity CLI (Keychain access)View → Developer → Allow JavaScript from Apple Events enabled (for Tier 2)cp skills/claude-oauth-renewal/scripts/check-claude-oauth.sh scripts/check-claude-oauth.sh
chmod +x scripts/check-claude-oauth.sh
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...)
# 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
| Environment Variable | Default | Description |
|---|---|---|
WARN_HOURS | 6 | Hours before expiry to start renewal attempts |
claude auth login manually to establish initial credentialssecurity find-generic-password -s "Claude Code-credentials" -a "$(whoami)" -gView → Developer → Allow JavaScript from Apple Eventsdefaults write com.google.Chrome AppleScriptEnabled -bool true (restart Chrome)json.loads) to handle truncated keychain outputsecurity -w truncates long values, the -g flag is used as fallbackZIP package — ready to use