What happens
On every agents-panel refresh, omarchy-agent-usage-codex re-parses every
~/.codex/sessions/**/*.jsonl file modified in the last 30 days, from scratch.
With a normal amount of Codex history this turns into a recurring, visible CPU
spike — omarchy-agent-u* sitting at 100% of a core for about a minute, every
15 minutes, indefinitely.
Measured on this machine (AMD Ryzen AI 9 HX PRO 370, 24 threads, Python 3.14.7):
|
files in 30-day window |
wall |
user CPU |
omarchy-agent-usage-codex --force |
1468 files / 7.8 GB |
56.9 s |
54.8 s |
omarchy-agent-usage-claude --force |
919 files / 440 MB |
~2 s |
~2 s |
99% CPU-bound, not I/O-bound.
What I expected
A periodic stats refresh that costs roughly nothing, because Codex session
files that belong to finished sessions never change again.
Why it is this expensive
Two things, one cheap to fix and one structural.
1. No pre-filter before json.loads. The Claude collector skips any line
that cannot be relevant before parsing it
(bin/omarchy-agent-usage-claude, in scan_project_transcripts):
# Cheap pre-filter before JSON parsing keeps files with unrelated
# lines inexpensive.
if '"usage":' not in line:
continue
The Codex collector has no equivalent — scan_native_codex_sessions in
bin/omarchy-agent-usage-codex calls json.loads(raw) on every line of every
file, then discards everything whose payload type is not token_count.
Those lines are a small minority of a session transcript.
Adding the matching guard:
for raw in handle:
if '"token_count"' not in raw and '"turn_context"' not in raw:
continue
try:
entry = json.loads(raw)
takes the same run from 54.8 s to 20.9 s of user CPU (56.9 s → 22.6 s wall),
with byte-identical output — I diffed todayPrompts, todaySessions,
todayTotalTokens, totalPrompts, totalSessions, activeDays,
modelUsage, recentDays and todayTokensByModel between patched and
unpatched runs and they match.
2. The cache is whole-result and time-bounded, so every refresh is a full
rescan. SCAN_REUSE_SECONDS = 20 exists only to dedup concurrent collector
runs, as its comment says:
# every periodic widget refresh lands a real rescan, however low
# refreshIntervalSec is set.
So even with the pre-filter it is still ~21 s of CPU every
refreshIntervalSec (default 900, shell/plugins/agents/Main.qml). Because a
closed session file is immutable, a per-file cache keyed on
(path, st_mtime, st_size) -> per-day/per-model totals would make steady-state
refreshes proportional to what actually changed — usually one live session —
instead of to the whole 30-day window. The existing
scan_cache_paths() / _cached_local_stats() machinery looks like the natural
place for it.
The pre-filter alone is a worthwhile standalone fix; the per-file cache is what
makes the cost stop scaling with accumulated history.
Steps to reproduce
- Accumulate Codex sessions until
~/.codex/sessions holds a few GB inside a
30-day window (du -sh ~/.codex/sessions).
time omarchy-agent-usage-codex --force >/dev/null
- Compare with
time omarchy-agent-usage-claude --force >/dev/null, which
scans a comparable file count with the pre-filter in place.
- Leave the agents panel enabled and watch
omarchy-agent-u* in top at each
refreshIntervalSec boundary.
System
omarchy version: 4.0.4-1
- Kernel: 7.2.5-3-omarchy
- Python: 3.14.7
- CPU: AMD Ryzen AI 9 HX PRO 370 (24 threads)
Workaround, for anyone who lands here first
Move older Codex transcripts out of the scanned roots — note that both
sessions and archived_sessions are scanned, so the destination has to be
neither:
mkdir -p ~/.codex/sessions-old
find ~/.codex/sessions -name '*.jsonl' -mtime +3 -exec mv -t ~/.codex/sessions-old {} +
Or make the spike rarer without making it smaller:
omarchy bar set omarchy.agents refreshIntervalSec 3600 --json
Disabling the Codex provider in shell.json does not help:
providerEnabled() only gates display, and omarchy-agent-usage-update still
forks every collector.
Filed by Claude Opus 5 via Claude Code.
What happens
On every agents-panel refresh,
omarchy-agent-usage-codexre-parses every~/.codex/sessions/**/*.jsonlfile modified in the last 30 days, from scratch.With a normal amount of Codex history this turns into a recurring, visible CPU
spike —
omarchy-agent-u*sitting at 100% of a core for about a minute, every15 minutes, indefinitely.
Measured on this machine (AMD Ryzen AI 9 HX PRO 370, 24 threads, Python 3.14.7):
omarchy-agent-usage-codex --forceomarchy-agent-usage-claude --force99% CPU-bound, not I/O-bound.
What I expected
A periodic stats refresh that costs roughly nothing, because Codex session
files that belong to finished sessions never change again.
Why it is this expensive
Two things, one cheap to fix and one structural.
1. No pre-filter before
json.loads. The Claude collector skips any linethat cannot be relevant before parsing it
(
bin/omarchy-agent-usage-claude, inscan_project_transcripts):The Codex collector has no equivalent —
scan_native_codex_sessionsinbin/omarchy-agent-usage-codexcallsjson.loads(raw)on every line of everyfile, then discards everything whose payload
typeis nottoken_count.Those lines are a small minority of a session transcript.
Adding the matching guard:
takes the same run from 54.8 s to 20.9 s of user CPU (56.9 s → 22.6 s wall),
with byte-identical output — I diffed
todayPrompts,todaySessions,todayTotalTokens,totalPrompts,totalSessions,activeDays,modelUsage,recentDaysandtodayTokensByModelbetween patched andunpatched runs and they match.
2. The cache is whole-result and time-bounded, so every refresh is a full
rescan.
SCAN_REUSE_SECONDS = 20exists only to dedup concurrent collectorruns, as its comment says:
So even with the pre-filter it is still ~21 s of CPU every
refreshIntervalSec(default 900,shell/plugins/agents/Main.qml). Because aclosed session file is immutable, a per-file cache keyed on
(path, st_mtime, st_size) -> per-day/per-model totalswould make steady-staterefreshes proportional to what actually changed — usually one live session —
instead of to the whole 30-day window. The existing
scan_cache_paths()/_cached_local_stats()machinery looks like the naturalplace for it.
The pre-filter alone is a worthwhile standalone fix; the per-file cache is what
makes the cost stop scaling with accumulated history.
Steps to reproduce
~/.codex/sessionsholds a few GB inside a30-day window (
du -sh ~/.codex/sessions).time omarchy-agent-usage-codex --force >/dev/nulltime omarchy-agent-usage-claude --force >/dev/null, whichscans a comparable file count with the pre-filter in place.
omarchy-agent-u*intopat eachrefreshIntervalSecboundary.System
omarchy version: 4.0.4-1Workaround, for anyone who lands here first
Move older Codex transcripts out of the scanned roots — note that both
sessionsandarchived_sessionsare scanned, so the destination has to beneither:
Or make the spike rarer without making it smaller:
omarchy bar set omarchy.agents refreshIntervalSec 3600 --jsonDisabling the Codex provider in
shell.jsondoes not help:providerEnabled()only gates display, andomarchy-agent-usage-updatestillforks every collector.
Filed by Claude Opus 5 via Claude Code.