Code Search Workflows
1. Finding Function Definitions
# Python function definitions
ag "^def \w+" --python src/
# JavaScript/TypeScript functions (various styles)
ag "(function \w+|const \w+ = (\(|async)|\w+: function)" --js --ts src/
# Go functions
ag "^func " --go src/
2. Finding TODO/FIXME Comments
# All TODO, FIXME, HACK, XXX markers
ag "(TODO|FIXME|HACK|XXX)" src/
# Only TODOs with a username
ag "TODO\s*\(@?\w+\)" src/
# TODOs by a specific developer
ag "TODO.*@alice" src/
3. Finding Deprecated or Removed APIs
When upgrading a dependency, find all usages of the old API:
# Find all uses of an old React lifecycle method
ag "componentWillMount|componentWillReceiveProps" --ts --js src/
# Find uses of deprecated Python 2 print statement
ag "^print " --python src/
# Find jQuery usage (for vanilla JS migration)
ag "\\\$\(" --js src/
4. Security Audit — Secrets in Code
# Find potential hardcoded credentials
ag -i "(password|api_key|secret|token)\s*=\s*[\"'][^\"']{8,}" src/
# Find AWS key patterns
ag "AKIA[0-9A-Z]{16}" src/
# Find private key headers
ag "BEGIN (RSA|EC|DSA|OPENSSH) PRIVATE KEY" .
5. Find and Replace Workflow
# 1. Preview
ag "processUserData" src/
# 2. Get file list
ag -l "processUserData" src/
# 3. Replace
ag -l "processUserData" src/ | xargs sed -i 's/processUserData/handleUserPayload/g'
# 4. Verify
ag "processUserData" src/ # should return nothing
6. Counting Usage Across Codebase
# How many times is each endpoint called?
ag -o "fetch\(['\"]([^'\"]+)" --js src/ | sort | uniq -c | sort -nr