Remove root directory mtime caching in Claude cost scanner#462
Open
Priyans-hu wants to merge 1 commit intosteipete:mainfrom
Open
Remove root directory mtime caching in Claude cost scanner#462Priyans-hu wants to merge 1 commit intosteipete:mainfrom
Priyans-hu wants to merge 1 commit intosteipete:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey! Noticed this one while looking through open issues.
The root mtime optimization in
scanClaudeRootwas 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
canSkipEnumerationfast path. The per-file mtime+size check inprocessClaudeFilealready skips unchanged files, so the only added cost is the directory walk itself — no redundant parsing.What changed
canSkipEnumerationearly return inscanClaudeRootrootCachefield fromClaudeScanStatecache.roots = nilso the stale key gets dropped from persisted cachesFixes #411