Code Intelligence provides two complementary layers of code understanding:
Tree-sitter (Built-in) - Out-of-the-box code intelligence for 18 languages. Search symbols with fuzzy matching, get document symbols, and lookup definitions without installing an LSP. With incremental loading and support for millions of tokens of indexed content, agents can efficiently search large codebases.
LSP Integration (Optional) - Enhanced precision with find references, go to definition, hover documentation, rename refactoring, and diagnostics. Requires language server installation.
Bash, C, C++, C#, Elixir, Go, Java, JavaScript, Kotlin, Lua, PHP, Python, Ruby, Rust, Scala, Swift, TSX, TypeScript
Code Intelligence provides these operations (no LSP required):
With LSP enabled (optional), additional operations become available:
Get a complete overview of any workspace in seconds:
/code overview
Specify a path to focus on a specific directory:
/code overview ./src/components
Use --silent for a cleaner output when diving deep into a package:
/code overview --silent
Ideal for:
Generate documentation for your codebase with an interactive session:
/code summary
This starts an interactive session where you can choose the output format:
The generated documentation is based on analysis of your codebase structure, dependencies, and code patterns.
AST-based structural code search and transformation. Find and modify code by structure, not just text.
$VAR - Matches single node (identifier, expression)$$$ - Matches zero or more nodes (statements, parameters)// Find all console.log calls pattern: console.log($ARG) language: javascript // Find all async functions pattern: async function $NAME($$$PARAMS) { $$$ } language: typescript // Find all .unwrap() calls pattern: $E.unwrap() language: rust
// Convert var to const pattern: var $N = $V replacement: const $N = $V language: javascript // Modernize hasOwnProperty pattern: $O.hasOwnProperty($P) replacement: Object.hasOwn($O, $P) language: javascript // Convert unwrap to expect pattern: $E.unwrap() replacement: $E.expect("unexpected None") language: rust
pattern_search first to verify matchespattern_rewrite with dry_run: true to previewdry_run: falseRun /code init to unlock full LSP-powered code intelligence with enhanced features like find references, hover documentation, and rename refactoring.
Kiro CLI spawns LSP server processes in the background that communicate via JSON-RPC over stdio. When you initialize a workspace, it detects languages from project markers (like package.json, Cargo.toml) and file extensions, then starts the appropriate language servers. These servers continuously analyze your code and maintain an index of symbols, types, and references. When you make queries, Kiro translates your natural language into LSP protocol requests, sends them to the relevant server, and formats the responses back into readable output.
Default LSP configurations are included for: C/C++, Go, Java, Kotlin, Python, Ruby, Rust, TypeScript/JavaScript
TypeScript/JavaScript
npm install -g typescript-language-server typescript
Rust
rustup component add rust-analyzer
Python
pip install pyright # or with pipx (recommended for isolation) pipx install pyright
Go
go install golang.org/x/tools/gopls@latest
Java
# macOS brew install jdtls # Linux - download from https://download.eclipse.org/jdtls/snapshots/ # Extract and add to PATH
Ruby
gem install solargraph
C/C++
# macOS brew install llvm # or brew install clangd # Linux (Debian/Ubuntu) sudo apt install clangd # Linux (Arch) sudo pacman -S clang
Kotlin
brew install kotlin-language-server
Run this slash command in your project root:
/code init
This creates lsp.json configuration and starts language servers.
What you'll see:
✓ Workspace initialization started Workspace: /path/to/your/project Detected Languages: ["python", "rust", "typescript"] Project Markers: ["Cargo.toml", "package.json"] Available LSPs: ○ clangd (cpp) - available ○ gopls (go) - not installed ◐ jdtls (java) - initializing... ✓ pyright (python) - initialized (687ms) ✓ rust-analyzer (rust) - initialized (488ms) ○ solargraph (ruby) - not installed ✓ typescript-language-server (typescript) - initialized (214ms)
Status indicators:
Restart LSP servers: If language servers shut down or become unresponsive, use /code init -f.
Auto-initialization: After the first /code init, Kiro CLI automatically initializes code intelligence on startup when lsp.json exists in the workspace.
Disabling code intelligence: Delete lsp.json from your project root to disable. Re-enable anytime with /code init.
Language servers provide semantic code intelligence through natural language queries. You can search symbols, navigate definitions, find references, rename across files, get diagnostics, view method documentation, and discover available APIs on classes and objects.
Find a symbol:
> Find the UserRepository class Searching for symbols matching: "UserRepository" 1. Class UserRepository at src/repositories/user.repository.ts:15:1
Find all references:
> Find references of Person class Finding all references at: auth.ts:42:10 1. src/auth.ts:42:10 - export function authenticate(...) 2. src/handlers/login.ts:15:5 - authenticate(credentials) 3. src/handlers/api.ts:89:12 - await authenticate(token)
Go to definition:
> Find the definition of UserService src/services/user.service.ts:42:1: export class UserService { ...
Get file symbols:
> What symbols are in auth.service.ts? Getting symbols from: auth.service.ts 1. Class AuthService at auth.service.ts:12:1 2. Function login at auth.service.ts:25:3 3. Function logout at auth.service.ts:45:3 4. Function validateToken at auth.service.ts:62:3
Rename with dry run:
> Dry run: rename the method "FetchUser" to "fetchUserData" Dry run: Would rename 12 occurrences in 5 files
Get diagnostics:
> Get diagnostics for main.ts 1. Error line 15:10: Cannot find name 'undefined_var' 2. Warning line 42:5: 'result' is declared but never used
Get hover documentation:
> What's the documentation for the authenticate method in AuthService? Type: (credentials: Credentials) => Promise<AuthResult> Documentation: Authenticates a user with the provided credentials. Returns an AuthResult containing the user token and profile. @param credentials - User login credentials @throws AuthenticationError if credentials are invalid
Discover available methods:
> What methods are available on the s3Client instance? Available completions: 1. putObject - Function: (params: PutObjectRequest) => Promise<PutObjectOutput> 2. getObject - Function: (params: GetObjectRequest) => Promise<GetObjectOutput> 3. deleteObject - Function: (params: DeleteObjectRequest) => Promise<DeleteObjectOutput> 4. listObjects - Function: (params: ListObjectsRequest) => Promise<ListObjectsOutput> 5. headObject - Function: (params: HeadObjectRequest) => Promise<HeadObjectOutput>
Add custom language servers by editing lsp.json in your project root:
{ "languages": { "mylang": { "name": "my-language-server", "command": "my-lsp-binary", "args": ["--stdio"], "file_extensions": ["mylang", "ml"], "project_patterns": ["mylang.config"], "exclude_patterns": ["**/build/**"], "multi_workspace": false, "initialization_options": { "custom": "options" }, "request_timeout_secs": 60 } } }
Fields:
After editing, restart Kiro CLI to load the new configuration.
/code initInitialize code intelligence in current directory.
/code init -fForce re-initialization (restart all LSP servers).
/code statusShow workspace status and LSP server states.
/code logsDisplay LSP logs for troubleshooting.
/code logs # Show last 20 ERROR logs /code logs -l INFO # Show INFO level and above /code logs -n 50 # Show last 50 entries /code logs -l DEBUG -n 100 # Show last 100 DEBUG+ logs /code logs -p ./lsp-logs.json # Export logs to JSON file
Options:
-l, --level <LEVEL>: Log level filter (ERROR, WARN, INFO, DEBUG, TRACE). Default: ERROR-n, --lines <N>: Number of log lines to display. Default: 20-p, --path <PATH>: Export logs to JSON file| Language | Extensions | Server | Install Command |
|---|---|---|---|
| TypeScript/JavaScript | .ts, .js, .tsx, .jsx | typescript-language-server | npm install -g typescript-language-server typescript |
| Rust | .rs | rust-analyzer | rustup component add rust-analyzer |
| Python | .py | pyright | pip install pyright |
| Go | .go | gopls | go install golang.org/x/tools/gopls@latest |
| Java | .java | jdtls | brew install jdtls (macOS) |
| Ruby | .rb | solargraph | gem install solargraph |
| C/C++ | .c, .cpp, .h, .hpp | clangd | brew install llvm (macOS) or apt install clangd (Linux) |
| Kotlin | .kt, .kts | kotlin-language-server | brew install kotlin-language-server |
| Issue | Cause(s) | Solution |
|---|---|---|
| Code tool is not enabled for this agent | Agent doesn't have the code tool in its tool list | Add "code" to the agent's tools array, or use @builtin to include all built-in tools, or use @builtin/code |
| Workspace is still initializing | LSP servers are starting up | Wait and try again. If servers crashed, use /code init -f to restart |
| LSP initialization failed | Check logs for details: /code logs -l ERROR | |
| No symbols found | Language server is still indexing or File has syntax errors or Symbol name doesn't match | Check file for errors, try broader search terms |
| No definition found | Position doesn't point to a symbol | Verify the row and column numbers point to a symbol name |
/code init in project root if you want enhanced LSP features like find references and rename. Built-in tree-sitter code intelligence works without initialization.
Code Intelligence