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★ 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:
Run the app under a pty, not your own foreground pane.
script -q /dev/null <cmd>(orexpect/tmux new-sessionfor 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.Sample accumulated CPU time with
ps -o time= -p <pid>, not instantaneoustop. 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 atopsnapshot 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.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/selectat the top of the stack; anything else (render/parse/format calls,fork/os.StartProcessframes) is real work happening while nothing should be.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 singlepssnapshot 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.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
WithFPSoption) moved idle CPU on th
Установить 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), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic