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

Function cleanupOldFileHistoryBackups

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

Source from the content-addressed store, hash-verified

303}
304
305export async function cleanupOldFileHistoryBackups(): Promise<CleanupResult> {
306 const cutoffDate = getCutoffDate()
307 const result: CleanupResult = { messages: 0, errors: 0 }
308 const fsImpl = getFsImplementation()
309
310 try {
311 const configDir = getClaudeConfigHomeDir()
312 const fileHistoryStorageDir = join(configDir, 'file-history')
313
314 let dirents
315 try {
316 dirents = await fsImpl.readdir(fileHistoryStorageDir)
317 } catch {
318 return result
319 }
320
321 const fileHistorySessionsDirs = dirents
322 .filter(dirent => dirent.isDirectory())
323 .map(dirent => join(fileHistoryStorageDir, dirent.name))
324
325 await Promise.all(
326 fileHistorySessionsDirs.map(async fileHistorySessionDir => {
327 try {
328 const stats = await fsImpl.stat(fileHistorySessionDir)
329 if (stats.mtime < cutoffDate) {
330 await fsImpl.rm(fileHistorySessionDir, {
331 recursive: true,
332 force: true,
333 })
334 result.messages++
335 }
336 } catch {
337 result.errors++
338 }
339 }),
340 )
341
342 await tryRmdir(fileHistoryStorageDir, fsImpl)
343 } catch (error) {
344 logError(error as Error)
345 }
346
347 return result
348}
349
350export async function cleanupOldSessionEnvDirs(): Promise<CleanupResult> {
351 const cutoffDate = getCutoffDate()

Callers 1

Calls 4

getCutoffDateFunction · 0.85
getFsImplementationFunction · 0.85
tryRmdirFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected