claude-code-usage-bar icon indicating copy to clipboard operation
claude-code-usage-bar copied to clipboard

Fast mode rewrites ~14 cache files every second: ~100 GB/day of disk writes (SSD wear)

Open Amadeco opened this issue 2 months ago • 0 comments

Summary

In fast (daemon) mode, the render workers replace about 14 small files in ~/.cache/claude-statusbar every second, whether or not anything changed. On our server this was the largest steady disk writer: about 69 MB per minute, roughly 100 GB per day, with the Claude Code sessions idle.

We found it while investigating two NVMe disks (software RAID1) that reached 100% "Percentage Used" in SMART. They had written about 300 GB per day for two years.

Environment

  • claude-statusbar 3.43.2 (standalone build, fast mode), the current release
  • Debian 12, kernel 6.1, ext4 on an mdadm RAID1 of two NVMe disks
  • 3 Claude Code sessions open at the same time

Measurement

Process writes, 60 seconds, from /proc/<pid>/io (write_bytes):

Process Written in 60 s
cs-python -m claude_statusbar.render_worker (1) 35.4 MB
cs-python -m claude_statusbar.render_worker (2) 33.5 MB
cs-python -m claude_statusbar.cli daemon 1.1 MB
claude (both sessions, idle) 0.8 MB

Files replaced in the same 60 seconds. The files were polled once per second; a changed inode means the file was replaced by a new one (temp file + rename):

File in ~/.cache/claude-statusbar/ Replaced Size
sessions/<id>/rendered.ansi (per session) 59–60× < 1 KB
sessions/<id>/rendered.meta.json (per session) 60× < 1 KB
sessions/<id>/last_stdin.json (per session) 58× < 1 KB
rate_projection.<id>.json 37× 0.57 MB
last_stdin.json 40× < 1 KB
scheduler.json 15× < 1 KB
rate_latest.<id>.json 10× 10 KB
sessions/<id>/party_scan.json 4× < 1 KB

The file contents add up to about 22 MB per minute; the rest of the 69 MB is metadata and journal traffic. Each replacement creates a new inode, which costs a data write, a directory update and a journal commit. On RAID1 every one of those is written twice.

Workaround

A tmpfs mount over the cache directory brings these writes to zero, since it is a cache:

tmpfs /home/<user>/.cache/claude-statusbar tmpfs rw,nosuid,nodev,noexec,size=256M,uid=<uid>,gid=<gid>,mode=0755 0 0

Suggestions

  1. Skip unchanged writes. Compare the new content with the last written bytes (or a hash kept in memory) and do not write when they match. When the sessions are idle, rendered.ansi and rendered.meta.json rarely change from one tick to the next.
  2. Keep per-tick state in the daemon's memory. Write it to disk only when it changes or every few minutes, and not once a second.
  3. rate_projection: 0.57 MB rewritten 37 times a minute is 21 MB a minute for this file alone. Appending new samples, or rewriting only when a new sample arrives, would remove most of it.
  4. Put the hot files under $XDG_RUNTIME_DIR (a tmpfs on systemd systems) when it exists, or honour XDG_CACHE_HOME, or document a tmpfs mount for heavy users.

Related: #50 and #53 addressed the per-second CPU cost; this report is about the disk-write side of the same 1 Hz loop.

Amadeco avatar Sep 23 '26 06:09 Amadeco