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

Function cleanupSingleDirectory

src/utils/cleanup.ts:266–298  ·  view source on GitHub ↗

* Generic helper for cleaning up old files in a single directory * @param dirPath Path to the directory to clean * @param extension File extension to filter (e.g., '.md', '.jsonl') * @param removeEmptyDir Whether to remove the directory if empty after cleanup

(
  dirPath: string,
  extension: string,
  removeEmptyDir: boolean = true,
)

Source from the content-addressed store, hash-verified

264 * @param removeEmptyDir Whether to remove the directory if empty after cleanup
265 */
266async function cleanupSingleDirectory(
267 dirPath: string,
268 extension: string,
269 removeEmptyDir: boolean = true,
270): Promise<CleanupResult> {
271 const cutoffDate = getCutoffDate()
272 const result: CleanupResult = { messages: 0, errors: 0 }
273 const fsImpl = getFsImplementation()
274
275 let dirents
276 try {
277 dirents = await fsImpl.readdir(dirPath)
278 } catch {
279 return result
280 }
281
282 for (const dirent of dirents) {
283 if (!dirent.isFile() || !dirent.name.endsWith(extension)) continue
284 try {
285 if (await unlinkIfOld(join(dirPath, dirent.name), cutoffDate, fsImpl)) {
286 result.messages++
287 }
288 } catch {
289 result.errors++
290 }
291 }
292
293 if (removeEmptyDir) {
294 await tryRmdir(dirPath, fsImpl)
295 }
296
297 return result
298}
299
300export function cleanupOldPlanFiles(): Promise<CleanupResult> {
301 const plansDir = join(getClaudeConfigHomeDir(), 'plans')

Callers 1

cleanupOldPlanFilesFunction · 0.85

Calls 4

getCutoffDateFunction · 0.85
getFsImplementationFunction · 0.85
unlinkIfOldFunction · 0.85
tryRmdirFunction · 0.85

Tested by

no test coverage detected