codecodebase analysis / search code

Search Code

search_code

Searches for code patterns across files in a local directory or a remote GitHub repository. Local mode requires no token; GitHub mode uses the GitHub connector (optional for public repos). Use when: user wants to find where a function, class, variable, or pattern is used across a codebase — locally or on GitHub. Scope: local directory walk (no token) OR GitHub code search API (token optional for public repos). Not for: fetching a specific known file (use get_file), analyzing commit history (use analyze_commits), or finding security issues (use repo_scanner).

How to use search_code

Provide only the required inputs below. Start with the smallest scope that answers the task, then review the risk properties before an agent executes the call.

Risk and execution properties

Read only: yes

Destructive: no

Idempotent: yes

Open world: yes — can reach external systems

Inputs

patternstringrequired

Search pattern — regex for local mode, keyword/qualifier for GitHub mode. Example: 'def run\(' or 'PyGithub language:python'

pathstring

Local directory to search. Use this for local mode. Omit if using 'repo'.

repostring

GitHub repo in 'owner/repo' format. Use this for GitHub mode. Omit if using 'path'. Example: 'agenticstore/agentic-store-mcp'

file_extensionstring

Filter by file extension. Example: 'py', 'ts', 'go'. Optional.

max_resultsinteger

Maximum number of results to return. Default: 50.

Default: 50

Example input

{
  "pattern": "<string>",
  "path": "<string>",
  "repo": "<string>",
  "file_extension": "<string>",
  "max_results": 50
}

Browse or search the full 74-tool reference to choose the smallest suitable capability.

Browse all tools →