Use your Claude Max subscription with OpenClaw — automatically refresh OAuth tokens that expire every few hours.
If you want to use your Claude Max subscription (instead of API credits) with OpenClaw, you need OAuth tokens (sk-ant-oat01-*). But these tokens expire every few hours, taking your bot offline.
Symptoms:
- Bot stops responding after a few hours
- Auth errors in logs
- Need to manually re-authenticate repeatedly
A Playwright script that automatically:
- Opens browser to claude.ai OAuth
- Clicks "Authorize" (if already logged in)
- Captures the setup-token from callback
- Pastes it into OpenClaw
Runs every 3 hours via launchd (macOS) or cron (Linux).
# Clone the repo
git clone https://github.com/getmolty/anthropic-token-refresh.git
cd anthropic-token-refresh
# Install dependencies
npm init -y
npm install playwright
npx playwright install chromium
# Edit the script to set your paths
nano refresh-anthropic-token.mjs
# Update OPENCLAW_CLI and USER_DATA_DIR for your setup
# Test it (browser will open - log in if needed)
node refresh-anthropic-token.mjs
# Install the launchd job
cp com.openclaw.token-refresh.plist ~/Library/LaunchAgents/
sed -i '' "s/YOUR_USERNAME/$(whoami)/g" ~/Library/LaunchAgents/com.openclaw.token-refresh.plist
sed -i '' "s|/Users/YOUR_USERNAME/scripts|$(pwd)|g" ~/Library/LaunchAgents/com.openclaw.token-refresh.plist
# Create logs directory and load the job
mkdir -p ~/.openclaw/logs
launchctl load ~/Library/LaunchAgents/com.openclaw.token-refresh.plist
# Verify it's running
launchctl list | grep token-refreshgit clone https://github.com/getmolty/anthropic-token-refresh.git
cd anthropic-token-refresh
npm init -y
npm install playwright
npx playwright install chromiumEdit refresh-anthropic-token.mjs and update these paths:
// Find your OpenClaw CLI path with: which openclaw
const OPENCLAW_CLI = '/path/to/openclaw';
// Where to store browser session (auto-created)
const USER_DATA_DIR = path.join(os.homedir(), '.openclaw/playwright-chrome-data');node refresh-anthropic-token.mjsA browser window opens:
- If already logged into claude.ai → auto-approves
- If not → log in once, session persists for future runs
# Copy the template
cp com.openclaw.token-refresh.plist ~/Library/LaunchAgents/
# Edit it with your paths
nano ~/Library/LaunchAgents/com.openclaw.token-refresh.plistUpdate these values:
/Users/YOUR_USERNAME→ your home directory- Path to
refresh-anthropic-token.mjs - Path to
node(find withwhich node)
# Create logs directory
mkdir -p ~/.openclaw/logs
# Load the job
launchctl load ~/Library/LaunchAgents/com.openclaw.token-refresh.plist
# Verify
launchctl list | grep token-refresh# Edit crontab
crontab -e
# Add this line (runs every 3 hours)
0 */3 * * * cd /path/to/anthropic-token-refresh && /usr/bin/node refresh-anthropic-token.mjs >> ~/.openclaw/logs/token-refresh.log 2>&1- Every 3 hours, the script launches a Chromium browser
- Navigates to claude.ai OAuth with PKCE challenge
- Auto-clicks "Authorize" if session is valid
- Captures the setup-token from the callback URL
- Pipes it into
openclaw models auth paste-token - Browser closes, token is refreshed
The browser session persists in ~/.openclaw/playwright-chrome-data/, so you only need to log in once.
Make sure you're logged into claude.ai:
- Run the script manually:
node refresh-anthropic-token.mjs - Complete the login in the browser window
- Future runs will auto-approve
Check your OpenClaw CLI path:
which openclaw
# Update OPENCLAW_CLI in the script# macOS
tail -f ~/.openclaw/logs/token-refresh.log
# Check launchd status
launchctl list | grep token-refreshnode refresh-anthropic-token.mjs# macOS
launchctl unload ~/Library/LaunchAgents/com.openclaw.token-refresh.plist
rm ~/Library/LaunchAgents/com.openclaw.token-refresh.plist
# Linux
crontab -e # remove the line
# Remove browser session
rm -rf ~/.openclaw/playwright-chrome-data- Node.js >= 18
- macOS or Linux
- OpenClaw CLI installed and configured
- Anthropic Claude subscription
MIT