X twitter

From mvanhorn/printing-press-library · View interactive version

X twitter is an AI agent skill from the GitHub repository mvanhorn/printing-press-library. Offline-searchable X/Twitter CLI and MCP surface for archiving posts, resolving links, monitoring mentions, composing threads, publishing Articles, and searching synced bookmarks. Trigger phrases: `search X for`, `archive tweets about`, `show me the X thread for`, `monitor my X mentions`, `post a th

How to use this skill

Skill file

X (Twitter) — Printing Press CLI

Prerequisites: Install the CLI

This skill drives the x-twitter-pp-cli binary. You must verify the CLI is installed before invoking any command from this skill. If it is missing, install it first:

  1. Install via the Printing Press installer. It defaults binaries to $HOME/.local/bin on macOS/Linux and %LOCALAPPDATA%\Programs\PrintingPress\bin on Windows:

```bash

npx -y @mvanhorn/printing-press-library install x-twitter --cli-only

```

  1. Verify: x-twitter-pp-cli --version
  2. Ensure the reported install directory is on $PATH for the agent/runtime that will invoke this skill.

If the npx install fails (no Node, offline, etc.), fall back to a direct Go install (requires Go 1.26.6 or newer). This installs into $GOPATH/bin (default $HOME/go/bin), so add that directory to $PATH instead:

go install github.com/mvanhorn/printing-press-library/library/social-and-messaging/x-twitter/cmd/x-twitter-pp-cli@latest

If --version reports "command not found" after install, the runtime cannot see the binary directory on $PATH. Do not proceed with skill commands until verification succeeds.

Mirrors the official X v2 API and adds what no other X tool has: a local SQLite store you can sync once and query many times with FTS5 search and group-by analytics, agent-native --json/--select output, and an MCP server that exposes the whole surface to AI agents through token-efficient orchestration plus named multi-step intents. Start pasted-link workflows with post resolve, use thread context when a post needs parent/quote/reply context, save durable source material with collection save/list/export, track ongoing searches with monitor create/run/list, package saved activity with brief, snapshot accounts with account snapshot, find launch or repo links with url mentions, track post metrics with performance snapshot/backfill/analyze, export account/query timelines with timeline export, reconstruct synced conversation threads offline with thread show, compose self-reply threads from markdown with thread compose, author long-form X Articles from markdown with articles-publish-md, and rescue your bookmark graveyard with users bookmarks find — keyword and author search over your synced bookmarks, which X itself gives you no way to search.

When to Use This CLI

For a ranked readout of recent posts, run x-twitter-pp-cli top-posts --metric engagement --limit 10 --max-fetch 100 --json. It reads the live X timeline, so each page may use paid API credits. --max-fetch accepts 1 to 1000 posts, with a small extra-page budget for sparse responses. A leaderboard returned at that budget is partial and has truncated: true in every JSON row. --user-id selects a numeric account ID without a separate username lookup; without it, the command uses the authenticated user. JSON rows name the effective score_metric, and missing impression scores are null rather than zero. --dry-run makes no request.

Reach for this CLI when a task involves reading, searching, or archiving X (Twitter) data and you want the results queryable offline rather than re-fetched each time — building a searchable corpus of posts, reconstructing a conversation thread, snapshotting a user's recent posts with engagement, or monitoring mentions incrementally. It is also the right choice when an AI agent needs an X surface with read-only/destructive safety hints and named multi-step intents rather than a pile of raw endpoint calls. Prefer it over raw API calls whenever the same data will be queried more than once, since the local store avoids re-spending per-read credits.

Unique Capabilities

These capabilities aren't available in any other tool for this API.

Local state that compounds

_Use this as the first command when an agent starts from a pasted X link. It avoids brittle URL parsing and returns stable fields for downstream workflows._

```bash

x-twitter-pp-cli post resolve https://x.com/user/status/123 --agent

x-twitter-pp-cli post resolve 123 --include author,media,links,refs,metrics --agent

```

_Use this before summarizing or drafting around a post. thread show is still the pure offline conversation reconstruction command; thread context is the URL-first workflow that can mix local and live data._

```bash

x-twitter-pp-cli thread context https://x.com/user/status/123 --agent

x-twitter-pp-cli thread context 123 --replies --depth 3 --limit 100 --agent

```

_Use collections for research libraries, launch mentions, examples, recruiting/source material, and anything an agent should reuse offline after the first API read._

```bash

x-twitter-pp-cli collection save https://x.com/user/status/123 --collection ai-agents --note "Good framing" --agent

x-twitter-pp-cli collection list ai-agents --agent

x-twitter-pp-cli collection export ai-agents --format markdown

```

_Use monitors for launch mentions, product/customer feedback, account tracking, and recurring agent jobs. --since last uses the saved watermark; --preview fetches without updating local state._

```bash

x-twitter-pp-cli monitor create ai-labs --query 'from:openai OR from:anthropic' --agent

x-twitter-pp-cli monitor create product-mentions --url https://example.com --agent

x-twitter-pp-cli monitor run ai-labs --since last --agent

x-twitter-pp-cli monitor list --agent

```

_Use this when an agent needs a daily/weekly X activity packet or a collection summary that can be pasted into notes, docs, or a CRM._

```bash

x-twitter-pp-cli brief --monitor ai-labs --since 24h --agent

x-twitter-pp-cli brief --collection launch-feedback --format markdown

```

```bash

x-twitter-pp-cli account snapshot @username --recent 20 --agent

x-twitter-pp-cli account snapshot 12345 --include recent,profile,metrics,pinned --format markdown

```

```bash

x-twitter-pp-cli url mentions https://example.com --since 7d --agent

x-twitter-pp-cli url mentions github.com/org/repo --collection launch-feedback --monitor repo-links --agent

```

```bash

x-twitter-pp-cli performance snapshot --ids 123,456 --label 24h --agent

x-twitter-pp-cli performance backfill --mine --days 90 --agent

x-twitter-pp-cli performance analyze --since 90d --group-by type,hour,has_media,has_link --agent

```

```bash

x-twitter-pp-cli timeline export @username --since 30d --format markdown

x-twitter-pp-cli timeline export --query 'ai agents' --since 7d --format jsonl

```

_When an agent needs the shape of a discussion (who replied to whom, in order), reach for this instead of paginating the search API and re-assembling the tree by hand._

```bash

x-twitter-pp-cli thread show 1750000000000000000 --agent

```

_The "I bookmarked something about this and can't find it" rescue. Sync bookmarks once, then let an agent retrieve and act on them (summarize, draft a thread, cluster) — the offline store is the agent's working set, not a per-query API spend._

```bash

# one-time populate (personal read — needs X_OAUTH2_USER_TOKEN); add author field + users for --from

x-twitter-pp-cli sync --resources bookmarks --param tweet.fields=author_id,created_at

x-twitter-pp-cli sync --resources users

x-twitter-pp-cli users bookmarks find "rust async" --agent

x-twitter-pp-cli users bookmarks find "llm" --from @karpathy --limit 20 --agent

```

Authoring workflows

_Compose a thread from a document deterministically; the dry-run default lets an agent preview the exact tweets before any write._

```bash

x-twitter-pp-cli thread compose ./update.md

```

_The only programmatic way to author a long-form X Article from a document; preview, --draft, and --update keep it private until you explicitly --post._

The converter supports paragraphs, #/## headers (### and deeper are downgraded to ##), lists, blockquotes, fenced code blocks, tables, dividers, image lines (![alt](path)), standalone tweet URLs (native embedded posts: put https://x.com/<user>/status/<id> alone on its own line), bold/italic inline styles (including inside blockquotes; backtick code spans become plain text because X Articles has no inline code style), and [text](url) inline links, which become real LINK entities (working hyperlinks) in the article. Lines that are HTML comments (<!-- ... -->) are stripped and never ship as article text.

```bash

x-twitter-pp-cli articles-publish-md ./post.md

x-twitter-pp-cli articles-publish-md ./post.md --update 1750000000000000000

```

_Edit the markdown, re-run one command. No duplicate drafts: the draft keeps its id, so the edit URL and any saved state stay valid._

```bash

x-twitter-pp-cli articles update-md ./post.md --article-id 1750000000000000000 --agent

```

WARNING — body replacement: articles update-md replaces the ENTIRE body of the target draft. Anything added by hand in the X composer that the markdown converter cannot reproduce is destroyed by the update. The command preflights the draft's content_state and refuses when it finds entity types outside the converter's emit set (LINK, MARKDOWN, MEDIA, TWEET, DIVIDER); pass --replace-unknown-entities only when you genuinely want to overwrite those artifacts. Markdown-authored content round-trips cleanly; if a draft holds composer-only embeds or other manual artifacts, edit it in the composer instead.

Draft-only by default: a published article is refused unless you pass --republish, which runs Unpublish -> UpdateContent -> Publish (the article is briefly unpublished). Use --dry-run to preview the converted payload with no API call.

_Use this instead of update-md for an article that already has images or composer edits: nothing outside the patch changes, and no image is re-uploaded._

```markdown

<!-- after: The other machines should appear in the list. -->

Here is the post where I said so:

https://x.com/cathrynlavery/status/2103588600076214414

<!-- before: The checklist -->

## A new section

Text, lists, links and fenced code work as in articles-publish-md.

<!-- replace: I installed five apps: => I installed four apps: -->

```

```bash

x-twitter-pp-cli articles patch-md ./edits.md --article-id 1750000000000000000 --dry-run --agent # plan + full body, no write

x-twitter-pp-cli articles patch-md ./edits.md --article-id 1750000000000000000 --republish --agent # published article

```

An anchor is the start of an existing paragraph or heading and must match exactly one block; a replace target must appear exactly once and may not cut across a link or bold span. Any miss stops the command before it writes. --dry-run still reads the article (it needs the real body) but never writes. Published articles need --republish (the same Unpublish -> UpdateContent -> Publish sequence the composer uses; the post, its URL and its likes stay). If your cookies were captured without twid, set X_TWITTER_USER_ID=<your numeric id>.

Command Reference

account-activity — Endpoints relating to retrieving, managing AAA subscriptions

activity — Manage activity

chat — Manage chat

communities — Manage communities

compliance — Endpoints related to keeping X data in your systems compliant

connections — Endpoints related to streaming connections

dm-conversations — Manage dm conversations

dm-events — Manage dm events

evaluate-note — Manage evaluate note

insights — Manage insights

lists — Endpoints related to retrieving, managing Lists

media — Endpoints related to Media

news — Endpoint for retrieving news stories

notes — Manage notes

openapi-json — Manage openapi json

spaces — Endpoints related to retrieving, managing Spaces

trends — Manage trends

tweets — Endpoints related to retrieving, searching, and modifying Tweets

usage — Manage usage

users — Endpoints related to retrieving, managing relationships of Users

webhooks — Manage webhooks

Finding the right command

When you know what you want to do but not which command does it, ask the CLI directly:

x-twitter-pp-cli which "<capability in your own words>"

which resolves a natural-language capability query to the best matching command from this CLI's curated feature index. Exit code 0 means at least one match; exit code 2 means no confident match — fall back to --help or use a narrower query.

Recipes

Archive a topic, then query it offline

x-twitter-pp-cli sync --resources tweets --since 24h && x-twitter-pp-cli search "ai agents" --type tweets --limit 50

Sync once into SQLite, then run as many offline FTS queries as you want without further API reads.

Agent-friendly field projection on a large response

x-twitter-pp-cli search "openai" --type tweets --agent --select id,text,author_id,public_metrics.like_count

Posts carry large nested payloads; --agent + --select trims the response to just the fields an agent needs, keeping context cheap.

Reconstruct a conversation thread offline

x-twitter-pp-cli thread show 1750000000000000000 --agent

Walks the synced posts joined on conversation_id and referenced_tweets into an ordered, depth-tagged tree — no API call.

Compose a self-reply thread from a document (dry-run by default)

x-twitter-pp-cli thread compose ./release-notes.md

Splits the markdown into a numbered 280-char-packed self-reply thread and prints it; add --post to actually publish.

Auth Setup

X auth has three separate lanes. Do not infer one lane from another; run x-twitter-pp-cli doctor --json and inspect auth_lanes before choosing a command.

Setup sequence:

  1. Attach the app to a Project in the X developer console.
  2. Set app permissions to Read and write when you need posting or other mutations.
  3. Copy the app Bearer Token and run x-twitter-pp-cli auth set-bearer-token <bearer-token> for app-only public reads. Environment alternative: set X_BEARER_TOKEN in your shell or runtime secret manager.
  4. Enable OAuth2 with suitable scopes such as tweet.read, tweet.write, users.read, offline.access, bookmark.read, like.read, like.write, follows.read, and follows.write. Add http://127.0.0.1:8787/callback as an OAuth2 redirect URI in the X developer app, then run x-twitter-pp-cli auth oauth2-login --client-id <oauth2-client-id> to complete the authorization-code + PKCE browser flow. Non-interactive fallback when you already have tokens: x-twitter-pp-cli auth import-oauth2 --client-id <oauth2-client-id> --access-token <oauth2-access-token> --refresh-token <oauth2-refresh-token> --scopes tweet.read,tweet.write,users.read,offline.access,bookmark.read,like.read,like.write,follows.read,follows.write. Environment alternative: set X_OAUTH2_USER_TOKEN in your shell or runtime secret manager.
  5. Separately run x-twitter-pp-cli auth login --chrome only when using articles ... commands.

auth set-token is deprecated because “token” is ambiguous for X. It remains as a compatibility alias for auth set-bearer-token and must not be used for OAuth2 user-context tokens. Use auth oauth2-login for the interactive OAuth2 browser flow or auth import-oauth2 when you already have tokens.

doctor --json is the machine-readable preflight. It reports selected_profile, per-lane status, /2/users/me probe results, authenticated user identity when returned, stored scopes, missing workflow scopes, token expiry, refresh-token presence, and X Articles cookie status without printing secrets.

When X returns Unsupported Authentication with Application-Only is forbidden, the command requires OAuth2 user-context auth. Fix auth_lanes.oauth2_user_context; cookie auth and app-only bearer auth will not satisfy that endpoint.

Raw API Escape Hatch

Use raw only for debugging new X endpoints, auth-lane behavior, or API errors when no generated command fits yet. It accepts relative API paths or allowlisted HTTPS X absolute URLs, repeatable query params and headers, and JSON bodies from --body, --body-file, or --body @-.

x-twitter-pp-cli raw GET /2/users/me --agent
x-twitter-pp-cli raw GET /2/tweets --param ids=123,456 --json
x-twitter-pp-cli raw POST /2/tweets --body '{"text":"hello"}' --dry-run --agent

Generated commands remain preferred for normal workflows because they include endpoint-specific validation, pagination, provenance, response envelopes, and workflow hints. raw preserves the upstream response body while using the same auth lanes as every other command: app-only public reads still need X_BEARER_TOKEN; user-context reads and writes still need X_OAUTH2_USER_TOKEN or an imported OAuth2 user-context token.

Agent Mode

Add --agent to any command. Expands to: --json --compact --no-input --no-color --yes.

```bash

x-twitter-pp-cli communities search --query example-value --agent --select id,name,status

```

Response envelope

Commands that read from the local store or the API wrap output in a provenance envelope:

{
  "meta": {"source": "live" | "local", "synced_at": "...", "reason": "..."},
  "results": <data>
}

Parse .results for data and .meta.source to know whether it's live or local. A human-readable N results (live) summary is printed to stderr only when stdout is a terminal AND no machine-format flag (--json, --csv, --compact, --quiet, --plain, --select) is set — piped/agent consumers and explicit-format runs get pure JSON on stdout.

Agent Feedback

When you (or the agent) notice something off about this CLI, record it:

x-twitter-pp-cli feedback "the --since flag is inclusive but docs say exclusive"
x-twitter-pp-cli feedback --stdin < notes.txt
x-twitter-pp-cli feedback list --json --limit 10

Entries are stored locally at ~/.local/share/x-twitter-pp-cli/feedback.jsonl. They are never POSTed unless X_TWITTER_FEEDBACK_ENDPOINT is set AND either --send is passed or X_TWITTER_FEEDBACK_AUTO_SEND=true. Default behavior is local-only.

Write what surprised you, not a bug report. Short, specific, one line: that is the part that compounds.

Output Delivery

Every command accepts --deliver <sink>. The output goes to the named sink in addition to (or instead of) stdout, so agents can route command results without hand-piping. Three sinks are supported:

| Sink | Effect |

|------|--------|

| stdout | Default; write to stdout only |

| file:<path> | Atomically write output to <path> (tmp + rename) |

| webhook:<url> | POST the output body to the URL (application/json or application/x-ndjson when --compact) |

Unknown schemes are refused with a structured error naming the supported set. Webhook failures return non-zero and log the URL + HTTP status on stderr.

Named Profiles

A profile is a saved set of flag values, reused across invocations. Use it when a scheduled agent calls the same command every run with the same configuration - HeyGen's "Beacon" pattern.

x-twitter-pp-cli profile save briefing --json
x-twitter-pp-cli --profile briefing communities search --query example-value
x-twitter-pp-cli profile list --json
x-twitter-pp-cli profile show briefing
x-twitter-pp-cli profile delete briefing --yes

Explicit flags always win over profile values; profile values win over defaults. agent-context lists the selected store's profiles under available_profiles. By default, saved profiles live in ~/.x-twitter-pp-cli/profiles.json even when --config selects a different credential file. Pass --profile-store <path> consistently when saving, listing, applying, or discovering a separate set of flag presets. The selector cannot be stored in a profile and does not change credentials or the SQLite store.

Async Jobs

For endpoints that submit long-running work, the generator detects the submit-then-poll pattern (a job_id/task_id/operation_id field in the response plus a sibling status endpoint) and wires up three extra flags on the submitting command:

| Flag | Purpose |

|------|---------|

| --wait | Block until the job reaches a terminal status instead of returning the job ID immediately |

| --wait-timeout | Maximum wait duration (default 10m, 0 means no timeout) |

| --wait-interval | Initial poll interval (default 2s; grows with exponential backoff up to 30s) |

Use async submission without --wait when you want to fire-and-forget; use --wait when you want one command to return the finished artifact.

Exit Codes

| Code | Meaning |

|------|---------|

| 0 | Success |

| 2 | Usage error (wrong arguments) |

| 3 | Resource not found |

| 4 | Authentication required |

| 5 | API error (upstream issue) |

| 7 | Rate limited (wait and retry) |

| 10 | Config error |

Argument Parsing

Parse $ARGUMENTS:

  1. Empty, help, or --help → show x-twitter-pp-cli --help output
  2. Starts with install → ends with mcp → MCP installation; otherwise → see Prerequisites above
  3. Anything else → Direct Use (execute as CLI command with --agent)

MCP Server Installation

  1. Install the MCP server:

```bash

go install github.com/mvanhorn/printing-press-library/library/social-and-messaging/x-twitter/cmd/x-twitter-pp-mcp@latest

```

  1. Register with Claude Code:

```bash

claude mcp add x-twitter-pp-mcp -- x-twitter-pp-mcp

```

  1. Verify: claude mcp list

Direct Use

  1. Check if installed: which x-twitter-pp-cli

If not found, offer to install (see Prerequisites at the top of this skill).

  1. Match the user query to the best command from the Unique Capabilities and Command Reference above.
  2. Execute with the --agent flag:

```bash

x-twitter-pp-cli <command> [subcommand] [args] --agent

```

  1. If ambiguous, drill into subcommand help: x-twitter-pp-cli <command> --help.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.