Search Workflow comparison

search_patterns

Nine built-in patterns for common code quality issues plus custom regex. Finds empty-catch, any-type, console-log, await-in-loop, and more.

-88%
Token reduction
rg with complex regex
Native baseline
1 vs 2
Calls (CS vs native)
2,500 vs 21,000
Tokens (CS vs native)

What It Does

search_patterns scans a codebase for known structural anti-patterns using pre-built detection rules. Each pattern is a combination of regex matching and false-positive exclusion that would take significant effort to replicate with raw grep.

The difference between search_patterns("empty-catch") and rg "catch.*\{\s*\}" is precision. The grep version matches test files, catches with intentional comments explaining why they are empty, and catches that contain logging but span multiple lines. The built-in pattern knows to skip test files, recognizes documented empty catches, and handles multi-line blocks correctly.

Built-in Patterns

PatternWhat it detectsFalse-positive handling
empty-catchCatch blocks with no error handlingSkips catches with comments, test files
any-typeTypeScript any usageSkips type definitions that genuinely need any
console-logConsole statements in production codeSkips test files, debug utilities
await-in-loopSequential await inside for/while loopsSkips loops with explicit ordering comments
todo-fixmeTODO/FIXME/HACK commentsGroups by priority keyword
large-functionFunctions exceeding line thresholdsConfigurable threshold
deep-nestingExcessive if/else/try nestingMeasures actual depth, not indentation
magic-numberUnnamed numeric literalsSkips common constants (0, 1, -1, 100)
scaffoldingLeftover scaffolding and boilerplateDetects template markers, placeholder text

Custom Regex

Beyond the built-in patterns, you can pass any regex:

search_patterns(repo, "custom", custom_regex="process\\.env\\.")

Custom patterns get the same output formatting and file-pattern scoping as built-in ones, but without the false-positive exclusion logic.

Why the Token Reduction Is Real

The -88% reduction comes from three sources:

Scoped scanning. Built-in patterns already know which file types to scan. empty-catch only looks at .ts, .tsx, .js, .jsx files. Grep scans everything unless you add --glob manually.

Ranked results. Findings are sorted by severity and grouped by file. The most problematic files appear first. Grep returns matches in directory traversal order.

False-positive exclusion. Each pattern has exclusion rules that prevent matches the agent would have to manually filter. A typical any-type grep returns 200+ results including type definition files and intentional escape hatches. The pattern returns the 30 that actually need attention.

Benchmark Results

Tested on anti-pattern detection across three codebases:

Scenariosearch_patternsrg equivalent
Find empty catches1 call, 2.5K tokens2 calls (search + filter tests), 21K tokens
Find console.log in prod1 call, 1.8K tokens3 calls (search + exclude tests + exclude utils), 18K tokens

The native workflow requires multiple grep passes: one to find matches, one to exclude test files, often a third to exclude known-safe directories. search_patterns handles all of this in a single call.

When to Use

  • During code audits (/code-audit, /review) — scan for structural issues before manual review
  • Before releases — check for leftover TODOs, console.log statements, scaffolding
  • Onboarding — quickly assess code quality patterns in an unfamiliar codebase
  • Refactoring prioritization — find which files have the most anti-patterns

When to Use Something Else

Use search_text when looking for a specific string that is not a structural anti-pattern. search_patterns is for known categories of issues, not arbitrary text search.

Use analyze_complexity when you need quantitative complexity metrics (cyclomatic complexity, function length distributions) rather than specific pattern matches.

Use a dedicated linter (ESLint, Biome) when you need rule enforcement in CI. search_patterns is a discovery tool for AI agents, not a CI gate.

Benchmark note

This benchmark compares CodeSift against the closest practical native workflow an agent would use for the same task. For some tools, that baseline is a direct shell equivalent such as rg or find. For AST-aware, graph-aware, and LSP-backed tools, the baseline is a multi-step workflow rather than a strictly identical command. Results should be read as agent-workflow comparisons: token cost, call count, and practical context efficiency.