Claude Code 透過重構檔案索引機制,成功將 @-mentions 搜尋效能提升三倍
AI 語音朗讀 · Edge TTS
Claude Code 透過重構檔案索引機制,成功將 @-mentions 搜尋效能提升三倍。
Claude Code 開發團隊近期針對大型企業級程式庫進行效能優化,透過將原本基於 Rust 的檔案索引系統遷移至原生 TypeScript,成功解決了在龐大專案中搜尋延遲的問題,並將 P99 延遲降低至 10 毫秒以下。
技術重構與效能優化
為了改善 Claude Code 在大型程式庫中輸入「@-mentions」時的卡頓感,開發團隊決定捨棄原本透過 NAPI 呼叫 Rust 檔案索引器的架構。團隊利用 Claude Opus 協助將索引器移植至原生 TypeScript,並透過嚴格的測試與效能分析,確保新實作的效能優於舊版。此次效能提升主要歸功於以下三點:
- 採用非阻塞主執行緒的預先計算策略。
- 針對小型結果集,避免了 NAPI 的額外開銷。
- 透過反覆要求 Claude 進行效能分析與優化,持續改進檔案搜尋演算法。
大型專案的彈性配置
針對無法完全依賴內建索引的大型程式庫,Claude Code 引入了新的 fileSuggestion 設定。此功能允許使用者整合自定義的程式碼索引工具(如 SourceGraph 或內部開發的索引系統),以適應極端複雜的專案需求。
階層式設定架構
Claude Code 透過一套嚴謹的範圍系統(Scope System)來管理設定,確保企業環境下的配置一致性與靈活性。設定優先級由高至低依序為:Managed(受管)、命令列參數、Local(本機)、Project(專案)、User(使用者)。
- Managed Scope:由 IT 或 DevOps 部署,用於強制執行安全政策與合規要求,使用者無法覆寫。
- Project Scope:儲存於
.claude/settings.json,適合團隊共享的設定與插件。 - User Scope:儲存於
~/.claude/目錄,適用於個人偏好與跨專案工具。 - Local Scope:儲存於
.claude/settings.local.json,專供個人測試或機器專屬設定,並預設由 Git 忽略。
實際影響
此次效能優化已於 v2.1.85 版本中正式發布。透過將檔案索引邏輯轉移至 TypeScript 並優化執行路徑,Claude Code 在處理大規模程式庫時的互動體驗獲得顯著改善,解決了開發者在輸入指令時感受到的延遲問題。
Just got a nice DM from a big enterprise customer using Claude Code in one of the world's biggest codebases
— Boris Cherny (@bcherny) April 9, 2026
Here's how we made @-mentions 3x faster in large enterprise codebases 🧵 pic.twitter.com/cDDeJ399ff
To power file @-mentions in Claude Code, we used to use a custom Rust-based file indexer that we invoked from Claude Code via NAPI. It was pretty fast.
— Boris Cherny (@bcherny) April 9, 2026
But in big codebases, it would fall over.
— Boris Cherny (@bcherny) April 9, 2026
So we introduced a new fileSuggestion setting in Claude Code, so customers with large codebases could plug in their custom code index (using SourceGraph, an in-house index, etc.).https://t.co/8AAzKtzNkE
To simplify our system, I asked Opus to port the file indexer to native TypeScript. Here's the prompt I used:
— Boris Cherny (@bcherny) April 9, 2026
> compile our rust+napi file index to native ts. compile the code over, and make sure the code perfectly passes the ORIGINAL test suite from the package. then profile…
After a few hours, I had a PR. The results were solid -- P99 got 3x faster after porting to TypeScript! pic.twitter.com/N6sOk2hODu
— Boris Cherny (@bcherny) April 9, 2026
The wins came from three places:
— Boris Cherny (@bcherny) April 9, 2026
1. Pre-computing upfront in a clever way that doesn't block the main thread
2. Avoiding NAPI overhead for small result sets
3. Iteratively asking Claude to find perf improvements for faster file search pic.twitter.com/5I5SS4fdNd
Enjoy faster @-mentions in Claude Code! This went out in v2.1.85.
— Boris Cherny (@bcherny) April 9, 2026
