Search Twitter/X directly from Claude Code CLI using two methods:
- Browser MCP (Recommended) - Uses your logged-in Chrome session, no API needed
- Twitter API (Backup) - Uses official Twitter API with rate limits
┌──────────────────────────────────────────────────────────────────────────────┐
│ CLAUDE CODE CLI │
│ │
│ User: "Search Twitter for $NVDA sentiment" │
│ │ │
│ ┌───────────────┴───────────────┐ │
│ ▼ ▼ │
│ ┌─────────────────────┐ ┌─────────────────────────┐ │
│ │ BROWSER MCP │ │ TWITTER API MCP │ │
│ │ (Recommended) │ │ (Backup/Offline) │ │
│ └─────────────────────┘ └─────────────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────┐ ┌─────────────────────────┐ │
│ │ Chrome Extension │ │ twitter_mcp_server.py │ │
│ │ + Your Login │ │ + Tweepy + Anthropic │ │
│ └─────────────────────┘ └─────────────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────┐ ┌─────────────────────────┐ │
│ │ twitter.com/x.com │ │ Twitter API v2 │ │
│ │ (Full Access) │ │ (Rate Limited) │ │
│ └─────────────────────┘ └─────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────┘
| Feature | Browser MCP | Twitter API |
|---|---|---|
| Cost | Free | Free tier limited, $200/mo for more |
| Rate Limits | None | 1,500 tweets/month (free) |
| Setup | Chrome extension | API keys + Python |
| Auth | Your Twitter login | Bearer token |
| Access | Full Twitter experience | API endpoints only |
| Works offline | No (needs Chrome) | Yes |
This method uses your Chrome browser with the Browser MCP extension. Claude controls your browser to search Twitter using your logged-in session.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Claude Code │────▶│ Browser MCP │────▶│ Chrome Browser │
│ CLI │ │ Extension │ │ (Your Login) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ twitter.com │
│ (Full Access) │
└─────────────────┘
- Go to Browser MCP on Chrome Web Store
- Click "Add to Chrome"
Add to C:\Users\<username>\.claude.json:
{
"mcpServers": {
"browsermcp": {
"command": "npx",
"args": ["@browsermcp/mcp@latest"]
}
}
}- Open Chrome and go to twitter.com
- Log into Twitter/X if not already
- Click the Browser MCP extension icon in toolbar
- Click "Connect"
Close and reopen Claude Code CLI, then verify with /mcp
Search Twitter for $NVDA sentiment
Find latest tweets about AI stocks
Go to twitter.com and search for $TSLA options flow
| Tool | Description |
|---|---|
browser_navigate |
Go to a URL |
browser_snapshot |
Read page content |
browser_click |
Click elements |
browser_type |
Type into fields |
browser_screenshot |
Take screenshot |
This method uses the official Twitter API via a custom MCP server. Useful when you need offline access or want an autonomous sub-agent.
┌─────────────────┐ ┌──────────────────────┐ ┌─────────────────┐
│ Claude Code │────▶│ twitter_mcp_server │────▶│ Twitter API │
│ CLI │ │ (Python + MCP) │ │ (v2 Endpoints) │
└─────────────────┘ └──────────────────────┘ └─────────────────┘
│
▼
┌──────────────────────┐
│ Sub-Agent (Claude) │
│ Autonomous Research │
└──────────────────────┘
Twitter Bearer Token:
- Go to developer.twitter.com
- Create Developer Account → Project → App
- Get Bearer Token from "Keys and Tokens"
Anthropic API Key:
- Go to console.anthropic.com
- Create API key
cd "d:\Claude Agent Twitter"
pip install -r requirements.txtCreate .env file:
TWITTER_BEARER_TOKEN=your_bearer_token_here
ANTHROPIC_API_KEY=your_anthropic_api_key_herepython test_connection.pyAdd to C:\Users\<username>\.claude.json:
{
"mcpServers": {
"twitter-research": {
"type": "stdio",
"command": "python",
"args": ["d:\\Claude Agent Twitter\\twitter_mcp_server.py"]
}
}
}| Tool | Description |
|---|---|
twitter_search |
Direct search query |
twitter_research_agent |
Autonomous multi-search sub-agent |
The twitter_research_agent spawns a specialized Claude instance:
def run_twitter_sub_agent(task: str) -> str:
# 1. Create Claude client with specialized system prompt
client = anthropic.Anthropic()
# 2. Define search tool for sub-agent
tools = [{"name": "search_twitter", ...}]
# 3. Agentic loop - makes multiple searches autonomously
while response.stop_reason == "tool_use":
result = search_twitter(**tool_use.input)
messages.append(tool_result)
# 4. Return comprehensive summary
return response.text| Tier | Price | Tweets/Month |
|---|---|---|
| Free | $0 | 1,500 |
| Basic | $200/mo | 10,000 |
| Pro | $5,000/mo | 1,000,000 |
d:\Claude Agent Twitter\
├── twitter_mcp_server.py # Twitter API MCP server
├── run_agent.py # CLI interface for sub-agent
├── test_connection.py # API connection tester
├── setup.py # Interactive setup helper
├── requirements.txt # Python dependencies
├── .env # API credentials (DO NOT COMMIT)
├── .gitignore # Git ignore rules
├── CLAUDE.md # Claude Code context
└── README.md # This file
| Operator | Example | Description |
|---|---|---|
$TICKER |
$NVDA |
Stock cashtag |
from:user |
from:elonmusk |
From specific user |
to:user |
to:nvidia |
Replies to user |
#hashtag |
#AI |
Hashtag |
"phrase" |
"options flow" |
Exact match |
-word |
-spam |
Exclude word |
lang:xx |
lang:en |
Language filter |
Search Twitter for $NVDA
Navigate to x.com/search?q=$TSLA&f=live
Use twitter_search to find tweets about $SPY
Use twitter_research_agent to research AI stock sentiment
https://x.com/search?q=%24NVDA&f=live # Latest $NVDA
https://x.com/search?q=from%3Aunusual_whales # From user
"No connection to browser extension"
- Click Browser MCP extension icon → Click "Connect"
- Make sure Chrome is open with the extension active
Page not loading
- Check if Chrome is responsive
- Try refreshing the connected tab
"429 Too Many Requests"
- Hit rate limit, wait 15 minutes
"TWITTER_BEARER_TOKEN not set"
- Check
.envfile exists with valid token
MCP server not appearing
- Restart Claude Code CLI
- Run
/mcpto check status - Verify path in
.claude.json
- Never commit
.envfile (contains API keys) - Browser MCP uses your logged-in session - be careful what you automate
- The
.gitignoreexcludes sensitive files
- Browser MCP - Chrome automation
- Anthropic Claude - AI
- Tweepy - Twitter API wrapper
- MCP Protocol - Tool integration