Skip to content

Remove root directory mtime caching in Claude cost scanner#462

Open
Priyans-hu wants to merge 1 commit intosteipete:mainfrom
Priyans-hu:fix/411-claude-cost-mtime-cache
Open

Remove root directory mtime caching in Claude cost scanner#462
Priyans-hu wants to merge 1 commit intosteipete:mainfrom
Priyans-hu:fix/411-claude-cost-mtime-cache

Conversation

@Priyans-hu
Copy link

@Priyans-hu Priyans-hu commented Mar 2, 2026

Hey! Noticed this one while looking through open issues.

The root mtime optimization in scanClaudeRoot was skipping the directory walk entirely when the root's mtime hadn't changed. Problem is, on macOS (and POSIX generally), a directory's mtime only updates when direct children change — not when files inside subdirectories get modified or created. Claude stores logs at ~/.claude/projects/<hash>/<session>.jsonl, so new session files in existing project folders never bump the root mtime.

The fix just removes the canSkipEnumeration fast path. The per-file mtime+size check in processClaudeFile already skips unchanged files, so the only added cost is the directory walk itself — no redundant parsing.

What changed

  • Removed root mtime caching and the canSkipEnumeration early return in scanClaudeRoot
  • Cleaned up the now-unused rootCache field from ClaudeScanState
  • Set cache.roots = nil so the stale key gets dropped from persisted caches

Fixes #411

The scanClaudeRoot function cached the root directory mtime and skipped
full directory enumeration when it was unchanged. On POSIX systems a
directory mtime only updates for direct child changes, not for files
created or modified inside subdirectories. This meant new session logs
in existing project folders were never discovered after the first scan,
leaving cost data frozen until the cache was manually deleted.

The per-file mtime/size cache in processClaudeFile already prevents
redundant parsing of unchanged files, so always enumerating only adds
the cost of the directory walk itself.

Fixes steipete#411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude cost data stops updating after first scan due to directory mtime caching in scanClaudeRoot

1 participant