Claude Code Twitter/X data: one-line setup
Claude Code can't read X on its own: its WebFetch tool gets HTTP 402 from x.com, so it reads posts through an MCP server or a skill backed by an X data API, and the official X API bills $0.005 per post.
Short answer: Claude Code reads X through a tool you add: an MCP server it calls, or a skill for writing API scripts. On the official X API, both need a developer app and cost $5.00 per 1,000 posts. For Claude Code, add Sorsa API's MCP server in one line: 40 read-only tools, tweets from $0.014 per 1,000, 100 free requests.
claude mcp add sorsa- 40 read-only tools
- Price
- tweets from $0.014 per 1,000
#Can Claude Code read Twitter on its own?
No. Claude Code has no X tool of its own, and its WebFetch tool can't open x.com: on November 2, 2026 we asked Claude Code 2.1.314 to fetch an X profile, a single post and a search page, and each request came back "HTTP 402 Payment Required" with no page body.
Even a browser that isn't signed in sees little of X: a profile shows its bio and counts, and search sends you to a login page. So X data has to reach Claude Code through a tool you add, and two kinds fit it:
- An MCP server hands Claude Code tools such as "search posts" or "get a profile" through the Model Context Protocol (opens in a new tab). You ask in plain words, Claude picks the tool and reads the JSON it returns, all inside the session.
- A skill gives Claude Code written know-how instead of tools: a SKILL.md file describing an API, so Claude writes and runs the requests itself, usually as a script you keep.
Both routes still have to get the data from somewhere. The official X API's hosted MCP server and most community servers run on your own X developer app, with OAuth and prepaid credits billed at $0.005 per post and $0.010 per profile, up to 3 million post reads a month (X's pricing (opens in a new tab)). Servers that sign in with your X username or cookies skip the developer app and put your account at risk instead. A data API key needs neither. Our guide to the Twitter API for AI agents compares these routes for any agent; this page sets them up in Claude Code.
#Add X data to Claude Code in one line
To read X in Claude Code, use Sorsa API, a Twitter (X) API and scraper, through its MCP server: one terminal line gives Claude 40 read-only tools behind one key, with no X developer account, tweets from $0.014 per 1,000 and 20 requests per second on every plan.
Sorsa API counts each tool call as one request, and a single call can bring back a whole batch of 100 posts. Claude Code launches the server through npx, so Node.js 18 or later has to be installed; node -v prints your version.
-
Get a key. Sign up for Sorsa API and copy your key from the dashboard's API keys page. A new account starts with 100 requests that cost nothing, ask for no card and don't run out with time.
-
Add the server. Run this in a terminal, outside a Claude Code session, after swapping
YOUR_API_KEYfor the key you copied. The-s userpart makes the X tools available in every project.Terminal claude mcp add sorsa -s user -e SORSA_API_KEY=YOUR_API_KEY -- npx -y sorsa-mcp -
Check the connection.
claude mcp get sorsashould print "Scope: User config" and "Connected". Inside a session,/mcplists sorsa with its tools. -
Ask a first question. Try "How many Sorsa API requests do I have left?". Claude answers with
get_key_usage_info, a free lookup onGET /key-usage-info(opens in a new tab) that doesn't use up a request. A number in the reply proves the whole chain works; a mistyped key brings back 401 "invalid api key" instead. -
Give it real work. Paste one of the three prompts below and watch Claude pick the tools.
Good to know
Keep the order of the line: name, then
-e, then--. Put the key first, as inclaude mcp add --env SORSA_API_KEY=... sorsa, and Claude Code stops with "Invalid environment variable format: sorsa": the flag accepts a list of pairs and swallows the name as another one.The double dash hands the rest of the line to npx, so a
-eadded at the very end goes to npx too. The server then starts with an empty environment and no key.
Setting up another app too? The Sorsa MCP server page lists the matching line for Cursor, Codex and VS Code, and our Twitter MCP server guide weighs the kinds of X servers against each other, cost per tool call included.
#Choose who gets the X tools: you, a project or your team
Claude Code keeps every MCP server in one of three scopes, and the scope decides who gets the X tools: you in one project, you in every project, or everyone who clones the repository.
- Local, the default when you leave out
-s: the server loads only in the project where you added it. Claude Code stores it in~/.claude.jsonunder that project's path. - User, with
-s user: the server loads in every project on your computer and stays private to you, also in~/.claude.json. - Project, with
-s project: Claude Code writes the server to.mcp.jsonat the repository root, and everyone who clones the repository gets it.
Pick the scope and copy the line:
Who should get the X tools?
claude mcp add sorsa -s user -e SORSA_API_KEY=YOUR_API_KEY -- npx -y sorsa-mcp
- Scope
- User: every project on this computer, private to you
- Adds
- 40 read-only X tools; each call is 1 request
- Stored in
~/.claude.json- Check with
claude mcp get sorsashows "Scope: User config" and "Connected"
claude mcp add sorsa -e SORSA_API_KEY=YOUR_API_KEY -- npx -y sorsa-mcp
- Scope
- Local, the default: only the project you run it in, private to you
- Stored in
~/.claude.json, under this project's path- Check with
claude mcp get sorsafrom the project folder
claude mcp add-json sorsa -s project '{"type":"stdio","command":"npx","args":["-y","sorsa-mcp"],"env":{"SORSA_API_KEY":"${SORSA_API_KEY}"}}'
- Scope
- Project: everyone who clones the repository
- Stored in
.mcp.jsonat the repository root, with the variable's name instead of the key; commit it- Each teammate
- Sets
SORSA_API_KEYin their own shell, then approves the server once in their first session
Each scope gets its own line; the team version keeps the key out of the repository.
For a team, commit the file and keep the key out of it. Claude Code expands ${VAR} references in .mcp.json, so the file can name the variable while each person keeps their own key in their shell:
{
"mcpServers": {
"sorsa": {
"type": "stdio",
"command": "npx",
"args": ["-y", "sorsa-mcp"],
"env": { "SORSA_API_KEY": "${SORSA_API_KEY}" }
}
}
}
We wrote this file with claude mcp add-json on November 2. Until a teammate approves it, claude mcp list shows the server as "Pending approval (run claude to approve)", and their first interactive session asks once. If the variable isn't set, the list warns "Missing environment variables: SORSA_API_KEY", so a missing key never fails silently. To ask again for servers you approved or declined, run claude mcp reset-project-choices. Anthropic's MCP guide for Claude Code (opens in a new tab) documents every scope.
#Add the agent skill when Claude Code writes code
Install Sorsa API's agent skill when the job should end in code that runs without Claude: an export script, a nightly job, a data pipeline. The MCP server answers questions inside a session; the skill gives Claude Code the API's rules of use (the endpoint for each job, paging through next_cursor, batches of up to 100 IDs), so the code it writes follows those rules from the start.
npx skills add Sorsa-io/sorsa-x-api-skill -g -a claude-code -y
The command copies the sorsa-x-api skill into ~/.claude/skills/, where every Claude Code session finds it; we ran it on November 2. Claude Code reads only the skill's short description until a task matches, then opens the full SKILL.md, as Anthropic's skills docs (opens in a new tab) describe. The skill's code reads your key from SORSA_API_KEY, so put it in the env block of ~/.claude/settings.json, which Claude Code applies to every session and to the commands it runs:
{
"env": { "SORSA_API_KEY": "YOUR_API_KEY" }
}
Then ask for the result as a file, not as an answer. "Write a Python script that saves every post mentioning our product from the last 30 days to mentions.csv" makes Claude Code write a loop on POST /search-tweets (opens in a new tab) that follows next_cursor to the end, run it, and leave the script for next month.
The two routes split the work cleanly:
| You want | Use | Why |
|---|---|---|
| An answer in the session | MCP server | Claude calls the tools and reads the results itself |
| A file or a script to keep | Agent skill | The code runs without Claude and keeps bulk data out of the conversation |
| Both | Both, on one key | Each call is one request either way |
An answer in the session
- Use
- MCP server
- Why
- Claude calls the tools and reads the results itself
A file or a script to keep
- Use
- Agent skill
- Why
- The code runs without Claude and keeps bulk data out of the conversation
Both
- Use
- Both, on one key
- Why
- Each call is one request either way
Most people start with the MCP server and add the skill the first time they want a file instead of an answer.
#Three ready prompts and what one run costs
Each prompt below names the job, the size and the output, so Claude Code calls a known tool a known number of times. Swap in your topic or handles and paste it into a session.
Research a topic this week
Search X for posts about [your topic] from the last 7 days with
at least 20 likes. Read the top 100, group them into 3 to 5
themes, and give me a brief with the best 2 posts per theme,
linked.
Claude runs search_tweets five times, following next_cursor, at about 20 posts a call. The 100 posts cost from $0.007 on Sorsa API and $0.50 at the official X API's rate of $0.005 per post.
Digest the accounts you follow
For each of these accounts, read their posts from the last 7
days: [paste up to 10 handles]. Summarize what each one
announced or argued, flag anything about pricing or launches,
and end with a 5-line overview.
Claude calls get_user_tweets once per account, which runs POST /user-tweets (opens in a new tab) for 20 posts at a time. About 200 posts cost from $0.014 on Sorsa API and $1.00 at the official X API's rates.
Vet a list of accounts
Here are up to 100 X handles: [paste]. Get all the profiles in
one batch, then make a table with followers, following, posts,
join date and bio, sorted by followers. Flag accounts younger
than one year and save the table as accounts.csv.
Claude calls get_user_info_batch, which runs GET /info-batch (opens in a new tab) and returns all 100 profiles at once, from $0.0014 on Sorsa API. The official X API bills $0.010 per profile, $1.00 for the list.
The official X API's side grows on November 22, 2026, when X starts billing the authors that come back with posts at $0.010 per user (X's notice (opens in a new tab)). A search that returns 20 posts from 20 different authors then costs $0.30 instead of $0.10. Every post on Sorsa API carries its author's full profile in the same request.
All three prompts together use 16 requests, so the 100 free requests run them six times before you pick a plan. Run the research prompt every day, or point it at a busy topic, and the gap grows with every post Claude reads:
Official X API
$500
for 100K posts
$0.005 per post
Sorsa API
from$7
for 100K posts
from $0.07 per 1,000
#Keep X results from flooding Claude's context
X results are long JSON, so ask Claude Code for the posts you need and send bulk jobs to a script. Claude Code warns when one MCP tool result passes 10K tokens and cuts it at 25K by default.
- Ask for a number. "The 50 most-liked posts" keeps each call small; "everything about X" makes Claude page on and fill its context with raw posts.
- Know what each post carries. Every post comes back with its author's full profile, which helps Claude judge sources and also takes room. Ask Claude to keep only the fields it needs when it saves results.
- Raise the cap for one session with
MAX_MCP_OUTPUT_TOKENS=50000 claudewhen a single large result matters more than room in the context. - Move thousands of rows to the skill. A follower list or a month of mentions belongs in a script that writes CSV; only Claude's summary of the file enters the conversation.
The tools themselves take little room. Sorsa API's server describes its 40 tools in about 23K characters, near 5,800 tokens, and with tool search on, the default, Claude Code sees only the names until a task calls for one.
#Let Claude Code run X jobs without asking
Because every Sorsa API tool only reads, you can let Claude Code call them without a prompt each time: the most a confused or looping session can do is spend requests. Add one allow rule to .claude/settings.json in the project, or to ~/.claude/settings.json for every project:
{
"permissions": { "allow": ["mcp__sorsa__*"] }
}
Claude Code accepts a wildcard only after a named server, so mcp__sorsa__* approves the Sorsa API tools and nothing else (permission rules (opens in a new tab)).
The same rule makes unattended runs possible. Claude Code's headless mode (opens in a new tab), claude -p, runs one prompt and exits, so a cron job or a CI schedule can write a daily X digest:
claude -p "Search X for posts about [your topic] from the last 24 hours
and write a 10-line digest to digest.md" \
--allowedTools "mcp__sorsa__*,Write"
We ran a headless call like this on November 2 with a made-up key: the Sorsa API tool ran with no approval prompt, and Sorsa API answered 401 "invalid api key", so the whole chain from Claude Code to the API was live. Spend has a ceiling as well: one key never goes past 20 requests per second, and extra requests on pay as you go stop at a limit you set for the billing period, $100 unless you raise it.
Good to know
Treat what posts say as material to read, never as orders. Some posts on X are written to steer AI agents; with read-only X tools, the worst such a post can do is cost a request. In headless runs, allow only the tools the job needs and keep Bash out of
--allowedTools.
#Connect Claude Code to X today
Claude Code can't fetch x.com, but one line gives it X data: Sorsa API's MCP server for questions in a session and its agent skill for scripts you keep, both on one read-only key. Tweets cost from $0.014 per 1,000, where the official X API charges $5.00, and no X login or developer app is ever involved. Start with the 100 free requests, enough for six rounds of the three prompts above, and find more prompts on build with AI.
#FAQ
Can Claude Code post to X?
Not through Sorsa API. Its MCP server and API are read-only, so Claude Code can read X but never post, like, follow or send DMs in your name. To post from Claude Code, pair it with the official X API on your own developer app, and keep each post behind Claude Code's approval prompt, with no allow rule for posting tools.
Which Twitter API should I use with Claude Code?
Use Sorsa API to read X in Claude Code. One claude mcp add line adds 40 read-only tools with no X developer account or OAuth, tweets cost from $0.014 per 1,000 where the official X API charges $5.00, and every plan handles 20 requests per second. The same key runs the agent skill for scripts, and your X account is never connected.
Do I need an X developer account to read tweets in Claude Code?
Only on the official X API. Its hosted MCP server and most community servers need an X developer app with OAuth and prepaid credits before the first read; our guide to the Twitter API without a developer account covers what that involves. Sorsa API needs one key from its dashboard, and the first 100 requests are free.
Can Claude Code search the full Twitter archive?
Yes, with a search tool that reaches back far enough. Sorsa API's search_tweets takes X's search operators, including since: and until:, and searches posts back to 2006, about 20 per call. Ask Claude Code for a date range in plain words, such as "posts about electric cars from March 2019", and it writes the operators itself.
Does the Sorsa MCP server work in Claude Desktop and on claude.ai?
Yes in Claude Desktop, no on claude.ai. Claude Desktop starts local servers: add the same command, arguments and SORSA_API_KEY to its config file (Settings, then Developer, then Edit Config) and restart it. Claude.ai in a browser connects MCP servers by URL only, while Sorsa API's server runs on your own computer, so chats that need X data belong in Claude Desktop.
#How we checked
On November 2, 2026 we ran Claude Code 2.1.314 in a scratch configuration with a made-up key. We asked its WebFetch tool to open an X profile, a post and a search page (each answered HTTP 402), added sorsa-mcp 1.0.4 at user and project scope, and made a headless call that reached Sorsa API and got 401 back. We installed the agent skill into a test home folder with the skills command line. We then compared our results with Claude Code's MCP, skills, permissions and headless docs, took the official X API's rates from its pricing page and its October 23 expansions notice, and matched each endpoint named here to the live Sorsa API reference.
Sources
- Connect Claude Code to tools via MCP (opens in a new tab), Anthropic
- Extend Claude with skills (opens in a new tab), Anthropic
- Configure permissions (opens in a new tab), Anthropic
- Run Claude Code programmatically (opens in a new tab), Anthropic
- Pay-per-use pricing (opens in a new tab), X
- X API PPU: expansions update (opens in a new tab), X Developers
- sorsa-mcp on npm (opens in a new tab)
- sorsa-x-api-skill on GitHub (opens in a new tab)
- Sorsa API reference