Learn Kiro CLI in 10 DaysDay 6: Code Intelligence
books.chapter 6Learn Kiro CLI in 10 Days

Dual-Layer Code Intelligence

Kiro CLI provides two layers of code understanding:

Layer Technology Setup Characteristics
Layer 1 Tree-sitter (built-in) None Works immediately, 18 languages
Layer 2 LSP integration (optional) /code init required References, rename, type info

Tree-sitter works without installing any language servers, so you can start using code intelligence features right away. Adding LSP integration unlocks even more advanced capabilities.

Tree-sitter Features

Supported Languages

Bash, C, C++, C#, Elixir, Go, Java, JavaScript, Kotlin, Lua, PHP, Python, Ruby, Rust, Scala, Swift, TSX, and TypeScript β€” 18 languages in total.

Symbol Search

Fuzzy-matched discovery of functions, classes, and methods:

> Where is the handleSubmit function defined?

Kiro CLI automatically uses the code tool to perform symbol searches.

Document Symbols

Enumerate all symbols (functions, classes, variables) within a specific file:

> Show all functions defined in src/api/handlers.ts

Symbol Lookup

Precise retrieval by name:

> Show me the UserService class definition

Codebase Overview

The /code overview command gives a high-level view of your workspace:

> /code overview

Displays project directory structure, key files, and dependency overview.

Codebase Map

Analyzes directory structure and organization:

> Analyze the architecture of this project

Code Summary Generation

The /code summary command auto-generates project documentation:

> /code summary

Interactively generates AGENTS.md, README.md, CONTRIBUTING.md, and similar files.

LSP Integration

Setup

Enable LSP integration by running /code init in your project root:

> /code init

Language servers are automatically set up for detected languages.

Installing Language Servers

Install the appropriate language server before running /code init:

# TypeScript / JavaScript
npm install -g typescript-language-server typescript

# Python
pip install pyright
# or
pipx install pyright

# Rust
rustup component add rust-analyzer

# Go
go install golang.org/x/tools/gopls@latest

Features Added by LSP

Feature Description
Find references Search where a symbol is used across the codebase
Go to definition Jump to a symbol's definition
Rename Project-wide symbol renaming
Diagnostics Display file errors and warnings
Type information Show types for variables and functions
Completions Context-aware code completion

Practical Examples

> Find all places where handleSubmit is used

> Rename UserService to UserManager

> Show errors and warnings in src/api/handlers.ts

Pattern Search and Rewrite

Structural code search and transformation using Tree-sitter's AST (Abstract Syntax Tree).

Metavariables

Special variables used in patterns:

Metavariable Matches
$VAR A single node (identifier, expression, etc.)
$$$ Zero or more nodes

Pattern Search Examples

> Search for the pattern var $N = $V

Matches all var declarations.

> Search for the pattern console.log($$$)

Matches all console.log calls.

Pattern Rewrite

Transform matched code into a different pattern:

> Convert var $N = $V to const $N = $V

Use dry_run: true to preview changes before applying:

> Convert var $N = $V to const $N = $V (preview only)

Practical Transformations

# Convert require to import
> Convert const $N = require($M) to import $N from $M

# Remove console logs
> Search for console.log($$$) and delete all matches

# Change test function naming
> Convert test($NAME, $$$) to it($NAME, $$$)
flowchart TB
    subgraph TreeSitter["Tree-sitter (Built-in)"]
        TS1["Symbol Search"]
        TS2["Document Symbols"]
        TS3["Pattern Search/Rewrite"]
        TS4["Codebase Overview"]
    end
    subgraph LSP["LSP Integration (Optional)"]
        L1["Find References"]
        L2["Go to Definition"]
        L3["Rename"]
        L4["Diagnostics & Types"]
    end
    Init["/code init"]
    TreeSitter -->|"Immediate"| Code["Code Intelligence"]
    Init --> LSP
    LSP -->|"After setup"| Code
    style TreeSitter fill:#3b82f6,color:#fff
    style LSP fill:#8b5cf6,color:#fff
    style Code fill:#22c55e,color:#fff

Managing Code Intelligence

Check Status

> /code status

View LSP server states (starting, connected, error, etc.).

View Logs

> /code logs

Display LSP server debug logs for troubleshooting.

Best Practices

Topic Recommendation
Initialization Run /code init once per project
Language servers Install servers for your languages beforehand
Pattern rewrite Preview with dry_run before applying
Search precision Use specific symbol names or patterns
Diagnostics Verify file syntax is correct before analysis

Summary

Topic Details
Tree-sitter 18 languages, no setup, built-in
LSP integration Enable with /code init, references/rename/types
Pattern search AST-based structural code search
Pattern rewrite Bulk transform with $VAR and $$$ metavariables
/code overview Project structure overview
/code summary Auto-generate documentation

In Day 7, you'll learn about steering files and context management.