Skip to main content
This guide will walk you through authenticating and running your first twitter-cli command.

Prerequisites

Before you begin, make sure you have:
  • Installed twitter-cli (see Installation)
  • A Twitter/X account
  • Logged into x.com in one of these browsers: Chrome, Firefox, Edge, or Brave

Authentication Setup

twitter-cli uses browser cookies for authentication. There are two methods:

Your First Command

Let’s fetch your home timeline (β€œFor You” feed):
twitter feed
By default, twitter-cli fetches 50 tweets. You can customize this with the --max flag.

Expected Output

You should see a formatted table of tweets:
πŸ” Getting Twitter cookies...
πŸ“‘ Fetching home timeline (50 tweets)...

βœ… Fetched 50 tweets in 2.3s

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ πŸ“± Twitter β€” 50 tweets                                                   ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

@username β€’ 2h ago
Tweet content appears here...
❀️  42  πŸ”„ 12  πŸ’¬ 8  πŸ‘ 1.2K

...

Essential Commands

Now that you’re authenticated, try these common operations:
View tweets from accounts you follow (chronological order):
twitter feed -t following
See your saved/bookmarked tweets:
twitter favorites
Search for tweets by keyword:
twitter search "Claude Code"
Search with filters:
twitter search "AI agent" -t Latest --max 50
Available filters: Top, Latest, Photos, Videos
Look up any user’s profile:
twitter user elonmusk
View their tweets:
twitter user-posts elonmusk --max 20
Create a new tweet:
twitter post "Hello from twitter-cli!"
Reply to a tweet:
twitter post "This is a reply" --reply-to 1234567890

Export Data as JSON

All read commands support JSON output for scripting and automation:
# Export to stdout
twitter feed --json

# Save to file
twitter feed --json > tweets.json

# Or use the -o flag
twitter search "machine learning" -o ml_tweets.json

Advanced: Filtering Tweets

Filter tweets by engagement score:
twitter feed --filter
This ranks tweets using a weighted score based on:
  • Likes (weight: 1.0)
  • Retweets (weight: 3.0)
  • Replies (weight: 2.0)
  • Bookmarks (weight: 5.0)
  • Views (logarithmic, weight: 0.5)
Customize scoring in config.yaml (see Configuration).

Common Authentication Issues

Error: No Twitter cookies foundSolution:
  1. Make sure you’re logged into x.com in a supported browser
  2. Try closing and reopening your browser
  3. Or set environment variables manually (see Environment Variables tab)
Error: Twitter API error 404This happens when Twitter rotates their GraphQL query IDs.Solution: Simply retry the command. twitter-cli includes fallback logic to fetch fresh query IDs.
Error: Cookie extraction fails on macOSSolution:
  1. Grant Terminal/your terminal app access to Chrome in System Settings
  2. Go to System Settings β†’ Privacy & Security β†’ Full Disk Access
  3. Add your terminal application

Setting Up a Proxy (Optional)

For privacy or to avoid rate limiting, route requests through a proxy:
# HTTP proxy
export TWITTER_PROXY=http://127.0.0.1:7890

# SOCKS5 proxy
export TWITTER_PROXY=socks5://127.0.0.1:1080
Add to your shell config to make it permanent.
Rate Limiting: Using a proxy doesn’t eliminate rate limits, but can help reduce IP-based restrictions. See Best Practices for more tips.

Quick Reference

Here are the most common commands:
# Home timeline (For You)
twitter feed

# Following feed
twitter feed -t following

# With filtering
twitter feed --filter --max 100

Next Steps

Command Reference

Explore all available commands and options

Configuration

Customize behavior with config.yaml

Best Practices

Learn how to avoid bans and rate limits

JSON Export

Export data for scripting and automation

Build docs developers (and LLMs) love