Code search

From Sir-chawakorn/power-ranger-toolkit · View interactive version

Code search is an AI agent skill from the GitHub repository Sir-chawakorn/power-ranger-toolkit. Efficiently search through codebases to find patterns, usages, and references

How to use this skill

Skill file

🔍 Code Search Skill


name: code-search

description: Efficiently search through codebases to find patterns, usages, and references


🎯 Purpose

ค้นหา code patterns, usages, และ references ใน codebase อย่างมีประสิทธิภาพ

📋 When to Use

🔧 Search Methods

1. grep_search (Tool)

grep_search(
  Query="functionName",
  SearchPath="./src",
  MatchPerLine=true
)

2. PowerShell Select-String

# ค้นหาใน file เดียว
Select-String -Path "file.ts" -Pattern "searchTerm"

# ค้นหาในหลาย files
Select-String -Path "src/*.ts" -Pattern "searchTerm" -Recurse

# Case insensitive
Select-String -Path "src/*.ts" -Pattern "searchTerm" -CaseSensitive:$false

3. ripgrep (rg)

# Basic search
rg "pattern" ./src

# With file type
rg "pattern" --type ts

# With context
rg -C 3 "pattern"

# Ignore case
rg -i "pattern"

# Fixed string (no regex)
rg -F "exact.string"

4. Git grep

# Search in tracked files
git grep "pattern"

# With line numbers
git grep -n "pattern"

# Only filenames
git grep -l "pattern"

📊 Search Patterns

Find Function Usage

# Find function calls
rg "functionName\(" --type ts

# Find function definition
rg "function functionName|const functionName" --type ts

Find Component Usage

# Find JSX usage
rg "<ComponentName" --type tsx

# Find import
rg "import.*ComponentName" --type ts

Find TODOs and FIXMEs

rg "TODO:|FIXME:|HACK:|XXX:" --type ts

Find Console Logs

rg "console\.(log|warn|error)" --type ts

Find Hardcoded Values

# Find hardcoded URLs
rg "https?://[^\s]+" --type ts

# Find hardcoded credentials
rg "(password|secret|api_key)\s*[:=]\s*['\"]" -i --type ts

📝 Search Results Template

## 🔍 Search Results: `{pattern}`

### Summary
- **Files matched**: 12
- **Lines matched**: 45
- **Pattern**: `{regex or string}`

### Results by File

#### `src/components/UserCard.tsx`
- Line 15: `const user = useUser(userId);`
- Line 23: `return <UserCard user={user} />;`

#### `src/hooks/useUser.ts`
- Line 8: `export function useUser(id: string) {`

### Suggestions
- Consider extracting common pattern to shared utility
- 3 instances could be simplified

🔧 Advanced Search Patterns

Regex Patterns

| Pattern | Matches |

|---------|---------|

| \bword\b | Whole word only |

| func\(.*\) | Function calls |

| import.*from | Import statements |

| useState<.*> | Generic useState |

| // TODO:.* | TODO comments |

Multi-term Search

# OR patterns
rg "pattern1|pattern2"

# AND patterns (in same file)
rg "pattern1" | xargs rg "pattern2"

# NOT pattern
rg "pattern1" --invert-match "pattern2"

📋 Common Searches

| Purpose | Pattern |

|---------|---------|

| Find imports | import.*{name} |

| Find exports | export.*{name} |

| Find hooks | use[A-Z]\w+ |

| Find components | <[A-Z]\w+ |

| Find API calls | fetch\(|axios\.|api\. |

| Find types | interface\|type\s+\w+ |

| Find console | console\. |

| Find comments | //.*\|/\*.*\*/ |

🛠️ IDE Search Features

VS Code

Antigravity

✅ Search Best Practices

🔗 Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.