[BUG] Claude Desktop (macOS): every Spotlight OS-entry refresh deletes the whole `com.anthropic.claude.os-entry` domain and re-indexes it, bloating the CoreSpotlight index and slowing all Spotlight searches

Aperta
#112,798 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
15/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
macos, swift, typescript

Direzione di ricerca

The refresh lives in the Swift ClaudeSwift.OsEntryPoints async path (setSpotlightEntries), which first calls deleteSearchableItemsWithDomainIdentifiers and then indexSearchableItems for every entry, and the JS caller r$a() in the desktop app bundle. Start by reading the Swift refresh and the JS trigger, then confirm the churn by counting deleteSearchableItemsWithDomainIdentifiers log lines for a session. Done would mean refreshes update items by identifier and only delete identifiers that disappeared, and unchanged refreshes are skipped. Reproducing needs macOS with the desktop app and Spotlight, so it is not a quick first-timer task.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area:desktop bug perf:reliability platform:macos
Summary

The desktop app's "OS entry points" feature lists recent Code sessions in Spotlight. Each refresh (setSpotlightEntries) first calls deleteSearchableItemsWithDomainIdentifiers(["com.anthropic.claude.os-entry"]), then re-indexes every entry: the 50 most recent sessions plus "New Claude Code session", "Ask Claude" and "Waiting for you". The JS side calls it whenever its session-list key changes.

The items already have stable uniqueIdentifiers. Even so, the domain-wide delete removes every item and re-inserts it as a new document. Over weeks of normal use, the app-content stores fill with dead document slots. Spotlight queries against those stores spend their time in bitmap operations over the whole ID range, and Spotlight doesn't show any results (even plain app launches) until that query returns. I measured a consistent 2–2.5 s delay.

Environment
  • Claude Desktop 7.37095.0 (macOS, Apple Silicon), Code tab in regular use
  • macOS 27.2 (Darwin 27.2.0)
Code path (decompiled app.asar.unpacked/node_modules/@ant/claude-swift/build/Release/swift_addon.node, arm64)
  • JS (app.asar): r$a() builds {model, entries, key}. If key !== IQ, it runs await $Qa(e => e.setSpotlightEntries(o)). Fea() produces the entries: 3 fixed URLs plus up to Sea = 50 non-archived sessions.
  • Swift ClaudeSwift.OsEntryPoints, async refresh with entry sub_BF6EC:
    1. sub_BF780: [CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithDomainIdentifiers:@[OsEntryPoints.spotlightDomain] completionHandler:, then awaits the result. The domain array is a static object containing com.anthropic.claude.os-entry.
    2. On success, sub_BF88C continues to sub_BF8E4.
    3. sub_BF8E4 loops over all SpotlightEntry values and builds a CSSearchableItemAttributeSet(contentType: .item) with title, displayName and contentDescription. It creates CSSearchableItem(uniqueIdentifier: entry.<first field>, domainIdentifier: "com.anthropic.claude.os-entry", attributeSet:), then calls indexSearchableItems:completionHandler: with the full array.
  • There is no diff against the previously indexed set. Every refresh is a full delete plus a full re-insert.
  • clearSpotlight (sub_BFE54) also deletes the domain. That one is fine.
Measurements
  • Spotlight UI log (Siri AI process, com.apple.SpotlightServices): the Metadata (files/apps) leg finishes in about 0.2 s, but results aren't drawn until [CoreSpotlight][priorityComplete] arrives. Over 12 h, that took a median of 1947 ms (max 2502 ms) on every search that ran to the end. Log line: Found no top hit from early priority index response. Not sending response early.
  • sample corespotlightd during a search: about 22.5k thread-samples across roughly 12 user-interactive threads in processNodes → _ContentIndexDocSetIteratorProcessIterHits → _CIIndexSetAddRange_Bitmap_Src_SparseDst / _CIIndexSetEnumeratorNext.
  • Store sizes (~/Library/Metadata/CoreSpotlight/<store>/index.spotlightV3/live.2.indexIds): 29.8 MB in NSFileProtectionCompleteUntilFirstUserAuthentication, roughly 7.4 M ID slots. Bundle-ID strings in that store's files: com.anthropic.claudefordesktop × 5,432, com.anthropic.claude.os-entry × 1,345. The next largest, com.apple.MobileSMS, appears × 438.
  • Write churn, attributed to the app: the CoreSpotlight client library logs inside the Claude process itself (Claude[<pid>] [com.apple.corespotlight:index] deleteSearchableItemsWithDomainIdentifiers, domainIdentifiers number:1). Over one hour of normal Code-tab use there were 276 of these, roughly one every 13 s, and up to 74 in a single 10-minute window. Each one wipes and re-adds all ~53 entries, which is about 14,000 new document IDs an hour. Reproduce with: log show --last 1h --predicate 'process == "Claude" AND subsystem == "com.apple.corespotlight"'
Workaround / confirmation

Moving the bloated stores aside and restarting corespotlightd brought priorityComplete from about 2.0 s down to 37–177 ms. Expect the delay to come back as the churn continues.

A caveat: the Priority store (15.2 MB of IDs) was also bloated, but Claude's entries are only a small part of it. Part of the slowdown is Apple's index design, which apparently doesn't compact dead slots and blocks the UI on the priority leg. That part is being reported to Apple separately.

Suggested fix
  • Drop the domain-wide delete. The uniqueIdentifiers are already stable, so indexSearchableItems on the current entries updates them in place. Call deleteSearchableItemsWithIdentifiers only for identifiers that disappeared since the last refresh.
  • Skip the refresh entirely when titles, details and IDs are unchanged, and debounce bursts.
  • Optionally, add a user setting to turn off the Spotlight and Dock OS entries. Today only the disableDeepLinks policy turns them off.
Lingua principale
TypeScript
Stelle
157k
Fork
25.1k
Merge medio
20h 25m
PR unite (30g)
4

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anthropics/claude-code

Tutte le issue di anthropics/claude-code

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.