ag
Files
SKILL.mdagentsreferencesscripts
Install
Install the containing plugin
/plugin install shared-skills@llm-skills
Invoke this skill after installation
/shared-skills:ag
This skill is bundled inside shared-skills. Install the plugin once, then Claude Code can use any of its included skills. Browse the full plugin repository at github.com/alisonaquinas/llm-shared-skills.
SKILL.md
name: ag
description: >
High-speed repository and document text search with The Silver Searcher (ag).
Use when the user asks for ag/Silver Searcher explicitly, or when tasks need fast
recursive matching, filename filtering, match counting, ignore-aware scanning
(.gitignore/.hgignore/.ignore/$HOME/.agignore), context extraction, script-friendly
result lists, multi-file search, file type filtering, or performance-critical searching.
Ag Search
Use ag to find text across code and documents quickly with the right scope, output mode, and ignore behavior.
Prerequisite Check
Run this before proposing ag-based search:
command -v ag >/dev/null 2>&1 || ag --version
If ag is missing, surface that first and either run scripts/install.sh or scripts/install.ps1, or fall back to rg and then grep -R when the user still needs search results in the current runtime.
Quick Start
- Confirm the binary exists:
ag --version - Start with a bounded search:
ag --numbers --column 'pattern' . - Narrow output before scaling up:
ag -l 'pattern' .orag -c 'pattern' . - If
agis unavailable, continue withrg 'pattern' .orgrep -R --line-number 'pattern' .
Intent Router
| Request | Reference | Load When |
|---|---|---|
| Install tool, first-time setup | references/install-and-setup.md | User needs to install ag or do initial configuration |
| Output modes, file filtering, patterns | references/ag-patterns.md | User needs ignore file info, output format details, or complex filtering |
| Preflight and environment | scripts/probe-ag.sh | Verify ag availability and features before workflows |
Workflow
- Confirm search goal: matching lines, matching files, counts, filename search, or inverse match.
- Pick pattern mode:
- Regex (default)
- Literal:
-Q/--literal - Whole word:
-w - If pattern starts with a dash, use
--before the pattern.
- Pick scope:
- Path(s):
ag '<pattern>' <path> - File name restriction:
-G '<file-regex>' - File type restriction: run
ag --list-file-types, then use--<type> - Depth restriction:
--depth <num>
- Pick output:
- Files only:
-l - Count per file:
-c - Column and line numbers:
--column --numbers - Script-safe filenames:
-0withxargs -0
- Run and summarize totals plus notable matches.
Ignore and Visibility Rules
Default behavior:
- Obey
.gitignore,.hgignore,.ignore, and$HOME/.agignore - Skip binary files
Overrides:
--hidden: include hidden files and still obey ignore files-U: ignore VCS ignore files and still obey.ignore-t: search all text files (not hidden)-a: search all file types (not hidden)-u: unrestricted (hidden + binary + ignore bypass)
Command Patterns
- Basic recursive search:
ag '<pattern>' . - Literal string search:
ag -Q '<literal>' . - Files containing match:
ag -l '<pattern>' . - Count matches per file:
ag -c '<pattern>' . - Filename-only search:
ag -g '<filename-regex>' . - Search pattern only in matching filenames:
ag -G '<filename-regex>' '<pattern>' . - Include context lines:
ag -C 2 '<pattern>' . - Search compressed content (if supported):
ag -z '<pattern>' . - Safe pipeline:
ag -l -0 '<pattern>' . | xargs -0 <command>
# Preferred fallback order when ag is unavailable
rg --line-number '<pattern>' .
grep -R --line-number -- '<pattern>' .
Safety and Guardrails
| Operation | Guardrail | Why |
|---|---|---|
| Recursive search | Always use --ignore or check .gitignore | Avoid unintended vendor/node_modules search blowup |
| Script output | Use -0 (null separator) with xargs -0 | Safe with filenames containing spaces/newlines |
| Large codebases | Start with -l, -c, or --depth | Prevent output flood; control volume |
| Pattern safety | Quote patterns to avoid shell expansion | 'pattern' not pattern |
Practical Guardrails
- Quote patterns to avoid shell expansion.
- For machine-readable output, add
--nocolorand optionally--nogroup. - For very large trees, start with
-l,-c, or--depthto control output volume. - Runtime defaults can vary by build/version; check
ag --helpon this machine when behavior differs. - Run probe script first:
scripts/probe-ag.shto verify ag availability and features - Recovery note: when falling back from
ag, call out behavior differences.rgandgrep -Rdo not matchag's ignore rules and file-type flags exactly.