X/Twitter research skill with a TypeScript CLI for searching tweets, reading threads, monitoring account watchlists, and returning structured, cache-backed findings for agent workflows.
This repository contains:
- A skill spec in
SKILL.mdthat tells an agent when and how to use X data for research. - A CLI in
scripts/x-search.tsthat wraps common X API v2 workflows. - Support libraries for API calls, caching, formatting, and dry-run mock data.
- Users who want quick, repeatable X/Twitter research from the terminal.
- Agents that need structured social-signal data (JSON) they can summarize, rank, and cite.
npx tsx scripts/x-search.ts search "AI agents replacing junior developers" --dry-runDry-run uses mock data from scripts/lib/mock.ts so you can test end-to-end behavior safely.
Create:
~/.openclaw/workspace/.env.x-api
With:
X_BEARER_TOKEN=your_token_hereThe CLI reads this token for live API calls.
Run from repository root:
npx tsx scripts/x-search.ts <command> ...npx tsx scripts/x-search.ts search "your query" --max-results 50 --sort relevancynpx tsx scripts/x-search.ts read "https://x.com/user/status/1234567890"
npx tsx scripts/x-search.ts read 1234567890npx tsx scripts/x-search.ts thread 1234567890npx tsx scripts/x-search.ts timeline someuser --max-results 20npx tsx scripts/x-search.ts watchlist
npx tsx scripts/x-search.ts watchlist-add someuser --reason "Tracks industry shifts"
npx tsx scripts/x-search.ts watchlist-remove someuser--dry-runIf you are wiring this into an agent workflow:
- Read
SKILL.mdfirst for trigger conditions and research methodology. - Execute
scripts/x-search.tscommands withnpx tsx. - Parse stdout as JSON and then post-process/summarize.
- Include tweet URLs in outputs so claims are traceable.
- Decompose the user question into multiple search angles.
- Run multiple
searchcalls. - Expand high-signal results via
thread/read. - Use
engagement_ratio, recency, and content quality to filter. - Return both curated findings and raw tweets.
The CLI auto-creates config/cache directories as needed.
- Token file:
~/.openclaw/workspace/.env.x-api - Config:
~/.openclaw/workspace/skills/x-api/config.json - Cache base:
~/.openclaw/workspace/memory/x-cache/- Search cache:
search/(24h TTL) - Thread cache:
threads/(24h TTL) - User cache:
users/(1h TTL)
- Search cache:
.
├── SKILL.md
├── README.md
├── scripts/
│ ├── x-search.ts
│ └── lib/
│ ├── api.ts
│ ├── cache.ts
│ ├── format.ts
│ └── mock.ts
├── references/
│ └── x-api.md
└── evals/
└── eval_metadata.json
- Missing token: create
~/.openclaw/workspace/.env.x-apiwithX_BEARER_TOKEN=.... - 401 Unauthorized: token is invalid or revoked.
- 429 rate limit: CLI includes retry/backoff; wait and retry.
- Noisy results: tighten query with operators (see
references/x-api.md). - Old threads returning empty: threads older than 7 days fall outside the
search/recentwindow. The CLI automatically falls back to the author's timeline. Check thesourceandcompletefields in the response —"timeline_fallback"withcomplete: falsemeans the thread may be partial.
- No build step is required for basic use.
- This repo is script-first and intended to be run locally.