MCPcopy Index your code
hub / github.com/codeaashu/claude-code / startBackgroundHousekeeping

Function startBackgroundHousekeeping

src/utils/backgroundHousekeeping.ts:31–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29const DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION = 10 * 60 * 1000
30
31export function startBackgroundHousekeeping(): void {
32 void initMagicDocs()
33 void initSkillImprovement()
34 if (feature('EXTRACT_MEMORIES')) {
35 extractMemoriesModule!.initExtractMemories()
36 }
37 initAutoDream()
38 void autoUpdateMarketplacesAndPluginsInBackground()
39 if (feature('LODESTONE') && getIsInteractive()) {
40 void registerProtocolModule!.ensureDeepLinkProtocolRegistered()
41 }
42
43 let needsCleanup = true
44 async function runVerySlowOps(): Promise<void> {
45 // If the user did something in the last minute, don't make them wait for these slow operations to run.
46 if (
47 getIsInteractive() &&
48 getLastInteractionTime() > Date.now() - 1000 * 60
49 ) {
50 setTimeout(
51 runVerySlowOps,
52 DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION,
53 ).unref()
54 return
55 }
56
57 if (needsCleanup) {
58 needsCleanup = false
59 await cleanupOldMessageFilesInBackground()
60 }
61
62 // If the user did something in the last minute, don't make them wait for these slow operations to run.
63 if (
64 getIsInteractive() &&
65 getLastInteractionTime() > Date.now() - 1000 * 60
66 ) {
67 setTimeout(
68 runVerySlowOps,
69 DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION,
70 ).unref()
71 return
72 }
73
74 await cleanupOldVersions()
75 }
76
77 setTimeout(
78 runVerySlowOps,
79 DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION,
80 ).unref()
81
82 // For long-running sessions, schedule recurring cleanup every 24 hours.
83 // Both cleanup functions use marker files and locks to throttle to once per day
84 // and skip immediately if another process holds the lock.
85 if (process.env.USER_TYPE === 'ant') {
86 const interval = setInterval(() => {
87 void cleanupNpmCacheForAnthropicPackages()
88 void cleanupOldVersionsThrottled()

Callers 1

REPLFunction · 0.85

Calls 8

initMagicDocsFunction · 0.85
initSkillImprovementFunction · 0.85
featureFunction · 0.85
initAutoDreamFunction · 0.85
getIsInteractiveFunction · 0.85

Tested by

no test coverage detected