Fixed Strings (-Q)
When your search term contains regex metacharacters (., [, +, *, ?, (), use -Q (--literal) to treat the pattern as a plain string.
Why You Need It
# BAD: dots match any character
ag "192.168.1.1" access.log # also matches "192x168y1z1"
# GOOD: exact literal match
ag -Q "192.168.1.1" access.log
Common Cases
# Searching for function calls with parentheses
ag -Q "process.exit(0)" src/
# Searching for regex-like code in templates
ag -Q "(\d+)" templates/
# Searching for file paths with slashes
ag -Q "/var/log/nginx" config.yml
# Searching for npm package references
ag -Q "@scope/package-name" package.json
Performance Benefit
-Q skips the PCRE compilation and matching overhead entirely, using a fast byte-string comparison instead. On large codebases, this is measurably faster for literal searches.
Combining with Other Flags
# Case-insensitive literal search
ag -Q -i "Connection Refused" /var/log/
# Only in Python files
ag -Q --python "import os.path" src/
# List files only
ag -Q -l "DEPRECATION WARNING" .