esp-optimize

A command for improving ESP32 firmware, which is software that runs on Espressif microcontrollers, for speed, memory use, battery life, or file size.

In plain words
What is it for?
Use it to review or optimize ESP32 code for speed, memory, power consumption, or binary size, including tasks involving IRAM, DMA, cache use, task priorities, and sleep modes.
Why use it?
It encourages measuring the firmware first, then addressing actual bottlenecks such as memory bandwidth, flash-cache misses, or data-transfer conflicts.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/mathisk2095/jko-claude-plugins/esp-optimize
Clone the repo
git clone --depth 1 https://github.com/mathisk2095/jko-claude-plugins
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 834 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00014 $0.00834
Opus 5 $0.00007 $0.00417
Sonnet 5 $0.00003 $0.00167
Haiku 4.5 $0.00001 $0.00083

Measured 2d ago against content hash f1b697f7a571, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

esp-optimize scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/esp32-cpp/commands/esp-optimize.md · 71 lines

How it starts

The opening of the file, as written. The whole thing — 71 lines — stays where its author put it; the contents beside it link to each section on GitHub.

ESP32 Firmware Optimization

First: Use the esp32-expert skill. → Consult memory reference for heap/PSRAM/IRAM placement, LVGL reference for display performance, and power reference for sleep mode design.

Optimization without measurement is guesswork. Profile first, then target the bottleneck. On ESP32, the bottleneck is almost always memory bandwidth (PSRAM), flash cache misses, or DMA contention -- not CPU speed.

Parse Target from $ARGUMENTS

$1 should be one of: speed, memory, power, size. Default to a general review if not specified.

Speed Optimization

  1. IRAM placement: Move critical functions to IRAM with IRAM_ATTR
  2. DMA usage: Ensure SPI/I2S/ADC use DMA for large transfers
  3. Cache optimization: Align data structures, avoid PSRAM for hot paths
  4. Task priority tuning: Ensure real-time tasks have appropriate priority
  5. Compiler flags: -O2 or -Ofast for performance-critical components
  6. Algorithm selection: Replace O(n^2) with O(n log n) where applicable
  7. Interrupt latency: Minimize ISR processing, use deferred handlers
  8. Flash access: Reduce flash reads (cache-friendly code layout)

Memory Optimization

  1. Heap analysis: Run idf.py size-components to identify large consumers
  2. Stack tuning: Measure with uxTaskGetStackHighWaterMark(), reduce to actual + 25%
  3. Flash strings: Use PROGMEM (Arduino) or ensure const strings stay in flash
  4. PSRAM offloading: Move large buffers to PSRAM (MALLOC_CAP_SPIRAM)
  5. Component pruning: Disable unused ESP-IDF components in menuconfig
  6. Static allocation: Replace dynamic allocation with static for permanent objects
  7. Shared buffers: Reuse buffers across non-concurrent operations

Power Optimization

  1. Sleep mode selection: Deep sleep for >1s idle, light sleep for 10ms-1s
  2. WiFi power save: Enable modem sleep, use duty cycling
  3. Peripheral shutdown: Disable unused peripherals before sleep
  4. CPU frequency: Reduce to 80MHz when processing demand is low
  5. GPIO hold: Use gpio_hold_en() to maintain state during sleep
  6. Batch operations: Wake, do all work, sleep (minimize active time)
  7. ULP usage: Offload monitoring to ULP coprocessor during deep sleep

Read the full file on GitHub · 71 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 71 lines · 14 tokens per session scan A f1b697f7a571

Subscribe to this mod's changes

esp-optimize is a command published in the GitHub repository mathisk2095/jko-claude-plugins (3 stars, last pushed 4d ago), licensed MIT. It adds 14 tokens to every session and 834 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.