Code Intelligence Tools
Claude Code includes two tools for advanced code understanding and tool management: LSPTool for Language Server Protocol operations, and ToolSearchTool for discovering deferred tools.
LSPTool
Provides IDE-grade code intelligence through the Language Server Protocol. LSPTool communicates with connected language servers to perform operations like jump-to-definition, find references, and hover information.
Parameters
The LSP operation to perform. One of: goToDefinition, findReferences, hover, documentSymbol, workspaceSymbol, goToImplementation, prepareCallHierarchy, incomingCalls, outgoingCalls.
Absolute or relative path to the file.
Line number (1-based, as shown in editors).
Character offset (1-based, as shown in editors).
Supported Operations
goToDefinition
Jumps to the definition of the symbol at the given position. Returns the file path, line, and character of the definition. Useful for navigating to where a function, class, or variable is defined.
findReferences
Finds all references to the symbol at the given position across the workspace. Returns a list of locations where the symbol is used. Essential for understanding the impact of changes.
hover
Returns type information and documentation for the symbol at the given position. Provides the same information you see when hovering in an IDE.
documentSymbol
Lists all symbols (functions, classes, variables, etc.) in the specified file. Useful for understanding file structure without reading the entire file. Does not require line or character parameters.
workspaceSymbol
Searches for symbols across the entire workspace by name. Does not require line or character parameters.
goToImplementation
Finds the implementation of an interface or abstract method. Navigates from type declarations to their concrete implementations.
prepareCallHierarchy
Prepares call hierarchy information for the symbol at the given position. Returns call hierarchy items that can be used with incomingCalls and outgoingCalls.
incomingCalls
Lists all callers of the function at the given position. Shows where a function is called from across the codebase.
outgoingCalls
Lists all functions called by the function at the given position. Shows the call graph emanating from a given function.
Validation
LSPTool validates input through several checks:
- Parses input against a discriminated union schema for better type safety
- Verifies the file exists and is a regular file
- Rejects files larger than 10MB (
MAX_LSP_FILE_SIZE_BYTES = 10_000_000) - Rejects UNC paths on Windows (NTLM credential leak prevention)
- Waits for LSP server initialization before performing operations
Result Formatting
Each operation has a dedicated formatter that converts raw LSP responses into human-readable text:
formatGoToDefinitionResult: Formats definition locationsformatFindReferencesResult: Formats reference lists with file groupingformatHoverResult: Formats type information and documentationformatDocumentSymbolResult: Formats symbol treesformatWorkspaceSymbolResult: Formats workspace-wide symbol search resultsformatPrepareCallHierarchyResult: Formats call hierarchy itemsformatIncomingCallsResult/formatOutgoingCallsResult: Format call graphs
Availability
LSPTool is enabled when ENABLE_LSP_TOOL is set to a truthy value AND at least one LSP server is connected (isLspConnected()). The tool integrates with the LSP server manager at src/services/lsp/manager.ts.
Key Properties
- Read-only: Yes
- Concurrency-safe: Yes
- Deferred: Yes (requires ToolSearch)
- isLsp: true
- maxResultSizeChars: 100,000
ToolSearchTool
Fetches full schema definitions for deferred tools. When many tools are available (especially with MCP servers), not all tool schemas are sent in the initial prompt. ToolSearchTool allows Claude to discover and load schemas on demand.
Parameters
Query to find deferred tools. Supports two forms: "select:ToolName" for direct selection by name, or keywords for fuzzy search.
Maximum number of results to return. Default: 5.
Search Algorithm
ToolSearchTool uses a multi-strategy scoring approach:
-
Direct selection: Queries starting with
select:fetch tools by exact name match. Supports comma-separated lists (e.g.,select:Read,Edit,Grep). -
Keyword search: For free-text queries, the tool scores each deferred tool by:
- Name matching: Parses CamelCase names and MCP tool names (
mcp__server__action) into searchable parts - searchHint matching: Each tool's
searchHintproperty provides additional keywords not in the name - Description matching: The tool's full prompt/description is searched (memoized for performance)
- Name matching: Parses CamelCase names and MCP tool names (
Tool Name Parsing
// CamelCase tools: FileReadTool -> ["file", "read", "tool"]
// MCP tools: mcp__server__action -> ["server", "action"]
function parseToolName(name: string): { parts: string[], full: string, isMcp: boolean }Cache Invalidation
Tool descriptions are memoized by tool name. The cache is invalidated when the set of deferred tools changes (e.g., when MCP servers connect or disconnect mid-session).
Output
{
matches: string[] // Tool names that matched
query: string // The original query
total_deferred_tools: number // Total count of deferred tools
pending_mcp_servers?: string[] // MCP servers still connecting
}ToolSearchTool is only included in the tool pool when isToolSearchEnabledOptimistic() returns true. This optimistic check evaluates whether the total tool count exceeds the threshold for deferred loading.
Key Properties
- Read-only: Yes
- Concurrency-safe: Yes
- maxResultSizeChars: 100,000
Key Source Files
src/tools/LSPTool/LSPTool.ts: LSP operations and validationsrc/tools/LSPTool/schemas.ts: Discriminated union input schema for LSP operationssrc/tools/LSPTool/formatters.ts: Result formatters for each LSP operationsrc/tools/ToolSearchTool/ToolSearchTool.ts: Tool search and schema fetchingsrc/utils/toolSearch.ts: Deferred tool enablement logic