Claude Code LSP tool: 100x faster code search than grep

Source

Summary

Claude Code defaults to grep for code search, which is slow (~5-6 seconds), token-hungry, and returns imprecise matches. Enabling LSP (Language Server Protocol) gives Claude the same structural code intelligence as an IDE, returning exact definitions in ~50 ms - roughly 100x faster while burning far fewer tokens.

Key Insight

Claude Code’s default grep-based search treats code as plain text, leading to false matches on comments and similarly-named variables, plus unnecessary full-file reads that waste tokens. LSP understands code structure (definitions, references, symbols) rather than just pattern-matching text.

Key performance difference:

  • Grep: 5-6 seconds per cross-codebase search, frequent wrong matches, reads entire files
  • LSP: ~50 ms for exact definition lookup, no wasted token reads

The setup is a 4-step, 2-minute process:

  1. Add enableLSPTool="1" to the env block in Claude Code’s settings.json
  2. Install language servers for your stack (TypeScript, Python, etc.) - one NPM install line covers most
  3. Add a rule to your CLAUDE.md telling Claude to prefer LSP over grep for code navigation (it won’t default to LSP unless explicitly instructed)
  4. Restart Claude Code

Verification: ask Claude to run document/symbol on any file - if it maps every function and variable with line numbers instantly, it’s working.

The author also mentions “CARL” (just-in-time rule injection system for Claude Code) which can set LSP-first as a global rule across all projects and sessions.