home / skills / openclaw / skills / gram

gram skill

/skills/arein/gram

This skill lets you view Instagram feeds, posts, and profiles via a cookie-authenticated CLI, enabling quick insights and engagement.

npx playbooks add skill openclaw/skills --skill gram

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
3.9 KB
---
name: gram
description: Instagram CLI for viewing feeds, posts, profiles, and engagement via cookies.
homepage: https://github.com/arein/gram
metadata: {"clawdbot":{"emoji":"📸","requires":{"bins":["gram"]},"install":[{"id":"npm","kind":"node","package":"@cyberdrk/gram","bins":["gram"],"label":"Install gram (npm)"}]}}
---

# gram 📸

Instagram CLI using REST/GraphQL API + cookie auth.

## Install

```bash
# npm/pnpm/bun
npm install -g @cyberdrk/gram

# One-shot (no install)
bunx @cyberdrk/gram whoami
```

## Authentication

`gram` uses cookie-based auth from your Instagram web session.

Use `--session-id`, `--csrf-token`, and `--ds-user-id` to pass cookies directly, or `--cookie-source` for browser cookies.

Run `gram check` to see which source is active. For Arc/Brave, use `--chrome-profile-dir <path>`.

## Commands

### Account & Auth

```bash
gram whoami                    # Show logged-in account
gram check                     # Show credential sources
gram query-ids --refresh       # Refresh GraphQL query ID cache
```

### Reading Posts

```bash
gram post <shortcode-or-url>   # View a post
gram <shortcode-or-url>        # Shorthand for post
gram comments <shortcode> -n 20 # View comments on a post
gram likers <shortcode>        # View users who liked a post
```

### Feeds

```bash
gram feed -n 20                # Home feed
gram explore -n 20             # Explore/discover feed
```

### User Profiles

```bash
gram user <username>           # View user profile
gram user @instagram --json    # JSON output
gram posts <username> -n 20    # User's posts
gram following [username]      # Users someone follows (defaults to you)
gram followers [username]      # Someone's followers (defaults to you)
```

### Search

```bash
gram search "query"            # Search users, hashtags, places
gram search "coffee" --type users
gram search "nyc" --type places
gram search "#photography" --type hashtags
```

### Engagement Actions

```bash
gram like <shortcode>          # Like a post
gram unlike <shortcode>        # Unlike a post
gram save <shortcode>          # Save/bookmark a post
gram unsave <shortcode>        # Unsave a post
gram comment <shortcode> "nice!" # Comment on a post
gram follow <username>         # Follow a user
gram unfollow <username>       # Unfollow a user
```

## Output Options

```bash
--json          # JSON output
--json-full     # JSON with raw API response in _raw field
--plain         # No emoji, no color (script-friendly)
--no-emoji      # Disable emoji
--no-color      # Disable ANSI colors (or set NO_COLOR=1)
```

## Global Options

```bash
--session-id <token>           # Instagram sessionid cookie
--csrf-token <token>           # Instagram csrftoken cookie
--ds-user-id <id>              # Instagram ds_user_id cookie
--cookie-source <source>       # Cookie source for browser cookies (repeatable)
--chrome-profile <name>        # Chrome profile name
--chrome-profile-dir <path>    # Chrome/Chromium profile dir or cookie DB path
--firefox-profile <name>       # Firefox profile
--timeout <ms>                 # Request timeout
--cookie-timeout <ms>          # Cookie extraction timeout
```

## Config File

`~/.config/gram/config.json5` (global) or `./.gramrc.json5` (project):

```json5
{
  cookieSource: ["safari", "chrome"],
  chromeProfile: "Profile 1",
  timeoutMs: 60000
}
```

Environment variables: `GRAM_TIMEOUT_MS`, `GRAM_COOKIE_TIMEOUT_MS`

## Troubleshooting

### Query IDs stale (404 errors)
```bash
gram query-ids --refresh
```

### Cookie extraction fails
- Check browser is logged into Instagram
- Try different `--cookie-source`
- For Arc/Brave: use `--chrome-profile-dir`
- Provide cookies manually: `--session-id`, `--csrf-token`, `--ds-user-id`

### User-agent mismatch errors
- The CLI uses desktop user-agent by default
- If your session was created on mobile, it may fail
- Create a new session by logging in via desktop browser

---

**TL;DR**: View feeds, profiles, search, and engage with Instagram via CLI. 📸

Overview

This skill is a command-line Instagram client for viewing feeds, posts, profiles, search results, and performing engagement actions using cookie-based authentication. It exposes a compact set of commands to read posts, browse feeds, inspect user profiles, and like/comment/follow directly from a terminal. It is designed for power users, scripts, and backups where a GUI is not required.

How this skill works

The tool talks to Instagram’s REST and GraphQL endpoints using cookies from your web session (sessionid, csrftoken, ds_user_id) or by extracting cookies from browser profiles. Commands map to API queries and return either human-readable text or JSON for scripting. Global flags and a config file let you control cookie sources, timeouts, and output format.

When to use it

  • Quickly inspect a post, comments, or likers without opening a browser
  • Automate reading or exporting feeds and profiles in scripts or cron jobs
  • Debug authentication or session issues for an account using cookie-based access
  • Perform lightweight engagement (like, comment, follow) from automation or CI
  • Search users/hashtags/places and fetch results as JSON for downstream tools

Best practices

  • Prefer browser cookie extraction for convenience, or pass --session-id, --csrf-token, and --ds-user-id for reproducible automation
  • Use --json or --json-full when piping output into tools or storing backups
  • Run gram query-ids --refresh if you see GraphQL 404s; keep query ID cache current
  • Set cookie-source and chrome/firefox profile options in config to avoid repeated interactive extraction
  • Use plain/no-emoji/no-color flags in scripts or when redirecting output to files

Example use cases

  • Fetch your home feed: gram feed -n 20 and process as JSON for analytics
  • Inspect a post and its comments: gram post <shortcode> or gram comments <shortcode> -n 50
  • Export a user’s recent posts: gram posts <username> -n 100 --json to archive media metadata
  • Automate engagement in a bot-like workflow: gram like <shortcode> and gram comment <shortcode> "Nice shot!" in a scheduled task
  • Search and combine results: gram search "coffee" --type places to populate a location database

FAQ

How do I authenticate without exposing my password?

Provide Instagram cookies (sessionid, csrftoken, ds_user_id) or let the tool extract cookies from an authenticated browser profile. No password is required.

What output formats are available for scripts?

Use --json or --json-full for structured output. Use --plain, --no-emoji, or --no-color to remove formatting for machine parsing.

I get 404s from GraphQL endpoints—what now?

Run gram query-ids --refresh to update the cached query IDs. If that fails, check cookie validity and your user-agent/session type.