searchfox-cli
A command-line interface for searching Mozilla codebases using searchfox.org, written by and for Claude Code.
Features
- Search across multiple Mozilla repositories (mozilla-central, autoland, beta, release, ESR branches, comm-central)
- Support for regular expressions and case-sensitive search
- Filter results by file path patterns (or search for files by path alone)
- Language filtering: Filter results by programming language (C++, C, WebIDL, JavaScript)
- Fetch and display file contents directly from GitHub
- Complete function and class extraction: Intelligently extracts entire method/function bodies and class definitions with brace matching
- Symbol search: Uses searchfox's native symbol indexing for precise symbol lookups
- Advanced definition finding: Uses searchfox's structured data for reliable symbol resolution, prioritizes class definitions
- Request logging: Detailed HTTP request timing and performance analysis
- Configurable result limits
Installation
Usage
Basic Search
# Search for "AudioStream" in mozilla-central
# Search with case sensitivity
# Search with regular expressions
# Limit results to 10 matches
Symbol and Definition Search
# Find symbol definitions
# Find exact identifier matches (not prefix-based)
# Search for symbols using searchfox's symbol index
# Search for symbols in specific paths
Repository Selection
# Search in autoland repository
# Search in beta branch
Path Filtering
# Search only in dom/media directory
# Search in specific file patterns
# Use -p alone to search for files by path pattern
# Using advanced path syntax in query
Language Filtering
Filter search results by programming language using language-specific flags:
# Search only in C++ files (.cc, .cpp, .h, .hh, .hpp)
# Search only in C files (.c, .h)
# Search only in WebIDL files (.webidl)
# Search only in JavaScript files (.js, .mjs, .ts, .cjs, .jsx, .tsx)
# Without language filters, all file types are included
Advanced Query Features
# Search with context lines
# Text search with regex
# Exact text search (escapes regex chars)
# Combined advanced queries
Symbol Search
The --symbol flag uses searchfox's native symbol indexing for precise symbol lookups:
# Search for symbols by name
# Combine with path filtering
Symbol search relies on searchfox's own symbol database, which includes properly mangled C++ symbols and other language constructs as indexed by the searchfox infrastructure.
Advanced Definition Finding
The --define flag provides an advanced way to find symbol definitions by:
- Symbol Search: Uses
id:prefix internally for precise symbol lookups - Class/Struct Priority: Prioritizes class and struct definitions over constructors
- Definition Resolution: Searches both "Definitions" and "Declarations" categories (for C++ classes)
- Context Extraction: Fetches the source file and displays the complete method/function/class
# Find class definition with full body
# Find method definition with full context
# Filter by language
# The tool will:
# 1. Search using id:AudioContext for precise matches
# 2. Prioritize class definitions over constructor declarations
# 3. Extract the complete class body (with brace matching)
# 4. Display the full definition with proper highlighting
This approach leverages searchfox's comprehensive symbol database for reliable definition finding.
Example Output:
For class definitions:
>>> 135
For method definitions:
>>> 469& ) {
));
}
The tool automatically:
- Searches searchfox's structured data for definition entries
- Uses searchfox's native symbol indexing for accurate results
- Finds the actual source file location (not generated binding files)
- Fetches the source code and displays complete methods/functions
- Highlights the exact definition line with
>>>
Complete Function and Class Extraction
When using --define, the tool automatically detects and extracts complete function/method bodies and class definitions using intelligent brace matching:
For simple functions:
>>> 469& ) {
));
}
For complex constructors with initializer lists:
>>> 154
)
)
)
)
)))
)
))) {
);
}
Features of complete extraction:
- Multi-language support: Handles C++, Rust, and JavaScript function syntax
- Class and struct definitions: Extracts complete class/struct bodies with proper brace matching
- Smart brace matching: Ignores braces in strings, comments, and character literals
- Complex signatures: Handles multi-line function signatures and initializer lists
- Constructor support: Properly extracts C++ constructors with member initialization lists
- Class termination: Handles classes/structs ending with semicolons correctly
- Safety limits: Truncates extremely long definitions (>200 lines) to prevent output overflow
- Accurate parsing: Correctly handles nested braces, escape sequences, and comment blocks
Request Logging and Performance Analysis
The --log-requests flag enables comprehensive HTTP request logging for performance analysis and infrastructure planning:
# Enable detailed request logging
Features:
- Baseline latency measurement: HTTP HEAD request to searchfox.org for baseline timing
- Request tracking: Each HTTP request gets a unique ID for correlation
- Detailed timing: Start/end timestamps with duration in milliseconds
- Response metrics: HTTP status codes and response size in bytes
- Performance insights: Compare request times against baseline to identify bottlenecks
Example output:
===
)
)
================================
)
)
Performance analysis insights:
- Network vs. server processing: Compare request duration against baseline latency
- Service comparison: GitHub file fetching vs. searchfox API performance
- Infrastructure planning: Determine if searchfox server upgrades would help vs. network optimization
- Request patterns: Track multiple requests to identify consistency and variation
File Retrieval
# Fetch and display a specific file
Available Repositories
mozilla-central(default) - Main Firefox developmentautoland- Integration repositorymozilla-beta- Beta release branchmozilla-release- Release branchmozilla-esr115- ESR 115 branchmozilla-esr128- ESR 128 branchmozilla-esr140- ESR 140 branchcomm-central- Thunderbird development
Command Line Options
-q, --query <QUERY>- Search query string (supports advanced syntax)-R, --repo <REPO>- Repository to search in (default: mozilla-central)-p, --path <PATH>- Filter results by path prefix using regex, or search for files by path pattern-C, --case- Enable case-sensitive search-r, --regexp- Enable regular expression search-l, --limit <LIMIT>- Maximum number of results to display (default: 50)--get-file <FILE>- Fetch and display contents of a specific file--symbol <SYMBOL>- Search for symbol definitions using searchfox's symbol index--id <IDENTIFIER>- Search for exact identifier matches--context <N>- Show N lines of context around matches--define <SYMBOL>- Find and display the definition of a symbol with full context--log-requests- Enable detailed HTTP request logging with timing and size information--cpp- Filter results to C++ files only (.cc, .cpp, .h, .hh, .hpp)--c- Filter results to C files only (.c, .h)--webidl- Filter results to WebIDL files only (.webidl)--js- Filter results to JavaScript files only (.js, .mjs, .ts, .cjs, .jsx, .tsx)
Examples
# Find all AudioStream references
# Find function definitions starting with "Audio"
# Search only in media-related files
# Get a specific file
# Search in Thunderbird codebase
# Find where AudioContext is defined
# Find exact matches for "main" function
# Search with context lines
# Symbol search using searchfox's symbol index
# Find complete definition with context
# Language filtering
# File path search
# Advanced query syntax
# Performance analysis with request logging
Dependencies
- clap - Command line argument parsing
- reqwest - HTTP client
- tokio - Async runtime
- serde - Serialization/deserialization
- anyhow - Error handling
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.