How-To Updated 4 min read

How to Search Your Codebase with AI

Use AI-powered grep and glob to find code patterns, understand functions, and navigate large codebases faster.

You need to find where a function is defined, how an API is used across your project, or which files import a specific module. Traditional grep works but requires exact pattern knowledge. AI-powered search lets you describe what you are looking for in natural language.

The Tools

Chapeta includes two code search tools:

  • Grep: Search file contents for patterns (like grep or rg)
  • Glob: Find files by name patterns (like find by filename)

Combined with AI understanding, these tools let you search by intent rather than exact syntax.

Basic Searches

Find Where Something Is Defined

“Search ~/projects/myapp for where the function ‘processPayment’ is defined”

Chapeta uses grep to find the definition, then reads the surrounding code to show you the full function.

Find All Usages

“Find every file in ~/projects/myapp that imports the ‘auth’ module”

Grep finds all import statements matching the pattern across your codebase.

Find Files by Name

“Find all test files in ~/projects/myapp”

Glob matches patterns like **/*test* or **/*.spec.* to locate test files.

Advanced Searches

Understand Code Patterns

“Search ~/projects/myapp for all error handling patterns and tell me if they’re consistent”

Chapeta greps for try/catch blocks, error callbacks, and error-related patterns, then analyzes whether the codebase follows a consistent approach.

Find Dead Code

“Find all exported functions in ~/projects/myapp/src/utils.js and check which ones are imported elsewhere in the project”

This chains grep (find exports), then grep again (search for imports of each), giving you a list of potentially unused exports.

Security Audit

“Search ~/projects/myapp for hardcoded API keys, passwords, or secrets”

Grep searches for common patterns like apiKey =, password =, secret =, and base64-encoded strings.

Dependency Analysis

“Find all files in ~/projects/myapp that import from ‘lodash’ and tell me which lodash functions are used”

This combines grep to find imports and AI analysis to extract the specific function names.

Combining Search with Code Understanding

The real power is not just finding code but understanding it. After a search, you can ask follow-up questions:

“Read the file at ~/projects/myapp/src/auth/login.js and explain what the authentication flow does”

Or chain it together:

“Find the main entry point of ~/projects/myapp, read it, and explain the application architecture”

Chapeta uses glob to find common entry points (index.js, main.ts, app.py), reads the file, and provides an explanation.

Practical Workflows

Onboarding to a new codebase: “Search this project and give me an overview of the folder structure, main technologies, and entry points.”

Refactoring: “Find all places that call the deprecated ‘oldFunction’ and show me the context around each call.”

Bug hunting: “Search for all places where ‘userId’ is used without null checking.”

Code review prep: “Find all files changed in the last git commit and show me the key changes.”

Tips

  • Specify the directory: Always provide the project path so Chapeta searches the right location
  • Narrow your search: “Search src/ folder” is faster than searching the entire project including node_modules
  • Use follow-ups: Start broad (“find all authentication-related files”) then narrow (“now show me the login handler in that auth file”)
  • Combine tools: Grep finds content, Glob finds files, file read shows context, and AI explains it all

Limitations

Chapeta’s search tools work on text files. They do not understand AST (Abstract Syntax Tree) relationships, so “find all callers of this function” relies on text pattern matching, not semantic code analysis. For very large monorepos, searches may take longer. The tools also do not index your codebase, so each search runs fresh against the filesystem.

There's a better way.