AI Assistant

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

operationstringrequired

The LSP operation to perform. One of: goToDefinition, findReferences, hover, documentSymbol, workspaceSymbol, goToImplementation, prepareCallHierarchy, incomingCalls, outgoingCalls.

filePathstringrequired

Absolute or relative path to the file.

linenumberrequired

Line number (1-based, as shown in editors).

characternumberrequired

Character offset (1-based, as shown in editors).

Supported Operations

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.

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.

Returns type information and documentation for the symbol at the given position. Provides the same information you see when hovering in an IDE.

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.

Searches for symbols across the entire workspace by name. Does not require line or character parameters.

Finds the implementation of an interface or abstract method. Navigates from type declarations to their concrete implementations.

Prepares call hierarchy information for the symbol at the given position. Returns call hierarchy items that can be used with incomingCalls and outgoingCalls.

Lists all callers of the function at the given position. Shows where a function is called from across the codebase.

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:

  1. Parses input against a discriminated union schema for better type safety
  2. Verifies the file exists and is a regular file
  3. Rejects files larger than 10MB (MAX_LSP_FILE_SIZE_BYTES = 10_000_000)
  4. Rejects UNC paths on Windows (NTLM credential leak prevention)
  5. 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 locations
  • formatFindReferencesResult: Formats reference lists with file grouping
  • formatHoverResult: Formats type information and documentation
  • formatDocumentSymbolResult: Formats symbol trees
  • formatWorkspaceSymbolResult: Formats workspace-wide symbol search results
  • formatPrepareCallHierarchyResult: Formats call hierarchy items
  • formatIncomingCallsResult / 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

querystringrequired

Query to find deferred tools. Supports two forms: "select:ToolName" for direct selection by name, or keywords for fuzzy search.

max_resultsnumber

Maximum number of results to return. Default: 5.

Search Algorithm

ToolSearchTool uses a multi-strategy scoring approach:

  1. Direct selection: Queries starting with select: fetch tools by exact name match. Supports comma-separated lists (e.g., select:Read,Edit,Grep).

  2. 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 searchHint property provides additional keywords not in the name
    • Description matching: The tool's full prompt/description is searched (memoized for performance)

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 validation
  • src/tools/LSPTool/schemas.ts: Discriminated union input schema for LSP operations
  • src/tools/LSPTool/formatters.ts: Result formatters for each LSP operation
  • src/tools/ToolSearchTool/ToolSearchTool.ts: Tool search and schema fetching
  • src/utils/toolSearch.ts: Deferred tool enablement logic