MCPcopy Create free account
hub / github.com/codeaashu/claude-code / cleanupOldVersionsThrottled

Function cleanupOldVersionsThrottled

src/utils/cleanup.ts:543–573  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

541 * The regular cleanupOldVersions() should still be used for installer flows.
542 */
543export async function cleanupOldVersionsThrottled(): Promise<void> {
544 const markerPath = join(getClaudeConfigHomeDir(), '.version-cleanup')
545
546 try {
547 const stat = await fs.stat(markerPath)
548 if (Date.now() - stat.mtimeMs < ONE_DAY_MS) {
549 logForDebugging('version cleanup: skipping, ran recently')
550 return
551 }
552 } catch {
553 // File doesn't exist, proceed with cleanup
554 }
555
556 try {
557 await lockfile.lock(markerPath, { retries: 0, realpath: false })
558 } catch {
559 logForDebugging('version cleanup: skipping, lock held')
560 return
561 }
562
563 logForDebugging('version cleanup: starting (throttled)')
564
565 try {
566 await cleanupOldVersions()
567 await fs.writeFile(markerPath, new Date().toISOString())
568 } catch (error) {
569 logError(error as Error)
570 } finally {
571 await lockfile.unlock(markerPath, { realpath: false }).catch(() => {})
572 }
573}
574
575export async function cleanupOldMessageFilesInBackground(): Promise<void> {
576 // If settings have validation errors but the user explicitly set cleanupPeriodDays,

Callers 1

Calls 3

logForDebuggingFunction · 0.85
cleanupOldVersionsFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected