Last active
January 4, 2026 22:17
-
-
Save matthewevans/a1d8b49a02f56aa2d866cc2044af1990 to your computer and use it in GitHub Desktop.
Gets a long-lived (1yr) Claude Subscription token and stores it for Claude Code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| echo "Setting up Claude credentials..." | |
| # 1. Run claude setup-token | |
| echo "Running claude setup-token..." | |
| claude setup-token | |
| # 2. Ask user for token and wait | |
| read -p "Enter your token: " token | |
| # Validate token | |
| if [[ -z "$token" ]]; then | |
| echo "Error: Token cannot be empty" | |
| exit 1 | |
| fi | |
| # 3. Get epoch of today + 1 year | |
| expiry=$(date -v+1y +%s) | |
| # 4. Create JSON string | |
| credentials_json="{\"claudeAiOauth\":{\"accessToken\":\"$token\",\"refreshToken\":\"$token\",\"expiresAt\":$expiry,\"scopes\":[\"user:inference\"],\"subscriptionType\":\"max\"}}" | |
| # 5. Write to ~/.claude/.credentials | |
| echo "Writing credentials to ~/.claude/.credentials..." | |
| mkdir -p ~/.claude | |
| echo "$credentials_json" > ~/.claude/.credentials | |
| # 6. Update/create keychain item | |
| # Check if keychain is unlocked | |
| echo "Updating macOS keychain..." | |
| if ! security show-keychain-info ~/Library/Keychains/login.keychain-db >/dev/null 2>&1; then | |
| echo "Keychain is locked. You may be prompted for your login password..." | |
| fi | |
| security add-generic-password -U -a "$USER" -s "Claude Code-credentials" -w "$credentials_json" | |
| echo "Setup complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment