Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

linux-battery-drain

БесплатноЗапускает вложенные скриптыНе проверен

Measure and diagnose laptop battery drain on Linux while off, suspended or idle, with gauge-aware tests. Use when a laptop's battery empties while off or in…

laurigatesот laurigates★ 61 звезда на GitHub

Об этом скилле

Linux Battery Drain

"The battery is always empty" covers three different states with different causes and fixes:

State Healthy draw (order of magnitude) Typical causes of excess
Off (S5) tens of mW EC staying powered, USB/PD power in off state, chipset deep-off mode disabled
Suspend (S3 / s2idle) ~100–500 mW, model-dependent s2idle without S0ix residency, devices not entering D3, wake sources
Running idle, screen off ~0.5–3 W a device kept awake by a failing driver, a stuck daemon, no package C-states

Work out which state the complaint is about before measuring. The journal usually tells you (Step 1).

When to Use This Skill

Use this skill when... Use something else when...
A laptop is empty after days or weeks unused Disk is full: linux-plugin:linux-disk-usage
Suspend lasts far shorter than expected The cause turns out to be EC firmware: bios-plugin's ec-firmware-analysis skill
Idle draw is high and fans run with nothing open Thermal or performance tuning beyond drain

Step 1: Find out what "off" really was

journalctl --list-boots
journalctl -b -1 --no-pager -n 20         # how the previous boot ended
journalctl --no-pager -q | grep -E 'PM: suspend (entry|exit)|System is powering down|Power key'
  • A boot that ends with systemd-shutdown lines was a real poweroff.
  • A boot that ends mid-log with no shutdown sequence ended with an empty battery or a forced power-off.
  • Long boots full of PM: suspend entry/exit pairs mean the machine was suspended, not off. Lid close usually defaults to suspend; check gsettings get org.gnome.settings-daemon.plugins.power lid-close-battery-action and logind.conf.

If it was really suspend, the fix may be a setting (hibernate, or suspend-then-hibernate) rather than a firmware problem.

Step 2: Check running drain first

High idle draw also empties a battery left on, and it confounds every other test:

cat /sys/class/power_supply/BAT*/power_now          # µW, on battery
ps -eo pcpu,etime,time,comm --sort=-pcpu | head
cat /sys/bus/pci/devices/*/power_state 2>/dev/null | sort | uniq -c

Two causes observed in practice:

  • A discrete GPU whose driver fails to load in a loop. For example, the NVIDIA open kernel module on a Pascal GPU: udev retries modprobe continuously, systemd-udevd workers burn CPU, and the GPU stays in D0. journalctl -k | grep -c "probe with driver" and the GPU's power_state show it. With a driver that runtime-suspends it (nouveau, or the supported proprietary branch), the GPU drops to D3cold.
  • A daemon spinning a core: check total CPU time, not just the current percentage.

Step 3: Measure, with the gauge's limits in mind

The only instrument most laptops offer is the battery's fuel gauge (energy_now, µWh). Four things make it lie:

  1. It recalibrates near full. At the end of a charge, gauges update their full-charge capacity (energy_full) and rescale energy_now. A test started right after unplugging from 100% can show energy rising on battery. Start at 40–80%. Both scripts log energy_full with every reading so a recalibration is visible.
  2. Readings move with voltage. The reading taken under load before a test and the one taken at boot after it differ by more than the drain in a short test. Use long periods: at least 2 h to tell 150 mW from 40 mW, overnight for a number within ~15%.
  3. Shutdown and boot cost energy. Roughly 0.1 Wh per cycle on a typical laptop (estimate). Measure it directly: run off-test.sh and power on as soon as the machine is off. That pair is the overhead to subtract.
  4. History files are keyed by the battery model string. upower writes /var/lib/upower/history-{charge,rate}-<model>-<…>.dat. The model string can change after a BIOS/EC update, and then the history continues in a new file. upower's percentage history is integer-rounded.

The charger must stay unplugged for the whole test. The scripts refuse to start with it connected and log the adapter state in every row.

Off (S5)

bash "${CLAUDE_SKILL_DIR}/scripts/off-test.sh" 7200          # or --no-rtc

It records energy, installs a one-shot unit that records it at the next boot, and powers off with an RTC alarm. Whether RTC wake from S5 works is firmware-specific: on some laptops it wakes from suspend but not from poweroff. Test it once with a short off period. If it doesn't wake, power on by hand; the unit logs at whatever boot comes next.

For a firmware-versus-OS split, repeat the same off period after a shutdown from the BIOS setup screen (systemctl reboot --firmware-setup, then power off from there). If that drains as much, the Linux shutdown path is not the cause.

Suspend

bash "${CLAUDE_SKILL_DIR}/scripts/s3-test.sh" 7200

Runs unattended: records, suspends with an RTC alarm, records again

Полный SKILL.md на GitHub

Установить linux-battery-drain в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Bash(bash ${CLAUDE_SKILL_DIR}/scripts/off-test.sh *)
Bash(bash ${CLAUDE_SKILL_DIR}/scripts/s3-test.sh *)
Bash(python3 -I ${CLAUDE_SKILL_DIR}/scripts/drain-calc.py *)
Bash(journalctl --list-boots *)
Bash(journalctl -b *)
Bash(upower -d)
Bash(cat /sys/class/power_supply/*)
Bash(cat /sys/power/mem_sleep)
Bash(cat /proc/acpi/wakeup)
Bash(ps *)
Read
Grep
Glob
AskUserQuestion

Вложенные файлы

scripts/drain-calc.pyscripts/off-test.shscripts/s3-test.sh

FAQ

Что делает скилл linux-battery-drain?

Measure and diagnose laptop battery drain on Linux while off, suspended or idle, with gauge-aware tests. Use when a laptop's battery empties while off or in suspend, or runs down fast at idle.

Как установить скилл linux-battery-drain?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл linux-battery-drain запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить linux-battery-drain с