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.
npx agentmods add commands/secondsky/claude-skills/optimize-kvgit clone --depth 1 https://github.com/secondsky/claude-skillsWrote 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.
[](https://agentmods.dev/commands/secondsky/claude-skills/optimize-kv)<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>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.
| Model | Per session | Once 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 |
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.
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
-
Analyzes Code Patterns
- Scans Worker files for KV operations
- Identifies get(), put(), delete(), list() calls
- Detects missing optimizations
-
Checks Best Practices
- TTL usage on put() operations
- cacheTtl usage on get() operations
- Error handling patterns
- Bulk operation opportunities
- waitUntil() for async writes
-
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:
- Search for common Worker files (src/index.ts, index.js, worker.ts)
- List found files
- 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
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.
- yesterday First seen · 331 lines · 33 tokens per session scan A eefbbfb84ac1
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.
Other commands, from other repositories
correlate
Find related failures through pattern matching.
diff
Compare two command outputs with intelligent diff.
open
Open/retrieve an offloaded output by ID or shortcut.
search
Search through offloaded outputs with hard caps.
stats
Show FewWord session statistics with rich output and token savings.
timeline
Visual timeline of command outputs in current session.