@hafez/x-cli

View X (Twitter) posts and their replies right from your terminal
Features
- Thread Context - See parent tweets and full reply chains
- Dual Output - JSON for scripting, pretty-print for humans
- Shell Completions - First-class support for bash, zsh, and fish
- Lightweight - Single dependency (yargs), fast startup
Quick Start
npm install -g @hafez/x-cli
x tweet https://x.com/Google/status/2001322381533409733
x tweet 2001322381533409733
x tweet 2001322381533409733 --pretty
Setup
The CLI uses your browser cookies to access X. One-time setup:
- Log into x.com
- Open DevTools (
F12) → Application → Cookies → x.com
- Copy
auth_token and ct0 values
- Create config:
mkdir -p ~/.config/x-cli
cat > ~/.config/x-cli/cookies.txt << EOF
auth_token=YOUR_AUTH_TOKEN
ct0=YOUR_CT0_TOKEN
EOF
Output Formats
JSON (default)
Perfect for piping to jq or other tools:
{
"mainTweet": {
"id": "1234567890",
"text": "Hello world!",
"author": { "name": "User", "username": "user" },
"metrics": { "likes": 10, "retweets": 5, "replies": 2 }
},
"parentTweets": [],
"replies": [...]
}
Pretty (--pretty)
Human-friendly terminal output:
User @username 2h ago
Hello world!
2 replies 5 retweets 10 likes 1.2K views
--- Replies (2) ---
Reply Author @reply_user 1h ago
Nice post!
Shell Completions
Auto-install for your shell:
x setup
Or install manually:
x completion bash >> ~/.bashrc
mkdir -p ~/.zsh/completions
x completion zsh > ~/.zsh/completions/_x
x completion fish > ~/.config/fish/completions/x.fish
Development
git clone https://github.com/AbdelrahmanHafez/x-cli.git
cd x-cli
npm install
npm run build
npm link
License
MIT