cloudflare-kv:optimize

cloudflare-kv:optimize is a command for coding agents from secondsky/claude-skills. It costs 33 tokens per session (1,849 once invoked), scanned A, original, MIT.

A command that reviews Cloudflare Workers KV code for performance, cost, and reliability issues. KV is a key-value storage service where applications save and retrieve data by key.

In plain words
What is it for?
It is for scanning Worker files, checking KV reads and writes, and producing prioritized recommendations with code examples.
Why use it?
It points out missing expiration or caching settings, inefficient operations, and other patterns that may increase delay or usage costs.

Command

Installs and runs on its own, but its text points at files inside its plugin — anything it tells you to read at a ${CLAUDE_PLUGIN_ROOT} path is only there once the plugin is installed. Installing the plugin gets both.

Part of the cloudflare-kv plugin — 1 skill, 3 commands, 2 agents shipped together

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/secondsky/claude-skills/optimize-kv
Clone the repo
git clone --depth 1 https://github.com/secondsky/claude-skills

Or install cloudflare-kv, the plugin that ships this one along with the rest of its 1 skill, 3 commands, 2 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cloudflare-kv:optimize

README.md
[![agentmods](https://agentmods.dev/badge/commands/secondsky/claude-skills/optimize-kv.svg)](https://agentmods.dev/commands/secondsky/claude-skills/optimize-kv)
Your own site
<a href="https://agentmods.dev/commands/secondsky/claude-skills/optimize-kv"><img src="https://agentmods.dev/badge/commands/secondsky/claude-skills/optimize-kv.svg" alt="Measured on agentmods" height="20"></a>
Per session 33 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,849 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.00033 $0.01849
Opus 5 $0.00016 $0.00924
Sonnet 5 $0.00007 $0.00370
Haiku 4.5 $0.00003 $0.00185

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

Security

Grade A, and why

cloudflare-kv: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.

plugins/cloudflare-kv/skills/cloudflare-kv/commands/optimize-kv.md · 331 lines

How it starts

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

/cloudflare-kv:optimize - Analyze and Optimize KV Usage

This command analyzes Worker code for KV usage patterns and provides actionable optimization recommendations to improve performance and reduce costs.

What This Command Does

  1. Analyzes Code Patterns

    • Scans Worker files for KV operations
    • Identifies get(), put(), delete(), list() calls
    • Detects missing optimizations
  2. Checks Best Practices

    • TTL usage on put() operations
    • cacheTtl usage on get() operations
    • Error handling patterns
    • Bulk operation opportunities
    • waitUntil() for async writes
  3. Generates Report

    • Critical issues (must fix)
    • Warnings (should fix)
    • Optimizations (nice to have)
    • Code examples for each issue
    • Estimated cost/performance impact

How to Use

Analyze Single File

/cloudflare-kv:optimize src/index.ts

Analyze Multiple Files

Run multiple times for different files:

/cloudflare-kv:optimize src/index.ts
/cloudflare-kv:optimize src/api/routes.ts
/cloudflare-kv:optimize src/lib/kv-utils.ts

Interactive Mode

If no file specified, command will:

  1. Search for common Worker files (src/index.ts, index.js, worker.ts)
  2. List found files
  3. Ask which to analyze
/cloudflare-kv:optimize

Implementation

Execute the analysis script from the cloudflare-kv skill:

${CLAUDE_PLUGIN_ROOT}/scripts/analyze-kv-usage.sh <worker-file>

The script performs static code analysis to detect:

  • Missing TTL/expiration on put()
  • Missing cacheTtl on get()
  • Lack of error handling
  • Sequential operations that could be parallel
  • Missing pagination on list()
  • Opportunities for waitUntil()
  • JSON.stringify usage for objects

Example Output

Cloudflare Workers KV - Usage Analyzer
======================================

Analyzing: src/index.ts

KV Operations Found:
  - get():    15
  - put():    8
  - delete(): 3
  - list():   2

Issue Check 1: Missing TTL on put() operations
----------------------------------------------
⚠ 5 put() operation(s) without TTL/expiration
  Issue: Data will persist indefinitely, increasing storage costs
  Fix: Add expirationTtl or expiration to put() calls

  Example:
    await env.KV.put('key', 'value', { expirationTtl: 3600 });

Issue Check 2: Missing cacheTtl on get() operations
---------------------------------------------------
⚠ 12 get() operation(s) without cacheTtl
  Issue: Missing edge caching optimization
  Fix: Add cacheTtl for frequently-read data (min 60 seconds)

  Example:
    const value = await env.KV.get('key', { cacheTtl: 300 });

Issue Check 3: Missing error handling
-------------------------------------
✗ No try-catch blocks found
  Issue: KV operations can fail (rate limits, network errors)
  Fix: Wrap KV operations in try-catch

  Example:
    try {
      const value = await env.KV.get('key');
    } catch (error) {
      console.error('KV error:', error);
      // Handle gracefully
    }

Issue Check 4: Sequential get() calls (bulk read opportunity)
-------------------------------------------------------------
⚠ Multiple sequential await get() calls detected
  Issue: Each get() counts as separate operation
  Fix: Consider using Promise.all() for parallel reads

  Example:
    const [val1, val2, val3] = await Promise.all([
      env.KV.get('key1'),
      env.KV.get('key2'),
      env.KV.get('key3')
    ]);

========================================
Summary
========================================

Critical Issues:   1
Warnings:          3
Optimizations:     2

⚠ Critical issues found

Please address critical issues before deploying to production.

For more details, see:
  - references/best-practices.md
  - references/performance-tuning.md

Read the full file on GitHub · 331 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 · 331 lines · 33 tokens per session scan A eefbbfb84ac1

Subscribe to this mod's changes

cloudflare-kv:optimize is a command published in the GitHub repository secondsky/claude-skills (214 stars, last pushed 2d ago), licensed MIT. It adds 33 tokens to every session and 1,849 once invoked, about $0.0002 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-09-03.