Skip to content

CLI: skip log files untouched since before the period - #3

Merged
Longado merged 1 commit into
mainfrom
perf/skip-untouched-logs
Dec 3, 2026
Merged

Longado merged 1 commit into
mainfrom
perf/skip-untouched-logs

Conversation

@Longado

@Longado Longado commented Dec 3, 2026

Copy link
Copy Markdown
Owner

What changes

tokenly <days> read every Claude Code and Codex log file and only then dropped entries older than the period. A file last written before the period cannot hold an entry from it, so scan_claude and scan_codex now skip those files by modification time.

On a Mac with about 7,400 log files, tokenly 1 --by provider --json went from 75 s to 8 s. The Anthropic totals of the two runs were identical; the OpenAI totals differed by the usage that live Codex sessions added during the slower run.

Why now

Node Monitor's probe can run this command every five minutes to report a machine's last 24 hours of AI usage. At 75 s a run that was too heavy to repeat.

Limits

  • A log copied in from elsewhere with an old modification time kept (for example rsync -t) is skipped for short periods even if it holds recent entries.
  • --quota is unchanged and still reads every Codex log.

Checks

  • New test: a file with a three-day-old modification time is left out of a one-day report and counted in a 30-day one
  • Existing tests pass
  • The macOS app is untouched; it has its own scanner

A one-day report read every Claude Code and Codex log on the machine and then
dropped the old entries. A file last written before the period cannot hold an
entry from it, so those files are no longer opened. On a Mac with about 7,400
log files, `tokenly 1 --by provider --json` went from 75 s to 8 s with the same
totals.
@Longado
Longado merged commit 8448323 into main Dec 3, 2026
4 checks passed
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.

1 participant