anthropic-token-refresh

Automatically refresh Anthropic Claude setup-token before expiration using browser automation. Use when: (1) Setting up auto token refresh for Claude Max/Pro subscription, (2) Token keeps expiring and causing OpenClaw to stop responding, (3) Want to maintain continuous Claude API access without manual intervention.

16 stars

Best use case

anthropic-token-refresh is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Automatically refresh Anthropic Claude setup-token before expiration using browser automation. Use when: (1) Setting up auto token refresh for Claude Max/Pro subscription, (2) Token keeps expiring and causing OpenClaw to stop responding, (3) Want to maintain continuous Claude API access without manual intervention.

Teams using anthropic-token-refresh should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/anthropic-token-refresh/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/data-ai/anthropic-token-refresh/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/anthropic-token-refresh/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How anthropic-token-refresh Compares

Feature / Agentanthropic-token-refreshStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Automatically refresh Anthropic Claude setup-token before expiration using browser automation. Use when: (1) Setting up auto token refresh for Claude Max/Pro subscription, (2) Token keeps expiring and causing OpenClaw to stop responding, (3) Want to maintain continuous Claude API access without manual intervention.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Anthropic Token Auto-Refresh Skill

This skill enables fully automatic refresh of Anthropic Claude setup-token using browser automation, ensuring your OpenClaw never goes offline due to token expiration.

## Problem

Claude `setup-token` (used for Max/Pro subscriptions) expires periodically and requires manual refresh:
1. Run `claude setup-token`
2. Browser opens authorization page
3. Click "Authorize" button
4. Copy verification code
5. Paste into CLI
6. Update OpenClaw config

This skill automates the entire process!

## Solution Overview

```
Daily Check → Token expires in < 30 days?
                    ↓ Yes
         Start `claude setup-token`
                    ↓
         Browser opens auth URL
                    ↓
         Auto-click "Authorize" button
                    ↓
         Extract verification code
                    ↓
         Auto-input code to CLI
                    ↓
         Get new token
                    ↓
         Update auth-profiles.json
                    ↓
         ✅ Token refreshed!
```

## Prerequisites

1. **Claude CLI installed and logged in**
   ```bash
   claude --version
   ```

2. **OpenClaw browser profile logged into Claude**
   - Run: `openclaw browser start --profile openclaw`
   - Navigate to https://claude.ai and log in
   - This is a one-time setup

3. **jq installed** (for JSON processing)
   ```bash
   brew install jq
   ```

## Setup

### Step 1: One-time Browser Login

The OpenClaw browser needs to be logged into Claude (separate from your regular browser):

```bash
# Start OpenClaw browser
openclaw browser start --profile openclaw

# Navigate to Claude login (via OpenClaw or manually)
# Log in with your Claude account
```

### Step 2: Set Up Cron Jobs

Create two scheduled tasks:

**1. Token Refresh Check (Daily)**
```json
{
  "name": "token-refresh-check",
  "schedule": {"kind": "every", "everyMs": 86400000},
  "payload": {
    "kind": "systemEvent",
    "text": "Token refresh check: Check token expiry, if < 30 days remaining, execute auto-refresh flow"
  },
  "sessionTarget": "main"
}
```

**2. Claude Session Keep-Alive (Every 3 Days)**
```json
{
  "name": "claude-session-keepalive",
  "schedule": {"kind": "every", "everyMs": 259200000},
  "payload": {
    "kind": "systemEvent",
    "text": "Claude login keepalive: Visit https://claude.ai in OpenClaw browser to maintain login session"
  },
  "sessionTarget": "main"
}
```

## Auto-Refresh Flow (For Agent)

When triggered, the agent should execute this flow:

### 1. Check Token Expiry
```bash
cat ~/.openclaw/agents/main/agent/auth-profiles.json | jq '.profiles["anthropic:setup-token"].expires'
```

Calculate days remaining:
```bash
EXPIRES=$(cat ~/.openclaw/agents/main/agent/auth-profiles.json | jq -r '.profiles["anthropic:setup-token"].expires')
NOW_MS=$(($(date +%s) * 1000))
DAYS_LEFT=$(( ($EXPIRES - $NOW_MS) / 1000 / 60 / 60 / 24 ))
echo "Days left: $DAYS_LEFT"
```

If `DAYS_LEFT > 30`, skip refresh.

### 2. Start Token Generation
```bash
# Run in PTY mode to capture output
claude setup-token
```

### 3. Extract Auth URL
From the CLI output, extract the authorization URL:
```
https://claude.ai/oauth/authorize?code=true&client_id=...
```

### 4. Browser Automation
```javascript
// Navigate to auth URL
browser.navigate(authUrl, {profile: "openclaw"})

// Wait for page load, take snapshot
browser.snapshot()

// Find and click "Authorize" button (usually ref like "e24")
browser.act({kind: "click", ref: "<authorize-button-ref>"})

// Take snapshot to get verification code
browser.snapshot()
// Code appears in format: "DYPxv9k9MyJ8lIW0G5AWYdbc..."
```

### 5. Input Verification Code
```bash
# Write code to the PTY session
process.write(sessionId, verificationCode + "\n")
```

### 6. Extract New Token
From CLI output, extract token:
```
sk-ant-oat01-XXXXX...
```

### 7. Update Config
```bash
NEW_TOKEN="sk-ant-oat01-..."
EXPIRES=$(($(date +%s) * 1000 + 365 * 24 * 60 * 60 * 1000))

cat ~/.openclaw/agents/main/agent/auth-profiles.json | \
  jq --arg token "$NEW_TOKEN" --argjson expires "$EXPIRES" \
  '.profiles["anthropic:setup-token"].token = $token | .profiles["anthropic:setup-token"].expires = $expires' \
  > /tmp/auth.tmp && mv /tmp/auth.tmp ~/.openclaw/agents/main/agent/auth-profiles.json
```

### 8. Verify
```bash
openclaw models status | grep "anthropic:setup-token"
```

## Session Keep-Alive

To prevent Claude login from expiring in the OpenClaw browser:

```javascript
// Every 3 days, visit Claude
browser.navigate("https://claude.ai", {profile: "openclaw"})
// Wait for page load
browser.snapshot()
// Verify logged in (should see user menu, not login page)
```

## Troubleshooting

### "Login page instead of authorize page"
The OpenClaw browser is not logged into Claude. Log in manually once.

### "Authorize button not found"
Page structure may have changed. Take a snapshot and find the correct button reference.

### "Token refresh failed"
1. Check Claude CLI: `claude --version`
2. Check browser: `openclaw browser status --profile openclaw`
3. Manual refresh: `claude setup-token`

### "Session expired in OpenClaw browser"
Run the keep-alive task more frequently, or log in again.

## Files

### Auth Profile Location
```
~/.openclaw/agents/main/agent/auth-profiles.json
```

### Browser Data Location
```
~/.openclaw/browser/openclaw/user-data/
```

## Security Notes

- Tokens are stored locally in `auth-profiles.json`
- OpenClaw browser profile is isolated from your main browser
- No credentials are sent to third parties
- The refresh process happens entirely on your local machine

Related Skills

seo-content-refresher

16
from diegosouzapw/awesome-omni-skill

Identifies outdated elements in provided content and suggests updates to maintain freshness. Finds statistics, dates, and examples that need updating. Use PROACTIVELY for older content.

refresh-content

16
from diegosouzapw/awesome-omni-skill

Update existing content with fresh information and improvements.

token-saver-75plus

16
from diegosouzapw/awesome-omni-skill

Always-on token optimization + model routing protocol. Auto-classifies requests (T1-T4), routes execution to the cheapest capable model via sessions_spawn, and applies maximum output compression. Target: 75%+ token savings.

internal-comms-anthropic

16
from diegosouzapw/awesome-omni-skill

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal ...

anthropic-xlsx

16
from diegosouzapw/awesome-omni-skill

Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas

anthropic-skill-creator

16
from diegosouzapw/awesome-omni-skill

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

anthropic-prompt-engineer

16
from diegosouzapw/awesome-omni-skill

Master Anthropic's prompt engineering techniques to generate new prompts or improve existing ones using best practices for Claude AI models.

anthropic-pptx

16
from diegosouzapw/awesome-omni-skill

Presentation creation, editing, and analysis. When Claude needs to work with presentations (.pptx files) for: (1) Creating new presentations, (2) Modifying or editing content, (3) Working with layouts, (4) Adding comments or speaker notes, or any other presentation tasks

anthropic-pdf

16
from diegosouzapw/awesome-omni-skill

Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. When Claude needs to fill in a PDF form or programmatically process, generate, or analyze PDF documents at scale.

anthropic-office-xlsx

16
from diegosouzapw/awesome-omni-skill

Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas

anthropic-office-pptx

16
from diegosouzapw/awesome-omni-skill

Presentation creation, editing, and analysis. When Claude needs to work with presentations (.pptx files) for: (1) Creating new presentations, (2) Modifying or editing content, (3) Working with layouts, (4) Adding comments or speaker notes, or any other presentation tasks

anthropic-office-pdf

16
from diegosouzapw/awesome-omni-skill

Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. When Claude needs to fill in a PDF form or programmatically process, generate, or analyze PDF documents at scale.