Skip to content
This repository was archived by the owner on Sep 30, 2026. It is now read-only.

Repository files navigation

ARCHIVED: everything moved to ziggygrep

rustygrep gets no more fixes. All new features land in ziggygrep now. ziggygrep is pure Zig, one static binary, zero deps, and beats ripgrep in 22 of 22 bench cases with byte-identical output. Use it for speed. This repo stays up for its --llm, --json, regex, and MCP server modes, as-is.

rustygrep logo — rust-orange rg monogram over a token-compression meter

rustygrep

Support: fuel the next build — Buy Me a Coffee

The token-efficient grep for AI coding agents. Compressed output, fewer tokens, more context room.

Future lives in ziggygrep. New search speed work ships in ziggygrep (pure Zig, one static binary, 22 of 22 benches at or below ripgrep). rustygrep stays maintained for its regex, --llm, --json, and MCP server modes. New users who want raw literal speed: start with ziggygrep.

crates.io Downloads Downloads/month CI License: MIT Rust

crates.io downloads release


Why

AI coding agents run thousands of grep calls per session. Each result eats context-window tokens. rustygrep --llm keeps the file paths, line numbers, and matching content, and cuts the token count 60-95%.

# Normal grep output (human-readable)
src/main.rs:42:    fn calculate_total(items: &[Item]) -> u64 {
src/main.rs:43:        items.iter().map(|i| i.price).sum()

# rustygrep --llm output (token-compressed)
--- src/main.rs (2 matches)
42:fn calculate_total(items: &[Item]) -> u64 {
43:  items.iter().map(|i| i.price).sum()

60-95% fewer tokens. Same information. Zero config.

Speed note: on raw literal search ziggygrep now beats both tools (22 of 22 cases at or below rg on the same corpus). rustygrep keeps the lead where agents need --llm, --json, regex, and MCP.

Features

  • MCP server — rustygrep mcp for AI coding agents (Claude Code, Cursor, OpenCode)
  • Token budget — --llm-budget N caps output to N tokens
  • Match ranking — --top N shows files with most matches first
  • Parallel search — uses all CPU cores via rayon
  • Gitignore-aware — respects .gitignore by default
  • LLM output — token-compressed format for AI agents
  • JSONL output — structured results for scripting and piping
  • Color highlighting — matches highlighted in red
  • File type filters — -t rs, -t py, -t js
  • Regex support — full Rust regex syntax
  • Zero config — works out of the box

Install

# From crates.io
cargo install rustygrep

# From source
git clone https://github.com/AkashPriyadarshii/rustygrep
cd rustygrep
cargo install --path .

Usage

# Basic search
rustygrep "pattern" src/

# Case insensitive
rustygrep -i "error" src/

# Only Rust files
rustygrep -t rs "fn main" .

# LLM-optimized output (token-compressed)
rustygrep "pattern" --llm src/

# Token budget: cap output to 500 tokens
rustygrep "pattern" --llm --llm-budget 500 src/

# Top 10 files by match count
rustygrep "pattern" --top 10 src/

# JSON Lines output (one object per match)
rustygrep "pattern" --json src/

# JSON per-file output (legacy format)
rustygrep "pattern" --json-file src/

# Count matches
rustygrep -c "TODO" .

# Files with matches only
rustygrep -l "FIXME" .

# Context lines
rustygrep -C 3 "error" src/

# Whole word match
rustygrep -w "fn" .

# Invert match
rustygrep -v "test" src/

MCP Server

rustygrep mcp starts a Model Context Protocol server for AI coding agents.

Claude Code setup

Add to .claude/settings.json or ~/.claude/settings.json:

{
  "mcpServers": {
    "rustygrep": {
      "command": "rustygrep",
      "args": ["mcp"]
    }
  }
}

Available MCP tools

Tool Description
rustygrep_search Pattern search with format options (llm/json/pretty)
rustygrep_files List files containing a pattern
rustygrep_count Count matches per file

CLI Reference

Flag Short Description
--llm Token-compressed output for LLM agents
--llm-budget N Cap output at N tokens
--llm-no-truncate Disable line truncation
--json JSON Lines output (one object per match)
--json-file JSON per-file output (legacy)
--top N Show top N files by match count
--type -t Filter by file type (rs, py, js...)
--type-not -T Exclude file type
--ignore-case -i Case insensitive
--word-regexp -w Whole word match
--count -c Match count only
--files-with-matches -l File paths only
--context -C Context lines around match
--after-context -A Context lines after match
--before-context -B Context lines before match
--max-columns -M Truncate long lines (default: 500)
--hidden Search hidden files
--no-ignore Skip .gitignore
--invert-match -v Invert match
--no-color Disable colors
--threads -j Parallel threads
--max-matches Max matches per file
mcp Start MCP server

Benchmarks

Measured 2026-09-26 on Windows 11, Intel i3-1115G4 (2C/4T), 8GB RAM. Corpus: 200 generated .rs files, 52MB, 600k lines, 112,426 HashMap hits. Median of 5 runs, output piped to null (search cost, not terminal cost). rg = ripgrep from the same shell, same corpus. Reproduce: python3 -c loop with time.perf_counter() around subprocess.run — or rustygrep PATTERN . --stats (internal timer on stderr).

Tool Search Time vs rg
ripgrep 64ms baseline
rustygrep --no-color 91ms 1.4x
ripgrep -l 24ms baseline
rustygrep -l 22ms faster
ripgrep -c 35ms baseline
rustygrep -c 56ms 1.6x
rustygrep --llm 96ms —
rustygrep --json 159ms —
miss (both) ~28ms parity

Correctness on the same corpus: -c per-file counts identical (diff clean, 112,426 both tools). -l beats rg (first-hit short-circuit + streaming walk). Miss path at parity (28 vs 27ms).

Old table (Apple M4, 9,000 files: rg 82ms / rustygrep 78ms) was measured on different hardware and is kept for reference, not as a current claim.

rustygrep --llm produces fewer tokens than ripgrep's default output while staying within ~2x of ripgrep's speed on this box.

How It Works

  1. Parallel file walking — uses the ignore crate (same as ripgrep) for gitignore-aware file discovery
  2. SIMD-accelerated matching — uses memchr for byte-level search
  3. Parallel search — rayon distributes work across all CPU cores
  4. Smart output — --llm mode strips ANSI codes, compresses format, and minimizes whitespace
  5. MCP integration — JSON-RPC over stdio, zero external dependencies

Comparison with Alternatives

For raw literal speed, use ziggygrep: 22 of 22 bench cases at or below ripgrep with byte-identical output. The table below covers feature breadth, where rustygrep still leads on agent modes.

Feature grep ripgrep rustygrep rustygrep --llm
Speed Slow Fast Fast Fast
Gitignore No Yes Yes Yes
Parallel No Yes Yes Yes
Token savings 0% 0% 0% 60-95%
AI-native No No No Yes
MCP server No No Yes Yes
Token budget No No No Yes
JSON output No Yes Yes Yes
Binary size N/A 8MB <3MB <3MB

Use Cases

For AI Coding Agents

# In your agent's CLAUDE.md or system prompt:
# Use rustygrep --llm for code search to save tokens
rustygrep --llm "function_name" ./src

# Or use MCP server for direct integration
rustygrep mcp

For CI/CD

# Check for TODOs in Rust files
rustygrep -t rs -c "TODO" . | awk -F: '{sum += $2} END {if (sum > 0) exit 1}'

For Code Review

# Find all unsafe code
rustygrep -t rs "unsafe" . --context 2

RTK Integration

RTK (69K stars) auto-rewrites grep → rtk grep via hooks. rustygrep is a drop-in replacement.

Setup

# Install rustygrep
cargo install rustygrep

# Rename or symlink binary to `rg` so RTK picks it up
# Option A: symlink (Linux/macOS)
ln -s $(which rustygrep) /usr/local/bin/rg

# Option B: just use rustygrep directly in RTK config
# Add to ~/.rtk/config.toml:
# [grep]
# command = "rustygrep"

Exit Codes

rustygrep matches ripgrep's exit codes exactly:

Code Meaning
0 Match found
1 No match
2 Error (invalid pattern, etc.)

This means rtk grep "pattern" works transparently with rustygrep installed.

RTK Token Savings

RTK applies its own compression on top. For maximum savings, use --llm directly:

# RTK will rewrite this, but --llm gives best token efficiency
rtk grep --llm "error" ./src

Shell Completions

# Bash — add to ~/.bashrc
source /path/to/rustygrep/completions/rustygrep.bash

# Zsh — copy to fpath
cp completions/_rustygrep.zsh ~/.zsh/completions/_rustygrep
autoload -U compinit && compinit

# Fish — copy to completions dir
cp completions/rustygrep.fish ~/.config/fish/completions/

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT License. See LICENSE-MIT for details.

Acknowledgments

  • Built on top of ripgrep's crates (grep-regex, grep-searcher, ignore)
  • Inspired by the need for token-efficient code search in AI agents
  • Thanks to Andrew Gallant (BurntSushi) for the amazing foundational crates

Made with Rust and care for AI agents

Need raw literal speed with zero agent modes? ziggygrep is the main line now: all future speed features land there.

Star on GitHub | Report Issues | Crates.io

About

rustygrep: token-efficient grep for AI coding agents. ripgrep-class speed with --llm output compressed 60-95%, built-in MCP server for Claude Code, Cursor, OpenCode. Rust, SIMD-parallel, zero config. cargo install rustygrep

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages