Command Palette

Search for a command to run...

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

idle-cost-audit

БесплатноБез исполняемых скриптовНе проверен

Audit a TUI/CLI app for battery/CPU cost while idle. Use when asked why an app is burning battery or CPU while sitting untouched, or when reviewing code that…

elentokот elentok★ 25 звёзд на GitHub

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

Idle Cost Audit

Find and fix the periodic work that keeps an otherwise-idle process off of deep sleep. Written from a real audit (gx's idle-cost epic) that found seven such sources in one TUI and fixed six of them; before/after numbers below are from that audit.

Invariants

Rules that, if followed while writing the code, would have prevented every finding below:

  • No unconditional periodic work. A timer/ticker that fires regardless of app state is a battery cost by construction. Every periodic callback needs a reason to still be running each time it fires.
  • A repeating tick must be gated on an active job and must stop when that job ends. Spinners, polls, and progress ticks should rearm only if running { return tickCmd }, never unconditionally. A dialog left open after its job finishes (failed/waiting-for-input) is the common miss — the job ended, but nothing told the tick to stop.
  • Cap the render frame rate rather than accepting a framework default. A 60 Hz renderer ticker is often the entire idle floor, independent of anything the app itself computes. Pick a rate the eye can't tell apart from 60 (15–20 Hz is invisible for anything without animation) and set it at every place a render loop is constructed — ideally through one shared constructor so a new call site can't forget it.
  • Never spawn a subprocess on a path that repeats on a timer. A subprocess is orders of magnitude more expensive than in-process work (tens of ms of fork/exec vs. sub-ms), and a call that's cheap once becomes the dominant cost once it's on a 1–2s loop. Resolve/cache the result once instead of re-deriving it on every tick.
  • A poll that exists as a correctness backstop should be slow, and should say so. If the real update path is event-driven (a filesystem watch, a push notification), the remaining poll is only there to catch what the event source might miss — it should run on the order of tens of seconds, and a comment or name should make clear it's a backstop, not the primary path, so nobody "fixes" it back down to 1–2s under the impression it's load-bearing.
  • Optimize wakeup rate, not just CPU%. A cheap-but-frequent timer (say, 1% CPU spent in 1ms bursts every 100ms) reads as negligible on a CPU% graph but is what actually keeps a CPU package out of deep-idle power states — the wakeup itself has a fixed energy cost independent of how much work it does once awake. When judging whether a periodic source matters, ask "how often does this wake the process" before "how much CPU% does this cost."

Method

The procedure that found all seven issues in the reference audit, in order:

  1. Run the app under a pty, not your own foreground pane. script -q /dev/null <cmd> (or expect/tmux new-session for something needing keystrokes), backgrounded, output redirected to a file. A full-screen TUI in your own terminal blocks you from running the next measurement command, and if you're an unattended agent it reads as a hung pane. Drive it to the tab/state you need with piped keystrokes, then leave it untouched — "idle" means untouched, not merely running.

  2. Sample accumulated CPU time with ps -o time= -p <pid>, not instantaneous top. Read the value at the start and end of a fixed window (30–90s), and report the delta over the window as a percentage. This is the load-bearing measurement: instantaneous CPU readouts hide a periodic cost that fires every couple of seconds — the process is at 0% between ticks and briefly spikes on each one, and a top snapshot has a good chance of landing in the gap and reporting nothing is happening. Accumulated time over a window can't miss a periodic cost no matter when you sample.

  3. Take stacks with sample <pid> (macOS; perf record/py-spy/equivalent elsewhere) while the process is idle, to see what's actually running during the wakeups the CPU delta implies. Idle sleep shows up as __psynch_cvwait/kevent/select at the top of the stack; anything else (render/parse/format calls, fork/os.StartProcess frames) is real work happening while nothing should be.

  4. Detect child-process spawns by polling ps -ax -o pid=,ppid=,args= and filtering on the target pid as parent, at a rate faster than the suspected interval (e.g. every 150ms against a suspected 2s poll), for the full measurement window, then dedup by pid. A subprocess that lives for tens of milliseconds is invisible to a single ps snapshot but will always be caught by one of several polls across its lifetime — and if it appears more than once, that's a repeating spawn.

  5. A/B a suspected cause with a variant binary, re-measured identically. Don't reason about whether a change will help — build it and compare. Worked example from the reference audit: dropping the render ticker from a 60Hz default to 15 fps (via the framework's WithFPS option) moved idle CPU on th

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

Установить idle-cost-audit в Claude Code и Claude Desktop

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

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

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

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

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

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл idle-cost-audit?

Audit a TUI/CLI app for battery/CPU cost while idle. Use when asked why an app is burning battery or CPU while sitting untouched, or when reviewing code that adds a periodic tick, poll, or subprocess call.

Как установить скилл idle-cost-audit?

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

Скилл idle-cost-audit запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

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

Сравнить idle-cost-audit с