twitter-cli-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetwitter-cli
twitter-cli
Overview
概述
twitter-cli--json--yamlKey capabilities:
- Read: feed, bookmarks, search, tweet detail, article, list timeline, user lookup
- Write: post, reply, quote, delete, like, retweet, bookmark
- Auth: browser cookie extraction (Arc/Chrome/Edge/Firefox/Brave) or env vars
- Anti-detection: TLS fingerprinting, full cookie forwarding, request jitter
- Output: rich tables (default), JSON, YAML, Markdown (articles)
twitter-cli--json--yaml核心功能:
- 浏览:动态、书签、搜索、推文详情、文章、列表时间线、用户查询
- 操作:发布、回复、引用、删除、点赞、转发、收藏
- 认证:浏览器Cookie提取(Arc/Chrome/Edge/Firefox/Brave)或环境变量
- 反检测:TLS指纹识别、完整Cookie转发、请求抖动
- 输出:丰富表格(默认)、JSON、YAML、Markdown(文章)
Installation
安装
bash
undefinedbash
undefinedRecommended: uv tool (fast, isolated)
推荐:uv工具(快速、隔离)
uv tool install twitter-cli
uv tool install twitter-cli
Alternative: pipx
替代方案:pipx
pipx install twitter-cli
pipx install twitter-cli
Upgrade to latest
升级至最新版本
uv tool upgrade twitter-cli
**From source:**
```bash
git clone git@github.com:jackwener/twitter-cli.git
cd twitter-cli
uv syncuv tool upgrade twitter-cli
**从源码安装:**
```bash
git clone git@github.com:jackwener/twitter-cli.git
cd twitter-cli
uv syncAuthentication
认证
Priority order:
- Environment variables: +
TWITTER_AUTH_TOKENTWITTER_CT0 - Browser cookies (auto-extracted from Arc/Chrome/Edge/Firefox/Brave)
Browser cookie extraction (recommended):
bash
undefined优先级顺序:
- 环境变量:+
TWITTER_AUTH_TOKENTWITTER_CT0 - 浏览器Cookie(自动从Arc/Chrome/Edge/Firefox/Brave提取)
浏览器Cookie提取(推荐):
bash
undefinedAuto-detect browser and extract all Twitter cookies
自动检测浏览器并提取所有Twitter Cookie
twitter feed
twitter feed
Specify browser explicitly
明确指定浏览器
TWITTER_BROWSER=chrome twitter feed
TWITTER_BROWSER=chrome twitter feed
Chrome multi-profile
Chrome多配置文件
TWITTER_CHROME_PROFILE="Profile 2" twitter feed
**Manual environment variables:**
```bash
export TWITTER_AUTH_TOKEN="your_auth_token"
export TWITTER_CT0="your_ct0_token"
twitter feedProxy support:
bash
export TWITTER_PROXY=http://127.0.0.1:7890TWITTER_CHROME_PROFILE="Profile 2" twitter feed
**手动设置环境变量:**
```bash
export TWITTER_AUTH_TOKEN="你的auth_token"
export TWITTER_CT0="你的ct0_token"
twitter feed代理支持:
bash
export TWITTER_PROXY=http://127.0.0.1:7890or
或
export TWITTER_PROXY=socks5://127.0.0.1:1080
undefinedexport TWITTER_PROXY=socks5://127.0.0.1:1080
undefinedCore Commands
核心命令
Read Timeline
浏览时间线
bash
undefinedbash
undefinedFor You feed (default)
为你推荐动态(默认)
twitter feed
twitter feed
Following feed
关注列表动态
twitter feed -t following
twitter feed -t following
Limit results
限制结果数量
twitter feed --max 20
twitter feed --max 20
Full text (no truncation)
完整文本(不截断)
twitter feed --full-text
twitter feed --full-text
Structured output for agents
供Agent使用的结构化输出
twitter feed --json
twitter feed --yaml
twitter feed --json
twitter feed --yaml
With ranking filter
排序过滤
twitter feed --filter --max 50
twitter feed --filter --max 50
Pagination cursor
分页游标
twitter feed --cursor "DAABCgABGdE..."
undefinedtwitter feed --cursor "DAABCgABGdE..."
undefinedSearch
搜索
bash
undefinedbash
undefinedBasic search
基础搜索
twitter search "AI agent"
twitter search "AI agent"
Search type: Top, Latest, Photos, Videos
搜索类型:热门、最新、图片、视频
twitter search "machine learning" -t Latest
twitter search "machine learning" -t Latest
Full text + JSON output
完整文本 + JSON输出
twitter search "python" --full-text --json
twitter search "python" --full-text --json
Advanced filters
高级过滤
twitter search "climate" --from scientist --lang en --since 2026-01-01
twitter search "news" --exclude retweets --has links
twitter search "climate" --from scientist --lang en --since 2026-01-01
twitter search "news" --exclude retweets --has links
Save to file
保存到文件
twitter search "trending" -o results.json
twitter search "trending" -o results.json
Apply ranking filter
应用排序过滤
twitter search "tech" --filter
undefinedtwitter search "tech" --filter
undefinedBookmarks
书签
bash
undefinedbash
undefinedList bookmarks
列出书签
twitter bookmarks
twitter bookmarks
Limit + full text
限制数量 + 完整文本
twitter bookmarks --max 30 --full-text
twitter bookmarks --max 30 --full-text
Export as YAML
导出为YAML格式
twitter bookmarks --yaml
undefinedtwitter bookmarks --yaml
undefinedTweet Detail (tweet + replies)
推文详情(推文 + 回复)
bash
undefinedbash
undefinedBy tweet ID
通过推文ID查询
twitter tweet 1234567890
twitter tweet 1234567890
By URL
通过URL查询
twitter tweet https://x.com/user/status/1234567890
twitter tweet https://x.com/user/status/1234567890
Full text in reply table
回复表格显示完整文本
twitter tweet 1234567890 --full-text
twitter tweet 1234567890 --full-text
Structured output
结构化输出
twitter tweet 1234567890 --json
undefinedtwitter tweet 1234567890 --json
undefinedShow Command (open tweet by index)
展示命令(按索引打开推文)
bash
undefinedbash
undefinedAfter running twitter feed
or twitter search
:
twitter feedtwitter search运行twitter feed
或twitter search
后:
twitter feedtwitter searchtwitter show 2 # Open tweet #2 from last list
twitter show 2 --full-text
twitter show 2 --json
undefinedtwitter show 2 # 打开上次列表中的第2条推文
twitter show 2 --full-text
twitter show 2 --json
undefinedTwitter Article (fetch and export as Markdown)
Twitter文章(获取并导出为Markdown)
bash
undefinedbash
undefinedBy article ID
通过文章ID查询
twitter article 1234567890
twitter article 1234567890
By URL
通过URL查询
twitter article https://x.com/user/article/1234567890
twitter article https://x.com/user/article/1234567890
Export as Markdown
导出为Markdown格式
twitter article 1234567890 --markdown
twitter article 1234567890 --output article.md
twitter article 1234567890 --markdown
twitter article 1234567890 --output article.md
JSON output
JSON输出
twitter article 1234567890 --json
undefinedtwitter article 1234567890 --json
undefinedList Timeline
列表时间线
bash
undefinedbash
undefinedFetch tweets from a Twitter List
获取Twitter列表中的推文
twitter list 1539453138322673664
twitter list 1539453138322673664
Pagination
分页
twitter list 1539453138322673664 --cursor "DAABCgABGdE..."
twitter list 1539453138322673664 --cursor "DAABCgABGdE..."
Full text
完整文本
twitter list 1539453138322673664 --full-text
undefinedtwitter list 1539453138322673664 --full-text
undefinedUser Lookup
用户查询
bash
undefinedbash
undefinedProfile
用户资料
twitter user elonmusk
twitter user elonmusk
User tweets
用户推文
twitter user-posts elonmusk --max 20
twitter user-posts elonmusk --full-text -o tweets.json
twitter user-posts elonmusk --max 20
twitter user-posts elonmusk --full-text -o tweets.json
User likes (own account only, private since Jun 2024)
用户点赞(仅自己账号可用,2024年6月起为私有)
twitter likes elonmusk --max 30
twitter likes elonmusk --max 30
Followers
粉丝列表
twitter followers elonmusk --max 50
twitter followers elonmusk --max 50
Following
关注列表
twitter following elonmusk --max 50
undefinedtwitter following elonmusk --max 50
undefinedWrite Operations
操作功能
Post Tweet
发布推文
bash
undefinedbash
undefinedSimple tweet
简单推文
twitter post "Hello from twitter-cli!"
twitter post "Hello from twitter-cli!"
Tweet with image (up to 4)
带图片的推文(最多4张)
twitter post "Hello!" --image photo.jpg
twitter post "Gallery" -i a.png -i b.jpg -i c.webp
twitter post "Hello!" --image photo.jpg
twitter post "Gallery" -i a.png -i b.jpg -i c.webp
Structured output
结构化输出
twitter post "Hello from twitter-cli!" --json
undefinedtwitter post "Hello from twitter-cli!" --json
undefinedReply
回复推文
bash
undefinedbash
undefinedReply to tweet
回复指定推文
twitter post "Nice!" --reply-to 1234567890
twitter post "Nice!" --reply-to 1234567890
Reply with image
带图片回复
twitter reply 1234567890 "Great!" -i screenshot.png
undefinedtwitter reply 1234567890 "Great!" -i screenshot.png
undefinedQuote Tweet
引用推文
bash
undefinedbash
undefinedQuote with text
带文本引用
twitter quote 1234567890 "Check this out"
twitter quote 1234567890 "Check this out"
Quote with image
带图片引用
twitter quote 1234567890 "Look at this chart" -i chart.png
undefinedtwitter quote 1234567890 "Look at this chart" -i chart.png
undefinedDelete Tweet
删除推文
bash
twitter delete 1234567890bash
twitter delete 1234567890Like / Unlike
点赞 / 取消点赞
bash
twitter like 1234567890
twitter like 1234567890 --yaml
twitter unlike 1234567890bash
twitter like 1234567890
twitter like 1234567890 --yaml
twitter unlike 1234567890Retweet / Unretweet
转发 / 取消转发
bash
twitter retweet 1234567890
twitter unretweet 1234567890bash
twitter retweet 1234567890
twitter unretweet 1234567890Bookmark / Unbookmark
收藏 / 取消收藏
bash
twitter bookmark 1234567890
twitter unbookmark 1234567890bash
twitter bookmark 1234567890
twitter unbookmark 1234567890Follow / Unfollow
关注 / 取消关注
bash
twitter follow elonmusk --json
twitter unfollow elonmuskbash
twitter follow elonmusk --json
twitter unfollow elonmuskConfiguration
配置
Create in your working directory:
config.yamlyaml
fetch:
count: 50
filter:
mode: "topN" # "topN" | "score" | "all"
topN: 20
minScore: 50
lang: []
excludeRetweets: false
weights:
likes: 1.0
retweets: 3.0
replies: 2.0
bookmarks: 5.0
views_log: 0.5
rateLimit:
requestDelay: 2.5 # base delay (randomized ×0.7–1.5)
maxRetries: 3
retryBaseDelay: 5.0
maxCount: 200Scoring formula:
text
score = likes_w * likes
+ retweets_w * retweets
+ replies_w * replies
+ bookmarks_w * bookmarks
+ views_log_w * log10(max(views, 1))Filter modes:
- : Keep highest N tweets by score
topN - : Keep tweets where score >= minScore
score - : Return all tweets sorted by score
all
在工作目录创建文件:
config.yamlyaml
fetch:
count: 50
filter:
mode: "topN" # "topN" | "score" | "all"
topN: 20
minScore: 50
lang: []
excludeRetweets: false
weights:
likes: 1.0
retweets: 3.0
replies: 2.0
bookmarks: 5.0
views_log: 0.5
rateLimit:
requestDelay: 2.5 # 基础延迟(随机乘以0.7–1.5)
maxRetries: 3
retryBaseDelay: 5.0
maxCount: 200评分公式:
text
score = likes_w * likes
+ retweets_w * retweets
+ replies_w * replies
+ bookmarks_w * bookmarks
+ views_log_w * log10(max(views, 1))过滤模式:
- : 保留评分最高的N条推文
topN - : 保留评分≥minScore的推文
score - : 返回所有按评分排序的推文
all
AI Agent Usage
AI Agent 用法
All commands support or for structured output. Non-TTY stdout defaults to YAML.
--json--yamlExample: Fetch and parse timeline
python
import subprocess
import yaml
result = subprocess.run(
["twitter", "feed", "--max", "10", "--yaml"],
capture_output=True,
text=True,
check=True
)
data = yaml.safe_load(result.stdout)
for tweet in data["tweets"]:
print(f"{tweet['author']['username']}: {tweet['text']}")Example: Post tweet from Python
python
import subprocess
import json
result = subprocess.run(
["twitter", "post", "Hello from Python!", "--json"],
capture_output=True,
text=True,
check=True
)
response = json.loads(result.stdout)
print(f"Tweet ID: {response['tweetId']}")Example: Search and filter
bash
undefined所有命令都支持或结构化输出。非TTY标准输出默认使用YAML格式。
--json--yaml示例:获取并解析时间线
python
import subprocess
import yaml
result = subprocess.run(
["twitter", "feed", "--max", "10", "--yaml"],
capture_output=True,
text=True,
check=True
)
data = yaml.safe_load(result.stdout)
for tweet in data["tweets"]:
print(f"{tweet['author']['username']}: {tweet['text']}")示例:通过Python发布推文
python
import subprocess
import json
result = subprocess.run(
["twitter", "post", "Hello from Python!", "--json"],
capture_output=True,
text=True,
check=True
)
response = json.loads(result.stdout)
print(f"推文ID: {response['tweetId']}")示例:搜索并过滤
bash
undefinedGet top 10 AI tweets from today as JSON
获取今日关于AI agent的前10条推文,格式为JSON
twitter search "AI agent" --since 2026-05-17 --filter --max 10 --json
**Structured output contract:** See [SCHEMA.md](https://github.com/jackwener/twitter-cli/blob/main/SCHEMA.md)twitter search "AI agent" --since 2026-05-17 --filter --max 10 --json
**结构化输出规范:** 查看[SCHEMA.md](https://github.com/jackwener/twitter-cli/blob/main/SCHEMA.md)Common Patterns
常用场景
Export bookmarks to file
将书签导出到文件
bash
twitter bookmarks --max 100 --json > bookmarks.jsonbash
twitter bookmarks --max 100 --json > bookmarks.jsonMonitor user tweets
监控用户推文
bash
undefinedbash
undefinedFetch latest 5 tweets from user
获取用户最新5条推文
twitter user-posts elonmusk --max 5 --yaml
undefinedtwitter user-posts elonmusk --max 5 --yaml
undefinedSearch and rank by engagement
搜索并按互动量排序
bash
undefinedbash
undefinedTop 10 tweets about "AI" by score
关于"AI"的前10条高评分推文
twitter search "AI" --filter --max 10 --full-text
undefinedtwitter search "AI" --filter --max 10 --full-text
undefinedPost with multiple images
发布多张图片的推文
bash
twitter post "My photo gallery" -i img1.jpg -i img2.png -i img3.webpbash
twitter post "My photo gallery" -i img1.jpg -i img2.png -i img3.webpReply to tweet with image
带图片回复推文
bash
twitter reply 1234567890 "Here's the screenshot" -i screenshot.pngbash
twitter reply 1234567890 "Here's the screenshot" -i screenshot.pngExtract article as Markdown
将文章提取为Markdown格式
bash
twitter article 1234567890 --markdown --output ~/articles/ai-safety.mdbash
twitter article 1234567890 --markdown --output ~/articles/ai-safety.mdUse proxy for all requests
为所有请求使用代理
bash
export TWITTER_PROXY=http://127.0.0.1:7890
twitter feed --max 20bash
export TWITTER_PROXY=http://127.0.0.1:7890
twitter feed --max 20Troubleshooting
故障排除
No Twitter cookies found
未找到Twitter Cookie
Solution:
- Log in to in a supported browser (Arc/Chrome/Edge/Firefox/Brave)
x.com - Or set and
TWITTER_AUTH_TOKENmanuallyTWITTER_CT0 - Run with for diagnostics:
-vbashtwitter -v feed
解决方案:
- 在支持的浏览器(Arc/Chrome/Edge/Firefox/Brave)中登录
x.com - 或手动设置和
TWITTER_AUTH_TOKENTWITTER_CT0 - 使用参数运行以获取诊断信息:
-vbashtwitter -v feed
Cookie expired (HTTP 401/403)
Cookie过期(HTTP 401/403)
Solution: Re-login to and retry.
x.com解决方案: 重新登录后重试。
x.comKeychain access denied (macOS)
钥匙串访问被拒绝(macOS)
SSH sessions:
bash
security unlock-keychain ~/Library/Keychains/login.keychain-dbLocal terminal:
- Open Keychain Access → search for "<Browser> Safe Storage"
- Access Control → add Terminal app → Save Changes
- Or click "Always Allow" when prompted
SSH会话:
bash
security unlock-keychain ~/Library/Keychains/login.keychain-db本地终端:
- 打开钥匙串访问 → 搜索"<浏览器名称> Safe Storage"
- 访问控制 → 添加终端应用 → 保存更改
- 或在提示时点击**"始终允许"**
Twitter API error 404
Twitter API错误404
Solution: Retry command. The client attempts a live queryId fallback when GraphQL IDs rotate.
解决方案: 重试命令。当GraphQL ID更新时,客户端会尝试实时查询ID回退。
Invalid tweet JSON file
无效的推文JSON文件
Solution: Regenerate using:
bash
twitter feed --json > tweets.json解决方案: 重新生成:
bash
twitter feed --json > tweets.jsonWindows: no pipe output in AI agent subprocess
Windows:AI Agent子进程无管道输出
Issue: ConPTY intercepts pipe output from network commands.
Fix:
- Use Git Bash as terminal shell
- Set in terminal settings
"windowsEnableConpty": false - Standard works correctly
subprocess.run(capture_output=True)
问题: ConPTY拦截网络命令的管道输出。
修复:
- 使用Git Bash作为终端Shell
- 在终端设置中设置
"windowsEnableConpty": false - 标准可正常工作
subprocess.run(capture_output=True)
Rate limiting (HTTP 429)
请求频率限制(HTTP 429)
Solution:
- Use to limit requests
--max - Set to avoid direct IP exposure
TWITTER_PROXY - Increase in
rateLimit.requestDelayconfig.yaml - Use residential proxies instead of datacenter IPs
解决方案:
- 使用限制请求数量
--max - 设置避免直接暴露IP
TWITTER_PROXY - 在中增加
config.yamlrateLimit.requestDelay - 使用住宅代理而非数据中心IP
Best Practices
最佳实践
- Use a proxy — set to avoid direct IP exposure
TWITTER_PROXY - Keep request volumes low — prefer over
--max 20--max 500 - Don't run too frequently — each startup fetches x.com to initialize headers
- Use browser cookie extraction — provides full cookie fingerprint
- Avoid datacenter IPs — residential proxies are safer
- Upgrade regularly — to avoid outdated API handling
uv tool upgrade twitter-cli
- 使用代理 — 设置避免直接暴露IP
TWITTER_PROXY - 控制请求量 — 优先使用而非
--max 20--max 500 - 不要过于频繁运行 — 每次启动都会获取x.com以初始化请求头
- 使用浏览器Cookie提取 — 提供完整的Cookie指纹
- 避免数据中心IP — 住宅代理更安全
- 定期升级 — 使用避免API处理过时
uv tool upgrade twitter-cli
Output Modes
输出模式
- Rich table (default): Interactive reading in terminal
- : Show full tweet text in tables
--full-text - : Structured output for agents (default for non-TTY)
--yaml - : Strict JSON for parsers
--json - /
-c: Token-efficient compact output--compact - : Save to file
-o FILE
- 丰富表格(默认):终端交互式浏览
- : 在表格中显示完整推文文本
--full-text - : 供Agent使用的结构化输出(非TTY环境默认)
--yaml - : 供解析器使用的严格JSON格式
--json - /
-c: 高效压缩输出--compact - : 保存到文件
-o FILE
Development
开发
bash
undefinedbash
undefinedInstall dev dependencies
安装开发依赖
uv sync --extra dev
uv sync --extra dev
Lint
代码检查
uv run ruff check .
uv run ruff check .
Tests
测试
uv run pytest -q
undefineduv run pytest -q
undefinedProject Structure
项目结构
text
twitter_cli/
├── cli.py # Command-line interface
├── client.py # HTTP client + anti-detection
├── graphql.py # GraphQL query IDs, URL building
├── parser.py # Tweet/User/Media parsing
├── auth.py # Cookie extraction
├── config.py # Configuration loading
├── filter.py # Ranking/scoring logic
├── formatter.py # Rich table formatting
├── output.py # JSON/YAML serialization
└── models.py # Data models (Tweet, User, Media)text
twitter_cli/
├── cli.py # 命令行界面
├── client.py # HTTP客户端 + 反检测
├── graphql.py # GraphQL查询ID、URL构建
├── parser.py # 推文/用户/媒体解析
├── auth.py # Cookie提取
├── config.py # 配置加载
├── filter.py # 排序/评分逻辑
├── formatter.py # 丰富表格格式化
├── output.py # JSON/YAML序列化
└── models.py # 数据模型(Tweet, User, Media)Example Workflows
示例工作流
Daily AI news digest
每日AI新闻摘要
bash
undefinedbash
undefinedSearch AI tweets from today, rank by engagement, export as JSON
搜索今日AI相关推文,按互动量排序,导出为JSON
twitter search "AI" --since 2026-05-17 --filter --max 20 --json > ai_digest.json
undefinedtwitter search "AI" --since 2026-05-17 --filter --max 20 --json > ai_digest.json
undefinedBookmark analysis
书签分析
python
import subprocess
import yaml
from collections import Counter
result = subprocess.run(
["twitter", "bookmarks", "--max", "200", "--yaml"],
capture_output=True, text=True, check=True
)
data = yaml.safe_load(result.stdout)python
import subprocess
import yaml
from collections import Counter
result = subprocess.run(
["twitter", "bookmarks", "--max", "200", "--yaml"],
capture_output=True, text=True, check=True
)
data = yaml.safe_load(result.stdout)Extract hashtags
提取话题标签
hashtags = []
for tweet in data["tweets"]:
hashtags.extend([h["text"] for h in tweet.get("hashtags", [])])
print(Counter(hashtags).most_common(10))
undefinedhashtags = []
for tweet in data["tweets"]:
hashtags.extend([h["text"] for h in tweet.get("hashtags", [])])
print(Counter(hashtags).most_common(10))
undefinedPost with automated image
自动生成图片并发布推文
python
import subprocesspython
import subprocessGenerate chart, then post with image
生成图表,然后带图片发布推文
subprocess.run(["python", "generate_chart.py"], check=True)
subprocess.run([
"twitter", "post",
"Daily metrics update",
"-i", "chart.png",
"--json"
], check=True)
undefinedsubprocess.run(["python", "generate_chart.py"], check=True)
subprocess.run([
"twitter", "post",
"Daily metrics update",
"-i", "chart.png",
"--json"
], check=True)
undefinedMonitor user and alert on keyword
监控用户推文并触发关键词提醒
bash
#!/bin/bashbash
#!/bin/bashCron job: check user tweets for keyword
定时任务:检查用户推文中的关键词
tweets=$(twitter user-posts elonmusk --max 5 --yaml)
if echo "$tweets" | grep -q "Mars"; then
echo "Alert: New Mars tweet from @elonmusk"
fi
undefinedtweets=$(twitter user-posts elonmusk --max 5 --yaml)
if echo "$tweets" | grep -q "Mars"; then
echo "提醒:@elonmusk发布了关于火星的新推文"
fi
undefinedRelated Projects
相关项目
- xiaohongshu-cli — Xiaohongshu (小红书) CLI
- bilibili-cli — Bilibili CLI
- discord-cli — Discord CLI
- tg-cli — Telegram CLI
License: Apache-2.0
Repository: https://github.com/jackwener/twitter-cli
PyPI: https://pypi.org/project/twitter-cli/
Repository: https://github.com/jackwener/twitter-cli
PyPI: https://pypi.org/project/twitter-cli/
- xiaohongshu-cli — 小红书CLI工具
- bilibili-cli — Bilibili CLI工具
- discord-cli — Discord CLI工具
- tg-cli — Telegram CLI工具
许可证: Apache-2.0
仓库地址: https://github.com/jackwener/twitter-cli
PyPI地址: https://pypi.org/project/twitter-cli/
仓库地址: https://github.com/jackwener/twitter-cli
PyPI地址: https://pypi.org/project/twitter-cli/