ast-index Documentation

repository·main·Indexed 19 days ago

https://github.com/defendend/claude-ast-index-search

A structural, AST-aware code navigation CLI (version 3.50.0) that builds a local SQLite index of symbols, references, and dependencies. It supports 30 programming languages across Web, Systems, Data, and Scripting categories. The tool provides specialized commands for searching classes, symbols, usages, and hierarchies, and includes integrations for AI agents such as Claude Code, Cursor, Codex, and Gemini CLI.

Tokens
84.4K
Snippets
286
Records
382
Agent score
67%

What's inside ast-index

  1. Supported Agent Surfaces for ast-index

    main

    The ast-index plugin provides integration payloads for several AI agent platforms. Each platform uses a specific directory structure for configuration and capabilities:

    • Claude Code: Uses .claude-plugin/plugin.json, commands/, and skills/.
    • Codex: Uses .codex-plugin/plugin.json and skills/.
    • Cursor: Uses .cursor-plugin/plugin.json, skills/, rules/, and commands-cursor/.

    Note: Claude Code commands are kept separate from Cursor commands because they target different project configuration files.

  2. Identify changed files on a branch

    main

    The changed command provides a summary of files changed relative to a base (Git or Arc). It is cache-independent and does not require an index rebuild.

    Key Features:

    • Automatic Base Detection: Without --base, it tries origin/HEAD, origin/main, origin/master, main, master, or trunk (for Arc).
    • Structured Output: Use --format json for machine-readable results.
    • Scope: The current working directory defines the scope; paths are relative to the repository root.

    Warning: changed reports file statuses (Added, Modified, etc.), not specific code/symbol changes. Use raw git diff or arc diff for patch hunks.

    # Compare against a specific base
    ast-index changed --base origin/develop
    
    # Get JSON output for scripts
    ast-index --format json changed --base origin/develop --timeout-ms 30000
    
    # Verbose output (shows root, scope, and timing)
    ast-index changed --verbose
  3. WSDL and XSD Element Mapping

    main

    When indexing WSDL (.wsdl) and XSD (.xsd) files, ast-index maps XML elements to specific symbol kinds. This allows you to search for services, operations, and types using the appropriate command types.

    ### WSDL Elements
    | WSDL Element | Symbol Kind | Example |
    |--------------|-------------|---------|
    | `<service name="...">` | Interface | `UserService` → Interface |
    | `<portType name="...">` | Interface | `UserPortType` → Interface |
    | `<operation name="...">` | Function | `getUser` → Function |
    | `<binding name="...">` | Class | `UserBinding` → Class |
    | `<message name="...">` | Class | `GetUserRequest` → Class |
    | `<import location="...">` | Import | `types.xsd` → Import |
    
    ### XSD Elements
    | XSD Element | Symbol Kind | Example |
    |-------------|-------------|---------|
    | `<complexType name="...">` | Class | `UserType` → Class |
    | `<simpleType name="...">` | Class | `StatusType` → Class |
    | `<element name="...">` | Property | `userId` → Property |
    | `<attribute name="...">` | Property | `version` → Property |
    | `<import schemaLocation="...">` | Import | `common.xsd` → Import |
  4. Configure .claude/rules/ast-index.md for AI Agents

    main

    The .claude/rules/ast-index.md file is a critical configuration that guides how an AI agent interacts with your code. It should contain instructions to:

    1. Always use ast-index first for code search tasks.
    2. Avoid duplicating results from grep if ast-index has already provided the answer.
    3. Only use grep or standard search when ast-index returns no results, when searching for regex patterns, searching for string literals inside code, or searching within comments.
    # ast-index Rules
    
    ## Mandatory Search Rules
    
    1. **ALWAYS use ast-index FIRST** for any code search task
    2. **NEVER duplicate results** — if ast-index found usages/implementations, that IS the complete answer
    3. **DO NOT run grep "for completeness"** after ast-index returns results
    4. **Use grep/Search ONLY when:**
       - ast-index returns empty results
       - Searching for regex patterns (ast-index uses literal match)
       - Searching for string literals inside code (`"some text"`)
       - Searching in comments content
  5. How smart-build detects build tools

    main

    The tool uses auto-detection to determine which parser to apply. It identifies the build tool based on the first word of the command or by looking for marker files in the project directory. Supported tools include:

    • cargo (Rust)
    • gradle / gradlew (Gradle)
    • tsc / npx tsc (TypeScript)
    • go build / go test (Go)
    • gcc / g++ / clang / clang++ (C/C++)
    • swift build / xcodebuild (Swift)
    • dotnet build (.NET)
    • dart analyze (Dart)
    • mvn / maven (Maven)
    • pytest (Python)
    • jest / npx jest (JavaScript)

    If no tool is recognized, it falls back to a Generic regex parser that looks for standard file:line:col: severity: message patterns.

  6. How Git worktrees handle indexing

    main

    Each git worktree is treated as a unique project because ast-index keys the cache by the canonical project-root path. This prevents stale results when different worktrees are on different branches.

    Workflow for worktrees:

    1. Go to the main worktree and run ast-index rebuild.
    2. Go to the feature worktree and run ast-index rebuild.
    3. Use update or watch within each worktree as usual.
    cd /path/to/project-main
    ast-index rebuild
    
    cd /path/to/project-feature-worktree
    ast-index rebuild
  7. Framework-specific indexing patterns

    main

    The indexer recognizes patterns specific to popular web frameworks:

    React

    • Functional Components: Indexed as [class] (e.g., const UserCard: FC<Props> = ... becomes UserCard [class]).
    • Hooks: Indexed as [function] (e.g., function useUser() ... becomes useUser [function]).
    • forwardRef: Components using forwardRef are indexed as [class].

    Vue 3 (Composition API)

    • Extracts the <script> section.
    • Indexes interface Props as [interface].
    • Indexes const declarations (like ref or computed) as [constant].

    Svelte

    • Indexes export let as [property] (exported props).
    • Indexes standard functions in <script> as [function].

    NestJS & Angular

    • Decorators: Indexed as [annotation] (e.g., @Controller, @Injectable, @Component, @Module, @Get).
    • Classes: Indexed as [class] (e.g., UserController, UserComponent).
    • Methods: Indexed as [function] (e.g., findOne, ngOnInit).
  8. Understand the ast-index database schema

    main

    The database consists of 15 base tables and one FTS5 virtual table (symbols_fts).

    Core Tables

    • files: Stores file identity using (root_path, path). path is relative to the root, and root_path is the absolute normalized path. Freshness is tracked via mtime and size.
    • symbols: Contains code declarations. Key columns include name, qualified_name, kind, line, and file_id.
    • modules: Represents logical modules/packages.
    • refs: Stores code references. Note that refs.name is a string and does not point to a specific symbols.id to remain language-agnostic.
    • inheritance: Maps child symbols to a parent_name (string-based).
    • subtrees: Manages attached project roots, mapping original_path to a canonical_path used in files.root_path.

    Platform-Specific Tables

    • Android: resources, resource_usages, and xml_usages.
    • iOS: ios_assets, ios_asset_usages, and storyboard_usages.

    Metadata

    The metadata table is a string-to-string store. Common keys include:

    • project_root: Used for cache ownership and migrations.
    • last_update_at: Unix timestamp (ms) of the last file-index update.
    • no_ignore: 1 if ignored files were included.
    • bypass_size_check: Persistent opt-in for bypassing file size caps.
  9. Language-specific search capabilities

    main

    The ast-index tool provides specialized support for various languages. Below is a summary of supported elements for key languages:

    TypeScript/JavaScript

    • Classes, interfaces, type aliases, enums
    • Methods (constructor, getters/setters, static, async), fields, private #members
    • Functions (regular, arrow, async)
    • React components and hooks (useXxx)
    • Vue SFC, Svelte components, Decorators, Namespaces

    Rust

    • Structs, enums, traits, Impl blocks
    • Functions, macros (macro_rules!), Type aliases, constants, statics
    • Modules, use statements, Derive attributes

    Python / Go

    • Classes, Structs, Interfaces, Functions, Symbols
    • File structure (outline) and imports

    iOS (Swift/Objective-C)

    • Storyboard/XIB usages, Asset usages, SwiftUI props, Async functions, Combine publishers