字节笔记本

2026年2月22日

bird - X/Twitter 高速 CLI 工具

本文介绍 bird,一个基于 GraphQL + Cookie 认证的高速 X/Twitter CLI 工具。无需 API Key,直接利用浏览器会话即可在命令行中完成发推、回复、浏览时间线等操作。

项目简介

bird 是由 Peter Steinberger (@steipete) 开发的开源 CLI 工具,它通过调用 X/Twitter 内部 GraphQL API,让用户能够在终端中快速与 Twitter/X 进行交互。该项目采用 Cookie 认证机制,无需申请开发者账号或 API Key,直接使用现有的浏览器登录会话即可操作。

截至 2026年1月,该项目已发布 v0.8.0 版本,支持丰富的推文操作功能。

核心特性

  • 🚀 极速体验:基于 GraphQL API,响应速度快
  • 🔐 Cookie 认证:无需 API Key,使用浏览器会话即可
  • 📖 阅读功能:读取推文、查看线程、浏览回复
  • ✍️ 发布功能:发送推文、回复、支持媒体上传
  • 🔍 搜索发现:搜索推文、查看热门话题、AI 精选新闻
  • 📋 列表管理:浏览书签、点赞、列表时间线
  • 🏠 多浏览器支持:自动提取 Safari、Chrome、Firefox、Arc、Brave 等浏览器的 Cookie

安装指南

通过 npm/pnpm/bun 安装

bash
# 全局安装
npm install -g @steipete/bird

# 或使用 pnpm
pnpm add -g @steipete/bird

# 或使用 bun
bun add -g @steipete/bird

通过 Homebrew 安装(macOS)

bash
brew install steipete/tap/bird

免安装运行

bash
# 使用 bunx 直接运行,无需安装
bunx @steipete/bird whoami

快速开始

1. 验证登录状态

bash
# 查看当前登录账号
bird whoami

# 检查认证信息来源
bird check

2. 读取推文

bash
# 读取单条推文
bird read https://x.com/username/status/1234567890

# 查看完整线程
bird thread https://x.com/username/status/1234567890

# 查看回复
bird replies https://x.com/username/status/1234567890

3. 浏览时间线

bash
# 主页时间线
bird home

# 只看关注的人
bird home --following

# 查看指定用户的推文
bird user-tweets @elonmusk

# 查看提及
bird mentions

4. 发送推文

bash
# 发送简单推文
bird tweet "Hello from bird CLI! 🐦"

# 回复推文
bird reply 1234567890 "This is a reply"

# 带媒体文件的推文(最多4张图片或1个视频)
bird tweet "Check out this image" --media ./photo.jpg

认证配置

bird 支持多种认证方式,按优先级自动尝试:

自动浏览器 Cookie 提取

bash
# 从 Chrome 提取 Cookie
bird whoami --cookie-source chrome

# 从 Firefox 提取
bird whoami --cookie-source firefox

# 从 Safari 提取
bird whoami --cookie-source safari

手动指定 Token

bash
bird whoami --auth-token "YOUR_AUTH_TOKEN" --ct0 "YOUR_CT0_TOKEN"

配置文件

创建配置文件 ~/.config/bird/config.json5

json5
{
  cookieSource: ["chrome"],
  chromeProfileDir: "/Users/username/Library/Application Support/Arc/User Data/Default",
  timeoutMs: 20000,
  quoteDepth: 1
}

搜索与发现

bash
# 搜索推文
bird search "Claude Code" -n 20

# 查看热门趋势
bird trending

# 查看 AI 精选新闻
bird news

# 浏览列表
bird lists

# 查看指定列表的时间线
bird list-timeline 1234567890

书签与互动

bash
# 查看书签
bird bookmarks

# 查看点赞
bird likes

# 取消书签
bird unbookmark 1234567890

# 关注/取消关注用户
bird follow @username
bird unfollow @username

高级用法

刷新 GraphQL Query ID 缓存

X/Twitter 的 GraphQL Query ID 会定期轮换,bird 会自动缓存并刷新:

bash
bird query-ids --fresh

Arc/Brave 浏览器支持

对于 Arc 或 Brave 等基于 Chromium 的浏览器:

bash
bird whoami --chrome-profile-dir "/Users/username/Library/Application Support/Arc/User Data/Default"

技术实现

  • GraphQL API:直接调用 X/Twitter 内部 GraphQL 端点
  • Cookie 认证:复用浏览器登录会话,无需额外授权
  • 自动重试:内置指数退避重试机制
  • TypeScript:使用 TypeScript 开发,提供类型定义

注意事项

  1. API 稳定性:使用的是 X/Twitter 未公开的内部 API,可能随时变更
  2. 速率限制:发推操作更容易触发限流,如被限制建议使用浏览器工具
  3. 媒体限制:单条推文最多支持 4 张图片或 1 个视频
  4. 账号安全:Cookie 认证等同于浏览器登录,请妥善保管认证信息

适用场景

  • 快速浏览:在终端中快速查看时间线,无需打开浏览器
  • 自动化脚本:集成到工作流中自动发布更新
  • 效率工具:"阅读 → 回复 → 继续工作" 的高效循环
  • 多账号管理:通过不同浏览器 Profile 切换账号

项目链接

总结

bird 是一个设计精良的 X/Twitter CLI 工具,特别适合需要在命令行环境中高效处理社交媒体内容的开发者。其 Cookie 认证机制简化了配置流程,GraphQL 架构保证了响应速度,丰富的命令集覆盖了日常使用的绝大部分场景。对于追求效率的终端用户来说,bird 是一个值得尝试的开源工具。

分享: