- Environment variables (recommended for CI/CD)
- Browser cookie extraction (recommended for local development)
Authentication Priority
The CLI checks for credentials in this order:- Environment variables (
TWITTER_AUTH_TOKEN+TWITTER_CT0) - Cached cookies from previous browser extraction
- Live browser cookie extraction
twitter_cli/auth.py:254-299
Environment Variables
Set bothTWITTER_AUTH_TOKEN and TWITTER_CT0 to authenticate via environment:
Finding Your Cookies
Open Browser DevTools
Log into x.com and press
F12 to open Developer ToolsCopy Cookie Values
Find and copy:
auth_token— your session authentication tokenct0— CSRF protection token
Browser Cookie Extraction
The CLI automatically extracts cookies from your browser using browser-cookie3.Supported Browsers
- Chrome
- Microsoft Edge
- Firefox
- Brave
twitter_cli/auth.py:132-149
How It Works
Full Cookie Fingerprint
Extracts all Twitter cookies (not just
auth_token + ct0) to mimic real browser behaviorBrowser Extraction Benefits
Browser extraction provides superior anti-detection:- Forwards all Twitter cookies for complete browser fingerprint
- Includes session cookies like
guest_id,personalization_id, etc. - Makes requests indistinguishable from actual browser traffic
twitter_cli/auth.py:1-9
Cookie Verification
After loading cookies, the CLI performs lightweight verification:- Tests cookies against
api.x.com/1.1/account/verify_credentials.json - Only raises on clear auth failures (
401,403) - Tolerates transient errors (
404, network issues) - Auto-invalidates cache and re-extracts on expiration
twitter_cli/auth.py:42-93
Cookie Cache
Extracted cookies are cached locally:- Location:
~/.cache/twitter-cli/cookies.json - TTL: 24 hours
- Permissions:
0600(owner read/write only)
twitter_cli/auth.py:302-351
Invalidate Cache
To force fresh cookie extraction, delete the cache:Troubleshooting
No Twitter cookies found
Cause: Not logged into x.com in any supported browser. Solution:- Log into x.com in Chrome/Edge/Firefox/Brave
- Or set
TWITTER_AUTH_TOKENandTWITTER_CT0manually
Cookie expired or invalid (HTTP 401/403)
Cause: Session expired or token revoked. Solution:- Log out and back into x.com
- Clear
~/.cache/twitter-cli/cookies.json - Retry your command
macOS Keychain Access Denied
Cause: Chrome encrypts cookies using macOS Keychain, which requires authorization. Solution:- Run the CLI from a Terminal with Keychain access
- Grant access when prompted
- Or use environment variables instead
twitter_cli/auth.py:118-124
Security Best Practices
- Use environment variables for CI/CD
- Restrict file permissions on cached cookies (
0600) - Rotate cookies regularly by logging out/in
- Use browser extraction for local development only
- Set up proxy to avoid IP exposure (see Proxy Configuration)
Next Steps
Config File
Configure YAML settings for fetch, filter, and rate limits
Proxy Setup
Route requests through HTTP/SOCKS5 proxy
