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

@cyberdrk/gram

v0.1.0

Published

CLI tool for interacting with Instagram via GraphQL/REST API

Readme

Gram

A CLI tool for interacting with Instagram via their undocumented GraphQL/REST API using cookie-based authentication.

Disclaimer

This project uses Instagram's undocumented web API (and cookie auth). Instagram can change endpoints, query IDs, and anti-bot behavior at any time — expect this to break without notice.

Install

npm install -g @arein/gram
# or
pnpm add -g @arein/gram
# or
bun add -g @arein/gram

# one-shot (no install)
bunx @arein/gram whoami

Quickstart

# Show the logged-in account
gram whoami

# View your home feed
gram feed
gram feed --count 50

# View the explore/discover feed
gram explore

# View a post
gram post CxyzABC1234
gram https://www.instagram.com/p/CxyzABC1234/

# View a user profile
gram user instagram
gram user @instagram --json

# Search for users, hashtags, places
gram search "coffee shop"
gram search "photography" --type hashtags

# Like/unlike posts
gram like CxyzABC1234
gram unlike CxyzABC1234

Commands

Feed Commands

  • gram feed [-n count] [--json] [--json-full] — get your home feed
  • gram explore [-n count] [--json] [--json-full] — get the explore/discover feed

Post Commands

  • gram post <shortcode-or-url> [--json] [--json-full] — view a post by shortcode or URL
  • gram comments <shortcode> [-n count] [--json] — view comments on a post
  • gram likers <shortcode> [--json] — view users who liked a post
  • gram <shortcode-or-url> — shorthand for gram post <shortcode-or-url>

User Commands

  • gram user <username> [--json] — view a user profile
  • gram posts <username> [-n count] [--json] — get a user's posts
  • gram following [username] [-n count] [--json] — get users that someone follows (defaults to you)
  • gram followers [username] [-n count] [--json] — get someone's followers (defaults to you)

Search

  • gram search <query> [--type <type>] [--json] — search for users, hashtags, and places
    • Types: blended (default), users, hashtags, places

Engagement

  • gram like <shortcode> — like a post
  • gram unlike <shortcode> — unlike a post
  • gram save <shortcode> — save/bookmark a post
  • gram unsave <shortcode> — unsave/unbookmark a post
  • gram comment <shortcode> "<text>" — comment on a post
  • gram follow <username> — follow a user
  • gram unfollow <username> — unfollow a user

Account

  • gram whoami [--json] — show the currently authenticated user
  • gram check — check credential availability and sources

Query IDs

  • gram query-ids [--refresh] [--json] — inspect or refresh cached GraphQL query IDs

Authentication

Gram uses your existing Instagram web session. It resolves credentials in this order:

  1. CLI flags: --session-id, --csrf-token, --ds-user-id
  2. Environment variables: SESSION_ID, CSRF_TOKEN, DS_USER_ID (or prefixed with INSTAGRAM_/IG_)
  3. Browser cookies via @steipete/sweet-cookie (Safari, Chrome, Firefox)

Required Cookies

  • sessionid — Your Instagram session cookie
  • csrftoken — Cross-site request forgery token
  • ds_user_id — Your user ID (optional but recommended)

Browser Cookie Sources

  • Safari: ~/Library/Cookies/Cookies.binarycookies
  • Chrome: ~/Library/Application Support/Google/Chrome/<Profile>/Cookies
  • Firefox: ~/Library/Application Support/Firefox/Profiles/<profile>/cookies.sqlite

Override browser order via --cookie-source (repeatable).

Config (JSON5)

Config precedence: CLI flags > env vars > project config > global config.

  • Global: ~/.config/gram/config.json5
  • Project: ./.gramrc.json5

Example ~/.config/gram/config.json5:

{
  // Cookie source order for browser extraction
  cookieSource: ["safari", "chrome", "firefox"],
  chromeProfile: "Profile 1",
  chromeProfileDir: "/path/to/Chrome/Profile",
  firefoxProfile: "default-release",
  cookieTimeoutMs: 30000,
  timeoutMs: 60000
}

Environment shortcuts:

  • GRAM_TIMEOUT_MS
  • GRAM_COOKIE_TIMEOUT_MS

Global Options

  • --session-id <token>: Instagram sessionid cookie
  • --csrf-token <token>: Instagram csrftoken cookie
  • --ds-user-id <id>: Instagram ds_user_id cookie
  • --cookie-source <safari|chrome|firefox>: browser cookie source (repeatable)
  • --chrome-profile <name>: Chrome profile name
  • --chrome-profile-dir <path>: Chrome/Chromium profile directory
  • --firefox-profile <name>: Firefox profile name
  • --cookie-timeout <ms>: cookie extraction timeout (milliseconds)
  • --timeout <ms>: request timeout (milliseconds)
  • --plain: stable output (no emoji, no color)
  • --no-emoji: disable emoji output
  • --no-color: disable ANSI colors (or set NO_COLOR=1)

Output Formats

  • Default: Human-readable terminal output with emoji
  • --json: Machine-readable JSON
  • --json-full: JSON with raw API response in _raw field
  • --plain: Stable output without emoji or colors

Library Usage

Gram can be used as a library:

import { InstagramClient, resolveCredentials } from '@arein/gram';

const { cookies } = await resolveCredentials({ cookieSource: 'safari' });
const client = new InstagramClient({ cookies });

// Get user profile
const userResult = await client.getUser('instagram');
if (userResult.success) {
  console.log(userResult.user);
}

// Get home feed
const feedResult = await client.getHomeFeed();
if (feedResult.success) {
  console.log(feedResult.posts);
}

// Like a post
const post = await client.getPost('CxyzABC1234');
if (post.success) {
  await client.like(post.post.id);
}

// Search
const searchResult = await client.search('coffee', 'users');

Query IDs

Instagram's web app uses query IDs that rotate periodically. Gram:

  1. Ships with baseline IDs in src/lib/query-ids.json
  2. Caches runtime-discovered IDs at ~/.config/gram/query-ids-cache.json (24h TTL)
  3. Can refresh on demand via gram query-ids --refresh

Override cache path: GRAM_QUERY_IDS_CACHE=/path/to/file.json

Development

pnpm install
pnpm run build        # dist/ + bun binary
pnpm run build:dist   # dist/ only
pnpm test
pnpm run lint

License

MIT