Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 23, 2026·3 min de lecture

The Silver Searcher (ag) — Lightning-Fast Code Search from the Terminal

A code-searching tool similar to ack but optimized for speed. ag recursively searches directories for a regex pattern while respecting .gitignore rules, delivering results 5-10x faster than ack and on par with ripgrep.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
The Silver Searcher
Commande d'installation directe
npx -y tokrepo@latest install d77daba2-8658-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

The Silver Searcher (ag) is a code-searching tool originally inspired by ack but rewritten in C for raw speed. It automatically skips files listed in .gitignore and .hgignore, making it ideal for searching large codebases without wading through build artifacts or vendor directories.

What The Silver Searcher Does

  • Recursively searches directories for regex or literal patterns at high speed
  • Honors .gitignore, .hgignore, and custom ignore files out of the box
  • Prints results with filenames, line numbers, and color highlighting
  • Supports PCRE-style regular expressions for complex pattern matching
  • Searches compressed files and allows file-type filtering with flags

Architecture Overview

ag is written in C and uses POSIX threads to parallelize directory traversal and file searching. It memory-maps files for fast I/O, builds an ignore-rule tree from .gitignore and similar files at startup, and applies those rules during traversal so excluded paths are never opened. Pattern matching is handled by the PCRE library.

Self-Hosting & Configuration

  • Ships as a single binary with no runtime dependencies beyond libc and PCRE
  • Available in all major package managers (brew, apt, yum, pacman, choco)
  • Configure default flags in a ~/.agrc file (e.g., --hidden, --depth)
  • Override ignore rules per-project with a .ignore or .agignore file
  • Integrates with editors via plugins for Vim (ag.vim), Emacs (ag.el), and VS Code

Key Features

  • Typically 5-10x faster than ack on large repositories
  • Automatic .gitignore awareness removes the need for manual exclude lists
  • Colored, grouped output is easy to scan in a terminal
  • Pager support pipes long results through less automatically
  • Broad platform support across Linux, macOS, FreeBSD, and Windows

Comparison with Similar Tools

  • ripgrep (rg) — newer Rust-based successor, generally faster on modern hardware but ag remains well-established
  • ack — the Perl-based predecessor; ag is a performance-oriented reimplementation
  • grep -r — universal but slower and requires manual ignore configuration
  • git grep — fast inside git repos but limited to tracked files only
  • ugrep — newer C++ grep alternative with ag-compatible output

FAQ

Q: How does ag compare to ripgrep? A: ripgrep is generally faster in benchmarks, especially on very large repos. ag is still fast and widely installed, making it a solid choice when rg is unavailable.

Q: Can ag search binary files? A: By default ag skips binary files. Use the --search-binary flag to include them.

Q: Does ag support multiline search? A: ag does not natively support multiline patterns. Use ripgrep with the -U flag or pcregrep -M for that.

Q: How do I search only specific file types? A: Use file-type flags like ag --python "pattern" or provide a glob with -G "*.ts".

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires