Agent skill

code-search

Use when searching code, refactoring, running codemods, or choosing between search tools. Provides guidance on ast-grep vs ripgrep selection and usage patterns.

Stars 53
Forks 5

Install this agent skill to your Project

npx add-skill https://github.com/edmundmiller/dotfiles/tree/main/config/agents/skills/code-search

SKILL.md

Code Search & Refactoring Tools

ast-grep vs ripgrep

When to Use ast-grep

Use ast-grep when structure matters. It parses code and matches AST nodes, so results ignore comments/strings, understand syntax, and can safely rewrite code.

Best for:

  • Refactors/codemods: rename APIs, change import forms, rewrite call sites or variable kinds
  • Policy checks: enforce patterns across a repo (scan with rules + test)
  • Editor/automation: LSP mode; --json output for tooling
  • Any operation where you'll apply changes to code

When to Use ripgrep

Use ripgrep when text is enough. It's the fastest way to grep literals/regex across files.

Best for:

  • Recon: find strings, TODOs, log lines, config values, or non‑code assets
  • Pre-filter: narrow candidate files before a precise pass
  • Quick searches where you just need to find text

Rule of Thumb

  • Need correctness over speed, or you'll apply changes → start with ast-grep
  • Need raw speed or you're just hunting text → start with rg
  • Often combine: rg to shortlist files, then ast-grep to match/modify with precision

Usage Examples

ast-grep Examples

Find structured code (ignores comments/strings):

bash
ast-grep run -l TypeScript -p 'import $X from "$P"'

Codemod (only real var declarations become let):

bash
ast-grep run -l JavaScript -p 'var $A = $B' -r 'let $A = $B' -U

Find function calls with specific patterns:

bash
ast-grep run -l Python -p 'logger.$METHOD($$$ARGS)'

Replace with transformation:

bash
ast-grep run -l TypeScript \
  -p 'useQuery($ARGS)' \
  -r 'useSuspenseQuery($ARGS)' \
  -U

ripgrep Examples

Quick textual hunt:

bash
rg -n 'console\.log\(' -t js

Find in specific file types:

bash
rg 'TODO|FIXME' -t py -t js

Context around matches:

bash
rg -C 3 'error' -t log

List files with matches:

bash
rg -l 'import.*React' -t tsx

Combined Approach

Speed + Precision: Use rg to find candidates, then ast-grep for precise operations:

bash
rg -l -t ts 'useQuery\(' | xargs ast-grep run -l TypeScript \
  -p 'useQuery($A)' \
  -r 'useSuspenseQuery($A)' \
  -U

Mental Model

Aspect ast-grep ripgrep
Unit of match AST node Line
False positives Low (understands syntax) Depends on regex
Rewrites First-class, safe Requires sed/awk, risky
Speed Slower (parses code) Fastest (text only)
Use case Structural search/refactor Text search/grep

Quick Decision Tree

Need to modify code?
├─ Yes → ast-grep (safe, structural rewrites)
└─ No
   ├─ Searching code structure? → ast-grep (accurate)
   └─ Just finding text? → ripgrep (fastest)

Common Patterns

Finding all function definitions

bash
# ast-grep (language-aware)
ast-grep run -l Python -p 'def $NAME($$$PARAMS): $$$BODY'

# ripgrep (text-based, faster but less precise)
rg '^def \w+\(' -t py

Refactoring API calls

bash
# ast-grep: Safe, precise
ast-grep run -l JavaScript \
  -p 'axios.get($URL)' \
  -r 'fetch($URL)' \
  -U

# ripgrep: Don't use for rewrites (will match in comments/strings)

Finding TODOs

bash
# ripgrep: Perfect for this
rg 'TODO:|FIXME:' --color=always

# ast-grep: Overkill for text search

Expand your agent's capabilities with these related and highly-rated skills.

edmundmiller/dotfiles

zbench

Benchmark interactive zsh performance with zsh-bench and track regressions. Use when benchmarking shell startup, comparing zsh latency after config changes, investigating slow shell, or running git bisect on performance. Trigger phrases: "benchmark zsh", "shell is slow", "zbench", "zsh-bench", "shell startup time", "profile zsh", "zsh performance".

53 5
Explore
edmundmiller/dotfiles

nix-rebuild

Rebuild nix-darwin/NixOS system after dotfiles changes. Use when config files managed by Nix (lazygit, ghostty, etc.) need to be regenerated, or after editing any .nix file in the dotfiles repo.

53 5
Explore
edmundmiller/dotfiles

hass-config-flow

Interact with Home Assistant via the REST API on a NixOS host. Use when adding integrations, querying entities, managing config flows, creating API tokens, or automating HA setup programmatically. Also covers identifying device protocols (Matter, Zigbee, Thread, HomeKit) from the device registry. Trigger phrases: "add HA integration", "configure home assistant", "query HA entities", "create HA token", "HA REST API", "pair homekit", "set up matter in HA", "add spotify to HA", "is this device zigbee or thread", "what protocol is this device", "move devices to ZHA", "identify matter devices".

53 5
Explore
edmundmiller/dotfiles

hass-declarative

Manage Home Assistant automations, scenes, and scripts declaratively via NixOS modules. Covers adding/editing/removing entities in the domain-based Nix structure, the ensureEnabled wrapper (initial_state enforcement), the sweep service that cleans orphaned entities, entity identity (IDs, slugs, unique_ids), the eval test assertions, and the build-time manifest. Trigger phrases: "add HA automation", "new scene", "new script", "remove automation", "declarative HA", "sweep unmanaged", "entity drift", "ghost entity", "orphaned automation", "HA domain file", "eval-automations test", "hass assertion", "ensureEnabled", "initial_state".

53 5
Explore
edmundmiller/dotfiles

agenix-secrets

Create, edit, and wire up agenix-encrypted secrets in this dotfiles repo. Use when adding API keys, tokens, credentials, passwords, or any sensitive values to NixOS host configs. Trigger phrases: "add a secret", "encrypt with agenix", "new age secret", "hide this value", "agenix secret".

53 5
Explore
edmundmiller/dotfiles

linear

Read-only Linear issue access via the Linear GraphQL API.

53 5
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results