rails_search_code
Search a Rails codebase by method, class, or call site to trace definitions, callers, and internal calls in one query. Narrow results by path or file type.
Instructions
Search the Rails codebase with smart modes. Use match_type:"trace" to see where a method is defined, who calls it, and what it calls - in one call. Use match_type:"definition" for definitions only, "call" for call sites only, "class" for class/module definitions. Requires pattern:"method_name". Narrow with path:"app/models" and file_type:"rb".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Subdirectory or file to search (e.g. 'app/models', 'config/routes.rb'). Default: entire app. | |
| limit | No | Max lines to return. Default: auto-sized so the page holds a useful number of matches. A limit too small for one match and its context still returns that match. | |
| offset | No | Skip this many emitted lines for pagination. Default: 0. | |
| pattern | Yes | Search pattern (regex supported). For definition and class, a plain method or constant name matches literally (`valid?`), anything else as a regex (`generate_.*`). | |
| file_type | No | Filter by file extension (e.g. 'rb', 'js', 'erb'). Default: all files. | |
| match_type | No | any: all matches (default). definition: `def` lines whose method name contains the pattern. class: `class/module` lines whose name contains it. call: call sites only (excludes definitions). trace: FULL PICTURE - shows definition + source code + all callers + what it calls internally. | |
| exact_match | No | Match the pattern literally, whole-word where its edges are word characters. `def reblog?` will not match `def reblog`. Default: false. | |
| context_lines | No | Lines of context before and after each match (like grep -C). Default: 2, max: 5. | |
| exclude_tests | No | Exclude test/spec files from results. Default: false. | |
| group_by_file | No | Group results by file with match counts. Default: false. |