/search-pattern
Search for code patterns across codebase
$ npx -y skills add bybren-llc/safe-agentic-workflow --agent claude-codeHow it fires
How this command gets triggered: by you, by Claude, or both.
- Fires itselfClaude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/search-pattern
Context preview
What this command does when you run it.
Search for code patterns across codebase
Command definition
search-pattern.mddescription: Search for code patterns across codebase
argument-hint: <pattern> [file-type]
allowed-tools: [Read, Write, Edit, Bash, Grep, Glob]
Search codebase for patterns using optimized tools. Useful for refactoring, finding usage, or understanding patterns.
Usage
/search-pattern "prisma\." ts # Find direct Prisma usage in TypeScript
/search-pattern "withUserContext" # Find RLS context usage
/search-pattern "import.*icons" # Find icon imports
Search Workflow
1. Parse Arguments
- $1 = Pattern to search (required)
- $2 = File type filter (optional: ts, tsx, js, md, etc.)
2. Execute Search
Use the Grep tool with these parameters:
**With file type filter** (recommended for large codebases):
| Parameter | Value | Example | | ------------- | ------------------------- | ----------------------- | | `pattern` | The regex pattern to find | `"withUserContext"` | | `type` | File type to search | `"ts"`, `"tsx"`, `"md"` | | `output_mode` | `"files_with_matches"` | Shows matching files |
**Without file type** (searches all files):
| Parameter | Value | Example | | ------------- | ------------------------- | -------------------- | | `pattern` | The regex pattern to find | `"prisma\."` | | `output_mode` | `"content"` | Shows matching lines | | `head_limit` | Limit results (optional) | `50` |
**With context** (show surrounding lines):
| Parameter | Value | Example | | ------------- | -------------------------- | --------------------------- | | `pattern` | The regex pattern | `"withUserContext"` | | `-C` | Context lines before/after | `3` | | `output_mode` | `"content"` | Required for context output |
3. Analyze Results
Report:
- Total matches found
- Files affected
- Common patterns noticed
- Potential refactoring opportunities
4. Categorize Findings
Group by:
- **Usage patterns**: How pattern is used
- **Contexts**: Where pattern appears
- **Variations**: Different uses of pattern
- **Outliers**: Unusual usage
Common Search Patterns
Find Direct Database Access
/search-pattern "prisma\.(user|payment|subscription)" ts
Identifies: Direct Prisma calls that should use RLS context helpers
Find Icon Library Usage
/search-pattern "from.*react-icons"
Identifies: Which icon libraries are used where
Find TODO Comments
/search-pattern "TODO:|FIXME:|HACK:"
Identifies: Technical debt markers
Find Deprecated Patterns
/search-pattern "deprecated|@deprecated"
Identifies: Code marked for removal
Find Error Handling
/search-pattern "try\s*\{|catch\s*\(" tsIdentifies: Error handling patterns
Find Environment Variables
/search-pattern "process\.env\."
Identifies: All environment variable usage
Find API Routes
/search-pattern "export.*GET|POST|PUT|DELETE" ts
Identifies: All API endpoints
Find Test Files
/search-pattern "describe\(|it\(|test\(" tsIdentifies: Test coverage
Advanced Patterns
Multiline Search
For patterns spanning multiple lines (e.g., finding function bodies):
| Parameter | Value | Purpose | | ----------- | --------------------------------------- | ------------------------- | | `pattern` | `"async function.*\\{[\\s\\S]*?return"` | Cross-line pattern | | `multiline` | `true` | Enable multiline matching | | `type` | `"ts"` | Optional file type filter |
Example: Find async functions that return Prisma results
Context Search
Show surrounding lines for understanding usage context:
| Parameter | Purpose | When to Use | | ------------- | ------------------------ | ------------------------------- | | `-A 3` | 3 lines after match | See what happens after | | `-B 3` | 3 lines before match | See imports, function signature | | `-C 5` | 5 lines before and after | Full context around match | | `output_mode` | Must be `"content"` | Required for context output |
Example: See function signature with implementation context
Regex Patterns
Complex patterns:
- `\bfunction\s+(\w+)` - Function names
- `import.*from\s+['"](.*)['"]` - Import sources
- `interface\s+(\w+)` - Interface names
Output Format
Summary
Pattern: {search-pattern}
Files: {count} files
Matches: {count} occurrencesGrouped Results
Category: {category-name}
- file1:line - context
- file2:line - context
Category: {category-name}
- file3:line - contextRecommendations
Based on findings:
- Refactoring opportunities
- Pattern consistency issues
- Missing patterns
- Best practice violations
Use Cases
1. Pre-Refactoring
Before refactoring, find all usage:
/search-pattern "oldFunctionName"
Creates checklist of files to update.
2. Pattern Enforcement
Verify pattern usage:
/search-pattern "withUserContext|withAdminContext"
Ensures RLS patterns followed.
3. Dependency Analysis
Find imports:
/search-pattern "from '@/lib/prisma'"
Understand module dependencies.
4. Migration Tracking
Find old patterns:
/search-pattern "OldComponent"
Track migration to new patterns.
5. Documentation
Find undocumented code:
/search-pattern "export (function|class|interface)" ts
Cross-reference with documentation.
Integration with Refactoring
After search:
1. Create Linear ticket for refactoring 2. List all affected files 3. Estimate effort 4. Plan incremental changes 5. Track progress
Success Criteria
- ✅
Read more
description: Search for code patterns across codebase argument-hint: <pattern> [file-type] allowed-tools: [Read, Write, Edit, Bash, Grep, Glob]
Search codebase for patterns using optimized tools. Useful for refactoring, finding usage, or understanding patterns.
Usage
/search-pattern "prisma\." ts # Find direct Prisma usage in TypeScript /search-pattern "withUserContext" # Find RLS context usage /search-pattern "import.*icons" # Find icon imports
Search Workflow
1. Parse Arguments
- $1 = Pattern to search (required)
- $2 = File type filter (optional: ts, tsx, js, md, etc.)
2. Execute Search
Use the Grep tool with these parameters:
**With file type filter** (recommended for large codebases):
| Parameter | Value | Example | | ------------- | ------------------------- | ----------------------- | | `pattern` | The regex pattern to find | `"withUserContext"` | | `type` | File type to search | `"ts"`, `"tsx"`, `"md"` | | `output_mode` | `"files_with_matches"` | Shows matching files |
**Without file type** (searches all files):
| Parameter | Value | Example | | ------------- | ------------------------- | -------------------- | | `pattern` | The regex pattern to find | `"prisma\."` | | `output_mode` | `"content"` | Shows matching lines | | `head_limit` | Limit results (optional) | `50` |
**With context** (show surrounding lines):
| Parameter | Value | Example | | ------------- | -------------------------- | --------------------------- | | `pattern` | The regex pattern | `"withUserContext"` | | `-C` | Context lines before/after | `3` | | `output_mode` | `"content"` | Required for context output |
3. Analyze Results
Report:
- Total matches found
- Files affected
- Common patterns noticed
- Potential refactoring opportunities
4. Categorize Findings
Group by:
- **Usage patterns**: How pattern is used
- **Contexts**: Where pattern appears
- **Variations**: Different uses of pattern
- **Outliers**: Unusual usage
Common Search Patterns
Find Direct Database Access
/search-pattern "prisma\.(user|payment|subscription)" ts
Identifies: Direct Prisma calls that should use RLS context helpers
Find Icon Library Usage
/search-pattern "from.*react-icons"
Identifies: Which icon libraries are used where
Find TODO Comments
/search-pattern "TODO:|FIXME:|HACK:"
Identifies: Technical debt markers
Find Deprecated Patterns
/search-pattern "deprecated|@deprecated"
Identifies: Code marked for removal
Find Error Handling
/search-pattern "try\s*\{|catch\s*\(" tsIdentifies: Error handling patterns
Find Environment Variables
/search-pattern "process\.env\."
Identifies: All environment variable usage
Find API Routes
/search-pattern "export.*GET|POST|PUT|DELETE" ts
Identifies: All API endpoints
Find Test Files
/search-pattern "describe\(|it\(|test\(" tsIdentifies: Test coverage
Advanced Patterns
Multiline Search
For patterns spanning multiple lines (e.g., finding function bodies):
| Parameter | Value | Purpose | | ----------- | --------------------------------------- | ------------------------- | | `pattern` | `"async function.*\\{[\\s\\S]*?return"` | Cross-line pattern | | `multiline` | `true` | Enable multiline matching | | `type` | `"ts"` | Optional file type filter |
Example: Find async functions that return Prisma results
Context Search
Show surrounding lines for understanding usage context:
| Parameter | Purpose | When to Use | | ------------- | ------------------------ | ------------------------------- | | `-A 3` | 3 lines after match | See what happens after | | `-B 3` | 3 lines before match | See imports, function signature | | `-C 5` | 5 lines before and after | Full context around match | | `output_mode` | Must be `"content"` | Required for context output |
Example: See function signature with implementation context
Regex Patterns
Complex patterns:
- `\bfunction\s+(\w+)` - Function names
- `import.*from\s+['"](.*)['"]` - Import sources
- `interface\s+(\w+)` - Interface names
Output Format
Summary
Pattern: {search-pattern}
Files: {count} files
Matches: {count} occurrencesGrouped Results
Category: {category-name}
- file1:line - context
- file2:line - context
Category: {category-name}
- file3:line - contextRecommendations
Based on findings:
- Refactoring opportunities
- Pattern consistency issues
- Missing patterns
- Best practice violations
Use Cases
1. Pre-Refactoring
Before refactoring, find all usage:
/search-pattern "oldFunctionName"
Creates checklist of files to update.
2. Pattern Enforcement
Verify pattern usage:
/search-pattern "withUserContext|withAdminContext"
Ensures RLS patterns followed.
3. Dependency Analysis
Find imports:
/search-pattern "from '@/lib/prisma'"
Understand module dependencies.
4. Migration Tracking
Find old patterns:
/search-pattern "OldComponent"
Track migration to new patterns.
5. Documentation
Find undocumented code:
/search-pattern "export (function|class|interface)" ts
Cross-reference with documentation.
Integration with Refactoring
After search:
1. Create Linear ticket for refactoring 2. List all affected files 3. Estimate effort 4. Plan incremental changes 5. Track progress
Success Criteria
- ✅
SAW — SAFe Agentic Workflow AI Agent Harness for Multi-Agent Team Workflows Built on SAFe methodology (Scaled Agile Framework), adapted for AI agent teams (Now With AI-DLC!) Works for any team with repeatable processes: Software, Marketing, Research, Legal, Operations.
Other commands on safe-agentic-workflow.
- /audit-deps
Run comprehensive dependency audit
Open command - /check-docker-status
Check if {{DEV_MACHINE}} Docker environment needs updating
Open command - /check-workflow
Quick status check of current workflow state
Open command - /deploy-dev
Deploy latest Docker image to {{DEV_MACHINE}} dev environment
Open command - /dev-health
Check {{DEV_MACHINE}} dev environment health dashboard
Open command - /dev-logs
View {{DEV_MACHINE}} dev container logs
Open command

