Claude Code 不必搜尋得更勤,而要看懂程式碼
Claude Code doesn't need to search harder. It needs to see the code.
作者主張為 Claude Code 接入語言伺服器,讓它按程式碼符號查找定義、引用和型別,而非只依賴文字搜尋。文中指出,程式碼變動會令筆記中的行號失效,語言伺服器則可按名稱定位程式碼。設定方法是按語言安裝伺服器及對應插件,並確認工具呼叫使用 LSP;作者亦建議在 `CLAUDE.md` 加入 `find code by name, never by line number`。
Every line number in the task notes was wrong.
Not one or two. All of them. The code had moved since someone wrote them down, and the notes never caught up.
A person would notice in a minute. An agent that trusts the notes reads the wrong lines, then writes a confident explanation of code that isn't there anymore.
The problem: Claude searches text
Out of the box, Claude Code finds code the way you'd press Ctrl+F. Ask "where is getUser used?" and a text search returns:
- The real calls to
getUser. -
getUserSettings, because it contains the same letters. - A comment that mentions it.
- A different
getUserin another file.
No error. Just a slightly wrong picture the agent builds on.
The fix: a language server
A language server is the program behind "go to definition" and "find all references" in your editor. It understands code instead of reading it as text: which getUser is which, what calls what, and what type everything is.
Give one to Claude Code and it can find every real caller, jump to definitions across files, and check types without running anything.
Why not just search better?
Text search finds where these letters appear. You almost always want where this thing is used.
Line numbers are an address. Names are an identity. Code moves and line numbers break, but a language server still finds the thing by name.
Set it up
Two steps per language. Install the language server, then the plugin that connects it:
npm install -g pyright # Python
npm install -g typescript-language-server typescript # TypeScript / JS
/plugin install pyright-lsp@claude-plugins-official
/plugin install typescript-lsp@claude-plugins-official
The test: ask Claude to "find every place that calls <a function>, using the language server". If the tool calls show LSP instead of a text search, it works.
And add one line to your CLAUDE.md: find code by name, never by line number.
This is part 3 of Claude Maxxing, a field journal of the systems I build around Claude Code on real work. The full post covers the comparison table, the gotchas that make it fail quietly, and what it still doesn't fix:
來源:DEV Community · dev.to