npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@patrikbreitenmoser/x-cli

v1.0.3

Published

CLI tool for querying the X (Twitter) API v2

Readme

x-cli

A command-line tool for the X (Twitter) API v2. Look up users, fetch tweets, sync bookmarks, and manage a follow list from the terminal with agent-friendly output.

Install globally:

npm install -g @patrikbreitenmoser/x-cli

Requirements

  • Node.js 18 or newer
  • An X developer app with OAuth 2.0 enabled

Create your app at developer.x.com.

Required scopes:

  • bookmark.read
  • tweet.read
  • users.read
  • offline.access

Install

The package name is @patrikbreitenmoser/x-cli, but the command you run is always x-cli.

Run without installing globally

npx @patrikbreitenmoser/x-cli --help

Install globally

npm install -g @patrikbreitenmoser/x-cli
x-cli --help

Install in a project

npm install @patrikbreitenmoser/x-cli
npx x-cli --help

Quick Start

  1. Authenticate with your X app credentials:

    x-cli auth login
  2. Complete the browser-based OAuth authorization flow.

  3. Start using the CLI:

    x-cli auth status
    x-cli user elonmusk
    x-cli tweets elonmusk --limit 10

Before login, make sure ~/.x-cli/credentials.json contains your X app client ID:

{
  "clientId": "YOUR_CLIENT_ID"
}

Authentication

x-cli auth login opens a browser window for OAuth authorization. It reads clientId from ~/.x-cli/credentials.json. If your app also requires a client secret for token exchange, keep clientSecret in the same file or pass --client-secret. After a successful login, credentials and tokens are stored in ~/.x-cli/credentials.json with owner-only permissions. Access tokens refresh automatically.

Useful auth commands:

x-cli auth status
x-cli auth logout

Common Commands

Home view

x-cli
x-cli --format json

Running x-cli with no subcommand prints a compact dashboard with auth status, follow-list count, sync state, and suggested next steps.

User lookup

x-cli user elonmusk
x-cli user alice bob charlie

Tweets

x-cli tweets elonmusk --limit 10
x-cli tweets alice bob --since 2026-01-01
x-cli tweets elonmusk --no-replies --no-retweets
x-cli tweets alice --fields url,attachments
x-cli tweets alice --full

Bookmarks

x-cli bookmarks
x-cli bookmarks --limit 50
x-cli bookmarks --all
x-cli bookmarks --all --full

bookmarks uses incremental sync by default. After the first run, it only returns bookmarks newer than the last saved bookmark ID.

Follow list

Manage a local follow list. When you run tweets with no targets, x-cli uses this list automatically.

x-cli follows add alice bob naval
x-cli follows remove bob
x-cli follows list
x-cli tweets

When x-cli tweets runs against the follow list, it also tracks the last sync timestamp and fetches only newer tweets on later runs unless you pass --since.

Output

All command results are written as structured data to stdout. The default format is TOON for lower token usage; use --format json for compatibility with JSON consumers. Status and diagnostic messages go to stderr.

x-cli tweets elonmusk
x-cli tweets elonmusk --format json | jq '.tweets[].text'
x-cli bookmarks --all --format json > bookmarks.json

Most list commands now default to compact fields. Use --fields <name,...> or --full to request expanded output.

Hooks

x-cli can install managed Codex and Claude session-start hooks if you want agents to start with a compact dashboard. Hook changes are explicit:

x-cli hooks status
x-cli hooks install
x-cli hooks uninstall

Data Storage

All local state is stored in ~/.x-cli/:

| File | Contents | |------|----------| | credentials.json | OAuth tokens and client credentials | | sync-state.json | Last sync timestamps and bookmark cursor | | follows.json | Local follow list |

The directory is created with mode 0700. Files are written with mode 0600.

Developer Setup

If you want to work on the CLI itself instead of consuming the npm package:

npm install
npm run build

Useful development commands:

npm run dev -- --help
npm run dev -- auth login
npm run dev -- tweets elonmusk --limit 10
node dist/index.js --help
npm test

Notes:

  • npm run build compiles TypeScript to dist/ and makes dist/index.js executable.
  • npm run dev -- ... runs the TypeScript entrypoint directly with tsx.
  • prepublishOnly runs npm run build before publishing.

License

MIT