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 search
The primary command. Searches for regex patterns across indexed files. Auto-builds the index on first run if no .ig/ directory exists.
Shortcut: the search subcommand is optional. ig "pattern" . and ig search "pattern" . are equivalent — all flags work the same way in both forms.
ig [OPTIONS] <PATTERN> [PATH]
ig search [OPTIONS] <PATTERN> [PATH] # also works | Flag | Short | Description |
|---|---|---|
--ignore-case | -i | Case-insensitive matching |
--after-context N | -A N | Show N lines after each match |
--before-context N | -B N | Show N lines before each match |
--context N | -C N | Show N lines before and after (overrides -A/-B) |
--type EXT | Filter by file extension (e.g. --type rs) | |
--glob PATTERN | Filter files by glob pattern (e.g. --glob '*.rs') | |
--json | Output results as JSON (for AI agents) | |
--stats | Print search statistics (candidates, time, etc.) | |
--no-index | Skip index, grep files directly (slow but always fresh) | |
--top N | v1.10.0 — Keep only the top N files ranked by BM25 relevance | |
--semantic | v1.10.0 — Expand query with PMI-learned synonyms from the corpus |
BM25 ranking — --top N v1.10.0
Regex search returns every match in filesystem order. --top N scores each matched file with Okapi BM25 and keeps only the N highest-ranked, so the agent sees the files that implement the concept — not the files that merely mention it in a comment.
$ ig --top 5 useState
apps/.../create-conversational/vehicle-edit-step-dialog.tsx
3: import { useState, useMemo } from "react";
73: const [value, setValue] = useState(formData.saleMode);
107: const [brandId, setBrandId] = useState(formData.brand);
…
(top-5 returns 3 KB instead of the 15 KB flat compressed output) Formula: score = idf · (tf · (k1+1)) / (tf + k1 · (1 − b + b · dl / avdl)) with k1 = 1.5, b = 0.75. tf is the match count, dl is the file byte-size, avdl is the mean across the result set. Overhead: one stat(2) per candidate, negligible.
Semantic query expansion — --semantic v1.10.0
Learn synonyms from the corpus itself, no ML model, no download. During ig index, a second pass tokenises every line and counts co-occurrences in a 5-line sliding window; at finalisation we rank each token's top-10 neighbours by count-weighted PPMI and persist to .ig/cooccurrence.bin (~1.5 MB on a 3K-file repo).
$ ig --semantic --top 5 throw
(semantic: expanded 'throw' → got, inattendu, denied, autorisé, trouvée, manquant)
apps/packages/reader-api-vo/scripts/test-rest-e2e.ts
44: throw new Error("HTTP server did not become ready in time");
114: throw new Error(`${label} should be an array`);
…
# finds literal throws AND French exception messages, in one pass Theoretical basis: Levy & Goldberg (NeurIPS 2014) proved skip-gram word2vec with negative sampling implicitly factorises the shifted-PMI matrix — direct PMI recovers most of the embedding neighbourhood quality at a fraction of the cost and with none of the model dependency.
Controls:
- Disable the second index pass entirely:
IG_SEMANTIC=0 ig index - Opt-out per query: just don't pass
--semantic - Inspect what was added: the stderr line
(semantic: expanded 'x' → …)shows every term included
Expansion quality depends on how often the term co-occurs with others in your corpus: throw, payment, auth, config work well; rare terms may get a weak or empty expansion.
# Basic regex search
ig "async fn \w+" src/
# Case-insensitive with 2 lines of context
ig -i -C 2 "TODO" .
# JSON output for AI agents
ig --json "impl \w+ for" src/
# Only Rust files
ig --type rs "pub fn" .
# Files matching glob
ig --glob 'src/**/*.rs' "Result<" .
# Show stats (candidates filtered, time)
ig --stats "use std" . 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.
ig index [OPTIONS] # default: current directory # 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.
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.
# 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.
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 # 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.
ig query [OPTIONS] <PATTERN> [PATH] # 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.
ig files [OPTIONS] [PATH] | Flag | Short | Description |
|---|---|---|
--compact | Tree-compressed listing — groups files by directory with counts and extension breakdown | |
--type EXT | -t | Filter by file extension |
--glob PATTERN | -g | Filter files by glob pattern |
--json | Output results as JSON (for AI agents) |
# 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.
$ 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.
ig symbols [OPTIONS] [PATH] # 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.
ig context <FILE> <LINE> # 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.
ig ls [PATH] # default: current directory # 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.
ig read <FILE> [OPTIONS] | Flag | Short | Description |
|---|---|---|
--signatures | -s | Signatures only — function/class/struct definitions |
--aggressive | -a | Strip comments, collapse blanks, elide function bodies. Keep signatures + struct fields |
--budget N | -b N | Max output tokens — uses entropy scoring to keep the most informative lines |
--relevance PAT | -r PAT | Boost score for lines matching pattern. Best combined with -b |
--delta | -d | Show only git-changed lines with enclosing function context |
# 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.
ig smart [PATH] # default: current directory # 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.
$ 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.
ig pack [PATH] # writes .ig/context.md # .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.
ig gain [OPTIONS] # show savings dashboard
ig gain --clear # reset history | Flag | Short | Description |
|---|---|---|
--graph | ASCII chart of daily savings (last 14 days) | |
--quota | Monthly quota savings estimate | |
--tier TIER | Subscription tier: pro, 5x, 20x (default: 20x) | |
--project | -p | Filter to current project only |
--daily | -d | Show daily breakdown |
--weekly | Show weekly breakdown | |
--monthly | -m | Show monthly breakdown |
--discover | Scan Claude Code sessions for missed savings | |
--since N | Days to scan for --discover (default: 30) | |
--history | Per-command history with individual savings | |
--json | Machine-readable JSON output | |
--full | v1.10.0 — Show the full By Command table instead of the top 20 | |
--clear | Reset 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.
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) # 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 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.
ig setup 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.
ig git <SUBCOMMAND> [GIT OPTIONS] # proxies to rtk git <subcommand> | Subcommand | Native size | After ig git | Savings |
|---|---|---|---|
git status | 732B | 127B | -83% |
git log -10 | 8,861B | 997B | -89% |
git show HEAD | 11,920B | 5,812B | -51% |
git diff | 26,288B | 6,906B | -74% |
# 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.
ig discover [OPTIONS] # scan Claude Code session logs | Flag | Short | Description |
|---|---|---|
--since DATE | Scan sessions since a date (e.g. --since 2026-03-01) | |
--limit N | Cap results to top N missed opportunities |
# 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.
ig proxy <COMMAND> [ARGS...] # execute raw without filtering # 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.
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.
{
"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
}
}