CLI Reference

Complete documentation for every ig command and flag. The search subcommand is the default — most commands listed here have no required subcommand prefix.

ig index

Build or rebuild the sparse n-gram index for a directory. Creates .ig/ with three binary files: lexicon.bin, postings.bin, and metadata.bin. Called automatically by ig search when no index exists.

syntax
ig index [OPTIONS]   # default: current directory
examples
# Index current directory
ig index

# Index specific path
ig index /path/to/project

# Force rebuild (even if index exists)
ig index --force .

ig status

Display statistics about the current index — file count, index size, n-gram count, version, and last build time.

output example
ig status .

instant-grep index status
──────────────────────────
Location:    /home/user/project/.ig/
Version:     7
Files:       1,552
N-grams:     48,392
Lexicon:     31 MB
Postings:    7.1 MB
Metadata:    111 KB
Built:       2026-03-24 10:12:08

ig watch

Watch a directory for file changes and automatically rebuild the index when files are created, modified, or deleted. The index stays fresh without manual intervention.

usage
# Watch and auto-rebuild on changes
ig watch .

[watching] src/ — press Ctrl+C to stop
[rebuild]  src/main.rs modified → rebuilding... done (43ms)
[rebuild]  src/lib.rs created → rebuilding... done (51ms)

Combine with ig daemon start for best results: watch keeps the index fresh, daemon keeps it in memory. Together they give you permanent sub-ms search on a live codebase.

ig daemon

Manage the background daemon — a Unix socket server that keeps the index mmap'd in process memory. Full lifecycle: start, stop, check status, or install as a launchd service for auto-restart on macOS. Use ig query to send queries to the running daemon.

syntax
ig daemon start     [PATH]   # start daemon in background
ig daemon stop      [PATH]   # stop running daemon
ig daemon status    [PATH]   # check if daemon is running
ig daemon install   [PATH]   # install launchd service (macOS auto-restart)
ig daemon uninstall [PATH]   # remove launchd service
usage
# Start daemon
ig daemon start .

[daemon] Daemon started
[daemon] Socket: .ig/daemon.sock
[daemon] Index loaded: 1,552 files (36 MB)
[daemon] Ready for queries...

# Check status
ig daemon status .
[daemon] Running (PID 12345) · socket: .ig/daemon.sock

# Install as launchd service for auto-restart (macOS)
ig daemon install .

ig query

Send a query to a running daemon via Unix socket. Same interface as ig search but routes through the socket. Requires ig daemon to be running.

syntax
ig query [OPTIONS] <PATTERN> [PATH]
examples
# Query daemon (sub-ms)
ig query "async fn" .

# JSON output via daemon
ig query --json "Result<" .

# p50 latency: 0.3ms (warm daemon)

ig files

List all project files, respecting .gitignore and default exclusions. Ideal for AI agents needing a file inventory before deciding what to read.

syntax
ig files [OPTIONS] [PATH]
Flag Short Description
--compactTree-compressed listing — groups files by directory with counts and extension breakdown
--type EXT-tFilter by file extension
--glob PATTERN-gFilter files by glob pattern
--jsonOutput results as JSON (for AI agents)
examples
# List all project files
ig files

# Only Rust files
ig files -t rust

# JSON output for agents
ig files --json

# With glob filter
ig files -g "src/**/*.ts"

# Tree-compressed view — directories with file counts
ig files --compact

# Compact view filtered to PHP files
ig files --compact -t php

Auto-compact on pipe v1.10.0

When stdout is a pipe and the listing has 40+ files, ig files emits a one-line aggregate instead of enumerating every path. A TTY or IG_COMPACT=0 keeps the verbose listing.

example
$ ig files | head
3201 files in 911 dirs · 972 tsx, 890 php, 790 ts, 80 mdx, 70 py, 47 json
(compact view set IG_COMPACT=0 or run in a TTY for the full listing)

# iautos monorepo: 176 KB → 149 B (≈1180×)

ig symbols

Extract symbol definitions (functions, classes, structs, interfaces) from source files. Language-aware patterns for Rust, TypeScript, Python, Go, PHP, and more.

syntax
ig symbols [OPTIONS] [PATH]
examples
# All symbols in project
ig symbols

# Only Rust symbols
ig symbols -t rust

# JSON output (for agents)
ig symbols --json

# Symbols in specific directory
ig symbols src/

ig context

Show the full code block (function, class, struct) containing a specific line. Automatically detects block boundaries using brace matching or indentation.

syntax
ig context <FILE> <LINE>
examples
# Show function containing line 42
ig context src/main.rs 42

# JSON output
ig context --json src/main.rs 42

ig ls

Compact directory listing optimized for AI agents. Groups files by directory, shows file counts, and respects .gitignore and default exclusions. Generates a tree-like overview without the noise.

syntax
ig ls [PATH]   # default: current directory
examples
# Compact listing of current project
ig ls

src/          (12 files)
  index/      (6 files)  ngram.rs  reader.rs  writer.rs  ...
  query/      (2 files)  extract.rs  mod.rs
  main.rs  daemon.rs  read.rs  smart.rs

# Listing a subdirectory
ig ls src/

ig read

Smart file reading with multiple compression modes. Full mode returns the complete file; --signatures extracts only function/class/struct definitions — dramatically reducing tokens when an AI agent only needs the API surface. Advanced modes offer aggressive compression, token budgets, relevance boosting, and delta views.

syntax
ig read <FILE> [OPTIONS]
Flag Short Description
--signatures-sSignatures only — function/class/struct definitions
--aggressive-aStrip comments, collapse blanks, elide function bodies. Keep signatures + struct fields
--budget N-b NMax output tokens — uses entropy scoring to keep the most informative lines
--relevance PAT-r PATBoost score for lines matching pattern. Best combined with -b
--delta-dShow only git-changed lines with enclosing function context
examples
# Full file content
ig read src/daemon.rs

# Signatures only (functions + structs — much smaller)
ig read -s src/daemon.rs

pub fn start_daemon(path: &Path) -> Result<()>
pub fn stop_daemon(path: &Path) -> Result<()>
pub async fn handle_connection(stream: UnixStream)

# Aggressive compression — strip comments, collapse blanks, elide bodies
ig read -a src/daemon.rs

# Budget mode — keep the 500 most informative tokens
ig read -b 500 src/daemon.rs

# Budget + relevance boost — prioritize payment-related code
ig read -b 500 -r "payment" src/billing.php

# Delta mode — only git-changed lines with enclosing signatures
ig read -d src/main.rs

ig smart

Generate 2-line heuristic summaries for every file in the project. Each summary captures the file's purpose in minimal tokens — ideal for giving an AI agent a high-level map before deciding which files to read in full.

syntax
ig smart [PATH]   # default: current directory
examples
# 2-line summaries for all project files
ig smart

src/daemon.rs
  Unix socket server — start/stop/status/install lifecycle.
  Keeps index mmap'd for sub-ms query latency.

src/index/ngram.rs
  Sparse n-gram generation via hash_bigram + covering set selection.
  Core algorithm — port of danlark1/sparse_ngrams.

Directory aggregate mode v1.10.0

When the target is a directory and stdout is a pipe, ig smart emits a one-block structural summary instead of reading every file. The per-file mode was O(N files) — hitting 5+ seconds on a 1000-file subtree — and produced a wall of text an agent rarely needs in full. The aggregate is three lines, fast, and usually more useful for orienting in an unfamiliar codebase.

example
$ ig smart apps/api
apps/api: 1042 files, 249 dirs · 890 php, 39 yaml, 31 twig, 29 sh, 10 md
top: src/ (664), migrations/ (109), tests/ (103), config/ (42)
key: composer.json, README.md, Makefile

# 345 B / 19 ms — down from 69 KB / 5.3 s (≈200× smaller, ≈280× faster)
# Force full per-file summary: IG_COMPACT=0 ig smart apps/api

ig pack New in v1.3

Generate a .ig/context.md file — a structured project snapshot for AI agents. Includes directory tree, symbol definitions, dependencies (Cargo.toml / package.json), API routes (Next.js), and environment variables (.env.example). Replaces manual context-building.

syntax
ig pack [PATH]   # writes .ig/context.md
output sections
# .ig/context.md contains:

## Directory Tree    — compact ig ls output
## Symbols          — all function/class/struct definitions
## Dependencies     — Cargo.toml or package.json (v1.3+)
## API Routes       — Next.js app/api/** routes (v1.3+)
## Environment      — .env.example keys (v1.3+)

Token savings: a typical Next.js project context shrinks from 1,517 lines to 263 lines when using ig pack vs naive directory listing. Also auto-generated by ig index on every rebuild.

ig gain

Token savings dashboard. Reads the JSONL tracking log written by the rewrite hook and displays cumulative token savings, cost estimates, and per-command breakdowns.

syntax
ig gain [OPTIONS]    # show savings dashboard
ig gain --clear      # reset history
Flag Short Description
--graphASCII chart of daily savings (last 14 days)
--quotaMonthly quota savings estimate
--tier TIERSubscription tier: pro, 5x, 20x (default: 20x)
--project-pFilter to current project only
--daily-dShow daily breakdown
--weeklyShow weekly breakdown
--monthly-mShow monthly breakdown
--discoverScan Claude Code sessions for missed savings
--since NDays to scan for --discover (default: 30)
--historyPer-command history with individual savings
--jsonMachine-readable JSON output
--fullv1.10.0 — Show the full By Command table instead of the top 20
--clearReset history

v1.10.0: the default dashboard now shows the top 20 commands (was 15). Long-tail ig run <cmd> variants usually fill positions 15-20 and collectively account for a big chunk of savings. Use --full when you need every row.

output example
ig gain

instant-grep token savings
────────────────────────────────
Session:      47 rewrites
Tokens saved: 142,380
Cost saved:   $0.13
Top command:  git status  (38 rewrites, 91K tokens)
examples
# Main dashboard
ig gain

# Daily savings chart (last 14 days)
ig gain --graph

# Monthly token projection
ig gain --quota

# Current project only
ig gain -p

# Find missed optimization opportunities
ig gain --discover

# Per-command history with individual savings (new in v1.4)
ig gain --history

# Machine-readable JSON output (new in v1.4)
ig gain --json
--history output example
command history (last 10)
────────────────────────────────────────────
2026-03-27 14:32  git status    -605B   (-83%)
2026-03-27 14:35  git log -10   -7,864B (-89%)
2026-03-27 14:41  grep -r …     -2,100B (-94%)
2026-03-27 14:50  git diff      -19,382B (-74%)

ig setup New

Auto-configure AI CLI agents (Claude Code, Codex, Gemini CLI) to use ig for code search. Detects installed agents and injects configuration. Idempotent — safe to run multiple times.

syntax
ig setup
output example
ig setup

✓ Claude Code
  → Added Bash(ig *) permission to settings.json
  → Added Search Tools section to CLAUDE.md
✓ Codex CLI
  → Added Search Tools section to AGENTS.md
ℹ Gemini CLI (manual config needed)

ig git New in v1.4

Token-compressed git proxy. Routes git commands through RTK to strip verbose output, filter noise, and track token savings. Supports status, log, diff, show, and branch. Transparent — the output is still valid git output, just compressed.

syntax
ig git <SUBCOMMAND> [GIT OPTIONS]   # proxies to rtk git <subcommand>
Subcommand Native size After ig git Savings
git status732B127B-83%
git log -108,861B997B-89%
git show HEAD11,920B5,812B-51%
git diff26,288B6,906B-74%
examples
# Compressed git status (127B instead of 732B)
ig git status

# Compact log — 10 entries, -89% token reduction
ig git log -10

# Diff with noise stripped
ig git diff

# Show last commit
ig git show HEAD

# Branch list
ig git branch

ig discover New in v1.4

Scan Claude Code session history for missed token-saving opportunities. Analyzes past shell commands and reports which ones could have been rewritten to ig equivalents — helping you tune your hook coverage.

syntax
ig discover [OPTIONS]   # scan Claude Code session logs
Flag Short Description
--since DATEScan sessions since a date (e.g. --since 2026-03-01)
--limit NCap results to top N missed opportunities
examples
# Scan all sessions for missed savings
ig discover

# Limit to sessions since March 2026
ig discover --since 2026-03-01

# Show top 20 missed opportunities
ig discover --limit 20

ig proxy New in v1.4

Debug passthrough mode — executes the raw command without any ig rewriting or RTK filtering. Useful for verifying hook behavior, comparing compressed vs native output, or bypassing rewrites for a single call.

syntax
ig proxy <COMMAND> [ARGS...]   # execute raw without filtering
examples
# Run git status without compression (debug)
ig proxy git status

# Run grep without rewriting
ig proxy grep -r "pattern" src/

# Compare native vs compressed
ig proxy git log -5
ig git log -5

ig rewrite hook-internal

Rewrites a shell command to its ig-optimized equivalent. Used internally by the Claude Code PreToolUse hook — not intended for direct invocation. ig setup installs the hook automatically.

example rewrites performed by the hook
grep -r "pattern" src/   →  ig "pattern" src/
find . -name "*.rs"      →  ig files -t rs .
git status               →  ig git status

JSON output format (--json)

Structured, parseable, minimal tokens. Supported by search, query, files, symbols, and context.

schema
{
  "pattern": "async fn",
  "matches": [
    {
      "file": "src/daemon.rs",
      "line": 23,
      "text": "pub async fn handle_connection(stream: UnixStream) {"
    }
  ],
  "stats": {
    "duration_ms": 0.9,
    "candidates": 47,
    "matches": 3
  }
}