Battery charge policy for Linux laptops. ChargeKeeper has a CLI, a root helper that validates every write, and an optional Omarchy bar widget.
The tool reports the charge controls the firmware and kernel expose. Machines
differ: some offer Fast, Standard, and Long_Life; others take a numeric
start and end percentage; others only expose charge_behaviour.
Linux only. There is no Windows or macOS support. Version 0.1 targets the
standard power_supply sysfs attributes and UPower.
ChargeKeeper works at two levels:
- L1, firmware modes:
charge_typeswithFast,Standard, andLong_Life. The limit is fixed by firmware, commonly 75-80% on Lenovo non-ThinkPads. - L2, numeric controls:
charge_control_start_threshold,charge_control_end_threshold, andcharge_behaviour.
A device may expose one level, both, or neither. chargekeeper probe reports
which; docs/capabilities.md explains the classes and per-vendor notes.
probe: enumerate batteries and their capabilities (human or JSON).status: charge level, power state, AC, active mode/limit/behaviour, backend.mode: setFast,Standard, orLong_Life.StandardandLong_Lifeuse UPower when it reports threshold support;Fastand any UPower fallback go through the root helper.limit: set an end threshold, optionally a start threshold, through the helper.behaviour: setauto,inhibit-charge, orforce-dischargethrough the helper.on/off: toggle UPower charge-threshold limiting, unprivileged.auto --once: apply the AC/battery/night policy once; the included systemd user timer runs it every minute.
Every write is validated against the live supported values, read back, and reported as a failure on mismatch. Only the helper writes sysfs directly; UPower handles the unprivileged threshold path.
Requirements: Linux, bash 5, jq, UPower (for on/off, the
Standard/Long_Life preference, and device state), and a kernel driver that
exposes the battery attributes. The Omarchy plugin also needs Omarchy's
Quickshell shell; the CLI runs without Omarchy.
The repository root is the plugin folder: manifest.json, Panel.qml,
Service.qml, Model.js, Policy.js, and i18n/. Omarchy can add the widget
straight from this repository:
omarchy plugin add https://github.com/ethandong16/chargekeeper --enable
omarchy restart shellThe plugin ID is io.github.ethandong16.chargekeeper. Standard and
Long_Life switch through UPower without a password. Fast, the numeric
limit commands, and charge_behaviour need the root helper, which the CLI also
uses; install it once from a checkout:
./install.sh --with-helperIf you installed the widget with omarchy plugin add, the checkout is
~/.config/omarchy/plugins/io.github.ethandong16.chargekeeper;
./install.sh detects that the plugin is already in place instead of copying
over it. To install only the helper from any checkout:
sudo install -d -m 0755 /usr/lib/chargekeeper
sudo install -m 0755 -o root -g root lib/chargekeeper-helper \
/usr/lib/chargekeeper/chargekeeper-helper
printf '%s\n' '%wheel ALL=(root) NOPASSWD: /usr/lib/chargekeeper/chargekeeper-helper' \
| sudo tee /etc/sudoers.d/chargekeeper >/dev/null
sudo chmod 0440 /etc/sudoers.d/chargekeeper
sudo visudo -cf /etc/sudoers.d/chargekeeperRemove the widget with:
omarchy plugin remove io.github.ethandong16.chargekeeperThen remove the helper and sudoers rule if you installed them:
sudo rm -f /etc/sudoers.d/chargekeeper /usr/lib/chargekeeper/chargekeeper-helperSee docs/omarchy.md for controls, IPC, settings, and the automation service
record.
cd packaging
makepkg -sichargekeeper-git installs the CLI to /usr/bin/chargekeeper, the helper to
/usr/lib/chargekeeper/chargekeeper-helper, the plugin source to
/usr/share/chargekeeper/omarchy, docs to /usr/share/doc/chargekeeper, and
the user units to /usr/lib/systemd/user. It does not install a sudoers rule;
the post-install message shows the one-line rule and how to validate it with
visudo -cf.
From the repository root:
./install.sh # CLI, plugin, user units, example config; no root
./install.sh --with-helper # also installs the root helper and sudoers rule
./install.sh --uninstall # removes the user-local filesinstall.sh never downloads anything and fails if source files are missing.
It installs the CLI to ~/.local/bin/chargekeeper, the plugin to
~/.config/omarchy/plugins/io.github.ethandong16.chargekeeper, units to
~/.config/systemd/user, and ~/.config/chargekeeper/config.json if absent.
Missing directories are created with mode 0755; directories that already exist
keep their current permissions.
--with-helper installs /usr/lib/chargekeeper/chargekeeper-helper (0755
root:root) and /etc/sudoers.d/chargekeeper, then runs visudo -cf. If
validation fails it removes both files and aborts.
systemctl --user daemon-reload
systemctl --user enable --now chargekeeper-auto.timerThe timer invokes chargekeeper auto --once every minute.
install.sh places the plugin in the user plugin directory:
omarchy plugin enable io.github.ethandong16.chargekeeper --section right
omarchy restart shellFor a package install, copy the shipped source first:
mkdir -p ~/.config/omarchy/plugins
cp -a /usr/share/chargekeeper/omarchy \
~/.config/omarchy/plugins/io.github.ethandong16.chargekeeper
omarchy plugin enable io.github.ethandong16.chargekeeper --section right
omarchy restart shellAutomation through the widget also needs the plugin's service record; see
docs/omarchy.md. The widget service and the systemd timer read the same
config and override file. Running both is harmless but redundant; choose one
automation owner.
chargekeeper probe
chargekeeper probe --json | jq '.batteries[0].capabilities'
chargekeeper status
chargekeeper mode Long_Life
chargekeeper mode Standard --battery BAT1
chargekeeper limit 80
chargekeeper limit 80 --start 75
chargekeeper behaviour inhibit-charge
chargekeeper on # enable UPower charge threshold limiting
chargekeeper off # allow full charge
chargekeeper auto --onceExit codes: 0 success, 1 write or readback failure, 2 usage error,
3 no supported backend.
~/.config/chargekeeper/config.json:
{
"enabled": true,
"acMode": "Long_Life",
"batteryMode": "Standard",
"acLimit": 80,
"batteryLimit": 100,
"acDelayMinutes": 10,
"nightStart": "",
"nightEnd": "",
"manualMinutes": 120
}- When firmware modes exist, the policy uses
acMode/batteryMode. - When only an end threshold exists, it uses
acLimit/batteryLimit. acDelayMinuteswaits after AC is attached;0applies immediately.nightStart/nightEnduseHH:MMand may cross midnight. Inside the window the policy forcesLong_Life, oracLimiton numeric-only hardware.manualMinutessuppresses automation after a manual change. The marker lives in~/.local/state/chargekeeper/manual-until.enabled: falsedisables automation.
The policy only ever applies Standard / Long_Life or a numeric limit.
Fast and charge_behaviour stay deliberate commands.
-
probeandstatusrun as the user. -
on,off, andmode Standard|Long_Lifewhen UPower reports threshold support run as the user. UPower performs the write; its polkit action isallow_active=yes, so an active local session is not prompted. -
mode Fast,limit,behaviour, and themodefallback when UPower cannot write invoke/usr/lib/chargekeeper/chargekeeper-helperthroughsudo -n. The packaged rule is:%wheel ALL=(root) NOPASSWD: /usr/lib/chargekeeper/chargekeeper-helperThe rule passes arguments straight to the helper, so the helper enforces the boundary. It accepts only
mode BAT MODE,limit BAT END [START], andbehaviour BAT VALUE, validates the battery against/sys/class/power_supply, checks the value against the live supported list, writes the one matching attribute, and verifies the readback. -
It does not use a setuid binary or daemon, and there is no arbitrary sysfs write path.
-
The package never installs a sudoers rule automatically.
| Class | Surface | What ChargeKeeper can set |
|---|---|---|
| A | charge_types |
Fast, Standard, Long_Life |
| B | charge_control_end_threshold |
numeric end threshold |
| C | start + end threshold | numeric start and end thresholds |
| D | charge_behaviour |
auto, inhibit-charge, force-discharge |
| E | fixed firmware limit | usually nothing numeric; modes only |
Support below comes from the kernel drivers and the TLP vendor matrix. Only the ThinkBook in the verified table has been tested for this release.
| Vendor / family | Typical surface | ChargeKeeper support | Verified here |
|---|---|---|---|
| Lenovo ThinkPad | start + end threshold; charge_behaviour on many |
C, D | No |
| Lenovo ThinkBook / IdeaPad | charge_types modes, fixed 75-80% |
A (no numeric limit) | Yes |
| ASUS | end threshold 1-100; some models accept only 40/60/80 | B | No |
| Dell | start 50-95 and end 55-100; driver switches to Dell Custom mode |
C | No |
| HP | no standard threshold in mainline for most models; BIOS-only charge control | unsupported unless probe shows an attribute |
No |
| Huawei | TLP uses a vendor platform attribute; standard BAT attributes are not guaranteed | only if standard attributes appear | No |
| MSI | end 10-100; firmware enforces start = stop - 10; only specific models/BIOS | B | No |
| Framework / Chromebook | cros_charge-control: start+end and charge_behaviour on EC v2/v3 |
C, D | No |
| LG Gram | end threshold, 80 or 100 | B (fixed values) | No |
| Samsung | vendor battery_life_extender at 80%, not a standard BAT attribute |
not supported in 0.1 | No |
For an unlisted device, chargekeeper probe --json is the authoritative
answer. It reports what that machine exposes, which may differ from the table.
- Lenovo non-ThinkPads: the 75-80% limit is firmware-fixed. There is no numeric threshold to configure.
- UPower flags can lie.
ChargeThresholdSupported=truetogether withChargeThresholdSettingsSupported=4means firmware-controlled limiting only (no start/end percentage). UPower may also report generic values that do not match the firmware's real limit. ChargeKeeper treats readable sysfs values as the source of truth and verifies every write. - Readback is mandatory. If the firmware accepts a write and ignores it, the command fails instead of reporting success.
- No recalibration, force-discharge-by-time, or
chargeonce. Those TLP features are outside 0.1 scope. - Persistence varies. Some firmware resets thresholds on boot or resume; the timer re-applies the policy, but only while the user session runs.
- No Windows or macOS support.
- No battery-health or temperature control.
| Model | Kernel | UPower | Surface | Result |
|---|---|---|---|---|
| Lenovo ThinkBook 16 G7+ IAH | 7.2.15-1-omarchy | 1.91.5 | charge_types = Fast [Standard] Long_Life; no start/end threshold; ChargeThresholdSettingsSupported = 4 |
probe, status, and Standard/Long_Life switching via UPower; Fast requires the helper |
- No capabilities reported: check
ls /sys/class/power_supply/BAT*/and the kernel driver.chargekeeper probe --jsonshows exactly which attributes and values were found. - Fast mode unavailable: the helper or the sudoers rule is missing. Check with
sudo -n -l /usr/lib/chargekeeper/chargekeeper-helper mode BAT1 Fast. Re-run./install.sh --with-helperand fixvisudo -cferrors. on/offexit 3: UPower is not running or the device does not expose threshold support. Trysystemctl status upower.- Limit write fails: the requested value may be outside the driver's range or step (for example ASUS models that accept only 40/60/80). The error names the value that did not stick.
autodoes nothing: confirmenabledis true, a supported capability exists, and no manual override is active. Inspect withjournalctl --user -u chargekeeper-auto.- Omarchy widget missing: run
omarchy plugin validateon the installed folder, thenomarchy plugin enable io.github.ethandong16.chargekeeper --section right, andomarchy restart shell. Quickshell caches IPC handlers for its lifetime. - Password prompt on every mode change: the
NOPASSWDrule for%wheelis absent or not validated. Check/etc/sudoers.d/chargekeeperwithsudo visudo -cf.
Bug reports need the output of:
chargekeeper probe --jsonRemove serial numbers or other machine identifiers before posting. Hardware
support claims must name the model, kernel version, driver, and the exact
attributes found; do not add a vendor to the matrix from a spec sheet alone.
Shell changes must pass bash -n, shellcheck, and tests/run.sh.
- UPower
org.freedesktop.UPower.Device: https://upower.freedesktop.org/docs/Device.html - TLP battery-care vendor specifics: https://linrunner.de/tlp/settings/bc-vendors.html
- Omarchy shell plugins manual: https://omarchy.org/manual/shell-plugins/
MIT. See LICENSE.