Overview
Authenticate Spacebot with LLM providers via OAuth or API keys. Thespacebot auth command manages login, logout, token refresh, and credential status.
Subcommands
login- Log in via OAuth (opens browser)status- Show current auth statuslogout- Log out (remove credentials)refresh- Refresh the access token
login
Authenticate with Anthropic via OAuth. Opens your browser to complete the login flow.Usage
Options
Use API Console authentication instead of Claude Pro/Max. Choose this if you want to use API credits rather than a Claude subscription.
Examples
Standard login (Claude Pro/Max)
Console login (API credits)
OAuth Flow
- CLI starts local server: Listens on
http://localhost:8919for OAuth callback - Opens browser: Navigates to Anthropic’s OAuth authorization page
- User authorizes: Logs in and grants permissions
- Callback received: Browser redirects to
http://localhost:8919/callbackwith auth code - Token exchange: CLI exchanges code for access token and refresh token
- Credentials saved: Stored encrypted in
~/.spacebot/auth.json
Manual URL
If the browser doesn’t open automatically (e.g., in SSH sessions):- Copy the URL from the CLI output
- Open it in a browser on any device
- Complete the login
- The callback will still reach your local server
status
Show current authentication status and token expiration.Usage
Examples
Valid credentials
Expired credentials
spacebot auth refresh to renew the token.
No credentials
Token Display
Tokens are truncated to the first 20 characters for security. The full tokens are stored inauth.json.
logout
Remove stored OAuth credentials.Usage
Examples
Logout
Already logged out
What Happens
- Deletes
~/.spacebot/auth.json - Does not revoke tokens on Anthropic’s side
- Does not stop the running daemon (you may need to restart)
refresh
Manually refresh the access token using the stored refresh token.Usage
Examples
Successful refresh
No credentials
Refresh failed
spacebot auth login again.
Automatic Refresh
The daemon automatically refreshes tokens when they’re close to expiration. You typically don’t need to run this command manually unless:- You want to test credential validity
- The daemon is not running
- You’re troubleshooting authentication issues
Authentication Modes
Claude Pro/Max (Default)
Uses your Claude subscription credits. Best for:- Personal use
- Development
- Lower-volume production
API Console
Uses pay-as-you-go API credits. Best for:- High-volume production
- Enterprise deployments
- When you need API-specific features
--console flag:
Credential Storage
Credentials are stored in~/.spacebot/auth.json in encrypted format:
- File is created with mode
0600(owner read/write only) - Tokens are encrypted using AES-256-GCM
- Never commit
auth.jsonto version control - Rotate tokens regularly via logout/login
Token Lifetime
| Token Type | Lifetime |
|---|---|
| Access token (Max) | 2 hours |
| Access token (Console) | 30 days |
| Refresh token | 90 days |
Alternative: API Keys
Instead of OAuth, you can configure API keys directly inconfig.toml:
Error Cases
Browser doesn’t open
Port already in use
auth login timeout.
Network error
Related Commands
spacebot start- Start daemon (requires authentication)spacebot status- Check daemon status
Implementation Notes
- The OAuth server runs on
http://localhost:8919 - Uses PKCE (Proof Key for Code Exchange) for enhanced security
- Callback endpoint:
/callback - State parameter prevents CSRF attacks
- Credentials are persisted across daemon restarts