optimize

A command that examines code for possible performance problems, such as inefficient algorithms, excess memory use, repeated database queries, or unnecessary input and output work.

In plain words
What is it for?
Use it to review a file or code path for performance issues, verify whether a suspected bottleneck is real, and fix confirmed problems.
Why use it?
It turns a general request to make code faster into specific bottlenecks, proposed changes, trade-offs, and checks against available evidence.

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/hamr0/liteagents/optimize
Clone the repo
git clone --depth 1 https://github.com/hamr0/liteagents
Per session 8 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 596 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.00008 $0.00596
Opus 5 $0.00004 $0.00298
Sonnet 5 $0.00002 $0.00119
Haiku 4.5 $0.00001 $0.00060

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

Security

Grade A, and why

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 yesterday.

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.

packages/ampcode/commands/optimize.md · 62 lines

How it starts

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

Analyze $ARGUMENTS for performance.

Examine

  • Time complexity (Big O)
  • Space complexity
  • I/O operations
  • Database queries (N+1?)
  • Unnecessary allocations

Output

Per bottleneck:

  • Location (file:line)
  • Cost — what's slow and by how much. Concrete ("N+1 over ~1k rows on every page load"), not vague ("could be faster").
  • Optimization — specific change.
  • Expected improvement — order-of-magnitude estimate.
  • Trade-offs — readability / memory / consistency cost.

After the analysis — verify, then fix

Performance claims are easy to invent. Validate before acting.

Verify each bottleneck. Re-read the cited file:line in context. Confirm the path is actually hot — look for at least one of:

  • a profile / benchmark / log line showing call frequency or duration,
  • the path sits on an obvious hot loop / per-request handler with real volume,
  • the user provided evidence in the request.

Without one of those, the claim is uncertain — don't optimize on speculation. Mark each finding confirmed, false positive (with reason), or uncertain (needs profiling data).

Fix what's confirmed and unambiguous — minimal change, one obvious shape, no behavior change, no API change. Apply directly. After each edit, re-read the changed region and confirm it still computes the same answer (perf optimizations that quietly change semantics are the worst kind).

Stop and ask when (HITL gates — not all the time, only here):

  • the bottleneck is uncertain after grounding (no profile / log and not obviously hot),
  • the fix has multiple reasonable shapes (cache vs precompute vs batch vs paginate vs index) — present options with tradeoffs, not a chosen path,
  • it changes public API / response shape / DB schema / caller contract,
  • it trades correctness for speed (lossy approximation, weaker consistency, eventual-vs-strict) — even when "obviously" faster, or
  • it touches concurrency primitives (locks, atomics, ordering) — easy to introduce races.

Read the full file on GitHub · 62 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. yesterday First seen · 62 lines · 8 tokens per session scan A ec5ee88c1df2

Subscribe to this mod's changes

optimize is a command published in the GitHub repository hamr0/liteagents (22 stars, last pushed 2d ago), licensed Apache-2.0. It adds 8 tokens to every session and 596 once invoked, about $0.0000 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-30.