ripgrep for AI agents
ripgrep (rg) for coding agents: fast code search by pattern and file type, list matching files, and show context, while respecting .gitignore by default.
What ripgrep does for an agent
ripgrep is a line-oriented search tool that recursively searches directories for a regex pattern. It respects .gitignore by default and skips hidden and binary files, so results stay focused on source code.
It is fast enough to run on every question an agent has about a codebase, and its flags for file types, globs, and context lines keep output short.
Install ripgrep
The install commands from the official docs. Check it worked with rg --version.
brew install ripgrep
sudo apt-get install ripgrep
cargo install ripgrep
Signing in ripgrep for an agent
No sign-in. ripgrep reads files the current user can read.
What agents use ripgrep for
Example commands with placeholder names. Swap in your own project, app, or file names.
Find a symbol with line numbers
rg -n "createSession" src/
Search only TypeScript files
rg -n --type ts "useEffect\("List files that mention a function
rg -l "oldFunctionName"
Show context around matches
rg -C 3 "TODO\(security\)"
List test files by glob
rg --files -g '*.test.ts'
Safety rules for agents
Safe to run without asking
rg <pattern> [path]rg --filesrg -l / -c / -C N
Ask a human first
rg --hidden or -uuu across home directories or secret stores
- ripgrep is read-only; the risk is output, not changes. Use -l or -c first on broad searches to keep results small.
- Searching with --hidden or -uuu can surface .env files and keys. Do not print secret values that turn up.
- Quote patterns and escape regex characters, or use -F for a literal string.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## ripgrep (rg) Use `rg` for searching code and text across a repository. - Check it is installed with `rg --version`. If it is missing, ask before installing it. - Auth: none needed. - Run without asking (read-only): `rg <pattern> [path]`, `rg --files`, `rg -l / -c / -C N`. - Ask a human first (changes or deletes things): `rg --hidden or -uuu across home directories or secret stores`. - ripgrep is read-only; the risk is output, not changes. Use -l or -c first on broad searches to keep results small. - Searching with --hidden or -uuu can surface .env files and keys. Do not print secret values that turn up. - Quote patterns and escape regex characters, or use -F for a literal string. - Prefer JSON output where the command supports it, and keep output short.
ripgrep or an MCP server?
No official MCP server. ripgrep is a local tool; most coding agents already search with it or something like it. File and search MCP servers help in clients without a shell.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Data & text tools
ripgrep questions
How do I install ripgrep?
Homebrew: brew install ripgrep. Other official options: Debian or Ubuntu, Cargo. Check the install with rg --version, and see the Andrew Gallant (BurntSushi) docs for other platforms.
How does an AI agent authenticate ripgrep?
No sign-in. ripgrep reads files the current user can read. There is nothing to set up: an agent can use it as soon as rg --version succeeds.
Which ripgrep commands are safe for an agent to run?
Commands that only read state are safe to run without asking: rg <pattern> [path]; rg --files; rg -l / -c / -C N. Ask a human before anything that changes or deletes something: rg --hidden or -uuu across home directories or secret stores.
Is there an MCP server for ripgrep?
ripgrep is a local tool; most coding agents already search with it or something like it. File and search MCP servers help in clients without a shell.