Codebase Analysis & AST Search
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Codebase Analysis & AST Search within Continuous Claude provides a multi-layered approach to exploring, indexing, and modifying source code. The system leverages high-performance search subagents, local Abstract Syntax Tree (AST) tools, and external documentation indexing to allow AI agents to navigate large codebases efficiently. By using specialized Model Context Protocol (MCP) tools, the project achieves a significant reduction in token overhead, preferring targeted searches over reading entire files into context.
The architecture is designed for 100% offline operation when necessary, providing local alternatives for all major search and analysis functions. This ensures that session state and context management remain performant even as the codebase grows. Primary tools include WarpGrep for 20x faster searches than traditional grep and ast-grep for structural code pattern matching.
Sources: CLAUDE_ONBOARDING.md:5-15, CLAUDE.md:144-155, scripts/SCRIPTS.md:8-15
Core Analysis Components
WarpGrep and Morph Search
The project utilizes the Morph MCP server to provide high-speed codebase exploration. The primary tool, warpgrep_codebase_search, acts as a search subagent that runs parallel grep and read operations. It is designed to locate specific line ranges and files based on natural language queries, such as identifying authentication middleware or routing logic.
Sources: servers/morph/README.md:29-37, scripts/morph_search.py:1-25
AST-Based Search
For structural analysis, the system integrates ast-grep. Unlike traditional regex-based search, AST search understands the syntax of the programming language, allowing for precise identification of function definitions, class structures, and complex code patterns without the noise of comments or string literals.
Sources: CLAUDE_ONBOARDING.md:65, scripts/SCRIPTS.md:63
External Documentation and Repository Indexing
The Nia API provides extended capabilities for research and analysis, including the ability to index GitHub repositories, documentation websites, and research papers. This allows the agent to perform "Oracle" research—autonomous investigations into best practices or library implementations across both local and external sources.
Sources: scripts/nia_docs.py:1-40, scripts/nia_docs.py:112-140
Search Workflow Architecture
The following diagram illustrates the data flow when an agent initiates a codebase analysis request.
The search workflow prioritizes token-efficient discovery before attempting file modifications.
Sources: CLAUDE.md:40-60, servers/morph/README.md:29-35
Key Search Tools and Parameters
| Tool / Script | Purpose | Key Arguments | Performance / Note |
|---|---|---|---|
morph_search.py | High-speed codebase search | --search, --path | 20x faster than standard grep |
ast-grep | Structural pattern matching | Syntax templates | Local, offline capability |
nia_docs.py | Universal doc/repo search | search universal, oracle research | Cross-repo and web-scale |
repomix | Codebase packing | --compress, --style xml | 50% token reduction |
edit_file | Precise code modification | code_edit, path | 10,500+ tokens/sec |
Sources: scripts/morph_search.py:27-35, scripts/nia_docs.py:465-510, servers/morph/README.md:8-25, CLAUDE.md:13-25
Sequence of Code Exploration
When onboarding to a new codebase or investigating a bug, the system follows a tiered exploration strategy:
Sources: servers/morph/README.md:32-37, CLAUDE.md:40-50
Analysis Configuration
The system uses mcp_config.json to manage the endpoints for these search tools.
Morph Search Example
# From scripts/morph_search.py:45-55
result = await call_mcp_tool("morph__warpgrep_codebase_search", {
"search_string": args.search,
"repo_path": args.path
})
Sources: scripts/morph_search.py:51-54
Nia Oracle Research Example
# From scripts/nia_docs.py:112-120
payload = {
"query": query,
"model": "claude-opus-4-5-20251101",
"repositories": repositories,
"data_sources": data_sources
}
Sources: scripts/nia_docs.py:120-135
Summary
Codebase Analysis & AST Search in Continuous Claude transitions the AI agent from a "full-file reader" to a "targeted explorer." By combining Morph's WarpGrep for rapid discovery, ast-grep for syntactic precision, and Nia for broader research, the system maintains a high-fidelity understanding of the codebase while strictly managing token consumption. This modular approach ensures that even complex, large-scale codebases can be analyzed and modified efficiently without context degradation.