| Crates.io | tmux-cpu-rs |
| lib.rs | tmux-cpu-rs |
| version | 0.5.0 |
| created_at | 2025-09-26 15:05:05.153771+00 |
| updated_at | 2025-10-10 00:00:46.127416+00 |
| description | A Tmux status line plugin to show CPU usage |
| homepage | |
| repository | https://github.com/playbahn/tmux-cpu-rs |
| max_upload_size | |
| id | 1856033 |
| size | 525,660 |
A small, fast Rust-based CLI tool to display CPU usage inside your tmux status line —
with caching for efficiency, and optional gradients & formatting.


Linux only - This tool reads CPU statistics from /proc/stat and only works on Linux systems.
Tested and supported architectures:
Untested architectures:
Note: tmux-cpu-rs should still work on untested architectures,
since there's no architecture specific code.
/proc/stattmux-like format stringsf64-based statsUsing cargo:
cargo install tmux-cpu-rs
Or clone and build manually:
git clone https://github.com/playbahn/tmux-cpu-rs
cd tmux-cpu-rs
cargo build --release
Or you can grab pre-built binary(s) from the Releases page.
Usage: tmux-cpu-rs [OPTIONS] <PID>
Arguments:
<PID> Pass in #{client_pid}
Options:
-H, --no-hook Disable setting of cache removal hooks (`client-detached` and `session-closed`)
-p, --precision <NUM> f64 precision to use for displayed stats [default: 0]
-w, --width <NUM> Minimum width (right-aligned with spaces) for usage string [default: 0]
-b, --before <FORMAT> Tmux-like format strings to place before usage string (see below)
-a, --after <FORMAT> Tmux-like format strings to place after usage string (see below)
-r, --raw Get CPU usage and gradient in a "raw" reusable format (see below)
-c, --cachedir <DIR> Directory to cache stats in [default: /tmp/tmcpu/]
-h, --help Print help
-V, --version Print version
...
--before and --after take tmux-like format strings where:
Embedded style strings are marked with @[] instead of #[], and
Every match for the exact pattern HEXGRAD inside @[] is replaced by a color from Hue 120
degrees (green) to Hue 0 degrees (red), going from low to high usage.
Multiple --before (and --after) options can also be specified, in which case the format strings
are concatenated in order of occurrence.
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} -p1 -b '@[fg=HEXGRAD]') "
With a low CPU usage, the above will render as:

When using --raw, the output format becomes:
USAGE\nHEXGRAD
where:
USAGE is the numeric CPU usage\n is the Unicode U+000A newline characterHEXGRAD is the computed color (hex string)This is useful if you want to build your own custom tmux formatting or use the values in other
scripts.
Adding a percent sign after usage:
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} --precision 1 --after %) "

With gradients turned on:
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} -p1 --before '@[fg=HEXGRAD]' -a%) "

tmux-cpu-rs emits plain tmux format strings. So, styles are persistent:
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} -b '@[fg=HEXGRAD]' -a%)"
set -ga status-right " #[reverse] #H #[noreverse]"

This will have to be resolved by resetting the style with either the --after option:
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} \
-b '@[fg=HEXGRAD]' -a '%@[fg=default]') \
#[reverse] #H #[noreverse]"
or with an embedded style string before the next text:
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} \
-b '@[fg=HEXGRAD]' -a% \
) #[fg=default,reverse] #H #[noreverse]"

--raw:
path/to/tmux-cpu-rs $(tmux display -p '#{client_pid}') --raw

With Nerd Font (Powerline) half circles:
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} \
-p1 \
-b '@[fg=HEXGRAD]\uE0B6' \
-b '@[reverse,bold]\uF4BC ' \
-a '@[noreverse]\uE0B4' \
) #[fg=default]\uE0B6#[reverse,bold]#H#[noreverse]\uE0B4"

With Nerd Font (Powerline) right dividers:
set -g status-right "#(path/to/tmux-cpu-rs #{client_pid} \
-p2 -w4 \
-b '@[fg=HEXGRAD]\uE0B2' \
-b '@[reverse,bold] \uF4BC ' \
-a ' @[noreverse,bg=#14b5ff]\uE0D6'\
)#[fg=default,bg=default,reverse,bold] #H "

Unicode escape sequences in the form given above are only rendered as glyphs if they're parsed by
tmux. In other words, this works at the tmux command prompt or .tmux.conf:
display "A\uE0B2B"
But at the (bash) shell command prompt or a (bash) shell script, it will need to be written as:
tmux display "A"$'\uE0B2'"B"
Firstly, tmux-cpu-rs runs only when it's invoked with #(). It is as "frequent" as the
status-interval your client is using. Users with lower status-intervals (say 1 second) will see
more sensible stats than users with a higher status-interval (say 5 second).
The first time it is invoked it finds no past or "old" stats, so it only caches the current stats
in a temp file with the name XYZ for a passed client_pid of XYZ) in the cachedir1, and sets
(appends) two hooks2 at client-detached and session-closed for the removal of that cache file.
For every subsequent run it updates the cache, and prints new usage stats to stdout.
Additionally, you could also redirect the stderr of tmux-cpu-rs inside the same #() with
2> /tmp/tmcpu.log if something's not working.
While looking for a CPU usage monitor for my tmux statusline, I looked through some options, but
was kind of annoyed by the fact that all (couldn't have been more than one or two) of them sleep
every time tmux evaluates #()'s. Taking a noticeable time to end execution, throwing away
current values, I wasn't happy. So, I wrote one in Rust that cached current stats in /tmp for the
next delta calculation for CPU usage. I looked once more, and found
tmux-plugins/tmux-cpu. Although tmux-cpu-rs is not a
rewrite of the CPU portion of tmux-plugins/tmux-cpu (they also have a GPU portion), they're quite
similar, as they both use caching. Then, I thought "let's make it use-able by people" and here we
are. I would say the (deemed) selling point of tmux-cpu-rs would be caching.
This project is licensed under either of
at your option.