Get the FREE Ultimate OpenClaw Setup Guide →

codebase-explorer

npx machina-cli add skill madeinoz67/madeinoz-knowledge-system/codebase-explorer --openclaw
Files (1)
SKILL.md
4.3 KB

Search Query Analysis

Query Optimization Skill

Codanna's semantic search works best with technical terms and specific concepts. Analyze the situation and optimize your codebase explore queries for code search:

Examples:

  1. If vague (e.g., "that parsing thing") → Make it specific (e.g., "language parser implementation")
  2. If a question (e.g., "how does parsing work?") → Extract keywords (e.g., "parsing implementation process")
  3. If conversational (e.g., "the stuff that handles languages") → Use technical terms (e.g., "language handler processor")
  4. If too broad (e.g., "errors") → Add context (e.g., "error handling exception management")

OptimizedQuery: {Claude: I will write my optimized query here, then use it below}

Execute this command with your optimized query:

Your Workflow <Workflow>

Gather Context <Step_1 GatherContext>

Use the Bash tool to perform semantic code search:

Execute: codanna mcp semantic_search_with_context query:"$OptimizedQuery" limit:5

What Codanna returns:

  • Relevance scores (how well each result matches)
  • Symbol signatures and documentation
  • Relationships (calls, called_by, implements, defines)
  • File locations with line ranges

Your Workflow <Step_2 YourWorkflow>

  1. Analyze the results with their relevance scores (focus on results with score > 0.6 (if possible))

  2. To see actual implementation of interesting results:

    • Use the line range from the Location field to read just the relevant code
    • Example: If you see "at src/io/exit_code.rs:108-120"
    • Use the Read tool with:
      • file_path: src/io/exit_code.rs (use the working directory from your environment context <env> to construct the absolute path)
      • offset: 108 (start line)
      • limit: 13 (calculated as: 120 - 108 + 1)
    • Formula: limit = end_line - start_line + 1
    • Example: Read(file_path="/full/path/to/src/io/exit_code.rs", offset=108, limit=13)
  3. When relationships are shown (called_by, calls, defines, implements):

    • If a relationship looks relevant to answering the query, investigate it
    • Execute: codanna retrieve describe <relationship_symbol_name|symbol_id:ID>
    • Example: If you see "Called by: initialize_registry [symbol_id:123]", run: codanna retrieve describe initialize_registry or describe symbol_id:123
    • Note: Following 1-2 key relationships per result is typically sufficient
  4. Build a complete picture by following key relationships and reading relevant code sections

  5. If needed, repeat <Step_1: GatherContext> with a refined query based on what you learned.


Tips for Efficient Exploration

The results include:

  • Relevance scores (how well each result matches the query)
  • Symbol documentation and signatures
  • Relationships (who calls this, what it calls, what it defines)
  • System guidance for follow-up investigation

sed (native on unix only):

  • You can also see actual implementation with sed: (works native on Unix based environments):

    • Use the line range from the Location field to read just the relevant code
    • Example: If you see "Location: src/io/exit_code.rs:108-120"
    • Execute: sed -n '108,120p' src/io/exit_code.rs to read lines 108-120
    • This shows the actual code implementation, not just the signature. It works like the Read tool.
  • Add lang:rust (or python, typescript, etc.) to narrow results by language if you work on multi-language projects

  • Follow relationships that appear in multiple results (they're likely important)

  • Use the describe command to get full details about interesting relationships

Token awareness:

  • Each search uses ~500 tokens
  • Each relationship follow uses ~300 tokens
  • Each file read uses ~100-500 tokens (depends on size)
  • Staying efficient keeps your context window clean for deeper analysis

This command is for exploration:

  • Build understanding of the codebase
  • Identify patterns and integration points
  • Present findings and await user direction
  • Don't start implementing or making changes yet

Based on the gathered context, engage with the user to narrow focus and help the user with further request.

Source

git clone https://github.com/madeinoz67/madeinoz-knowledge-system/blob/main/.claude/skills/codebase-explorer/SKILL.mdView on GitHub

Overview

codebase-explorer helps you understand a codebase by running semantic searches and mapping relationships between symbols. It surfaces relevant symbols, docs, and relationships (calls, called_by, defines, implements) to build a coherent picture of how the system components fit together.

How This Skill Works

It uses codanna's semantic_search_with_context to fetch top results with relevance scores, symbol signatures, and relationships. You then read precise code ranges with Read or sed, and follow key relationships with describe to deepen understanding and trace dependencies.

When to Use It

  • You’re onboarding to a large codebase and need a quick, structured mental model of how components fit together.
  • You’re debugging a bug and want to trace a function across its call chain and dependent modules.
  • You want to understand a module’s public interface and how it defines or implements its contracts.
  • You need to assess coupling and dependencies across components, possibly across multiple languages.
  • You’re documenting the codebase for teammates and want reproducible, relation-driven exploration steps.

Quick Start

  1. Step 1: Define an OptimizedQuery focused on the target area (e.g., specific subsystem or function).
  2. Step 2: Run semantic search: codanna mcp semantic_search_with_context query:"<OptimizedQuery>" limit:5
  3. Step 3: For each result with a useful Location, read code with Read(file_path="/full/path/to/file", offset=start, limit=end-start+1); if relationships appear, run codanna retrieve describe <relationship> to explore deeper.

Best Practices

  • Start with a tightly scoped OptimizedQuery that uses concrete technical terms instead of vague language.
  • Prioritize results with relevance scores (focus on score > 0.6 when possible) to reduce noise.
  • Read actual implementations by using the Location line ranges with Read or sed to inspect code, not just signatures.
  • Follow 1-2 key relationships per result (e.g., calls, defines, implements) to keep exploration focused.
  • Filter results by language using lang (rust, python, typescript, etc.) when the repo is multi-language.

Example Use Cases

  • Map out the language parser implementation by locating the implement/defines relationships and reading the relevant source range.
  • Trace an error path across modules by following called_by and calls relationships to identify where the failure propagates.
  • Inspect a module’s interface and its implementing types or functions to evaluate compatibility and contracts.
  • Compare related components across languages by narrowing with lang to identify cross-language interactions.
  • Onboard a new engineer by generating a module-level map of interfaces, implementations, and dependencies.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers