cairo-optimization

cairo-optimization is a skill for Claude Code, Codex from keep-starknet-strange/starknet-agentic. It costs 55 tokens per session (2,279 once invoked), scanned A, original, MIT.

A guide for making Cairo programs cheaper and faster after their tests already pass. Cairo is a programming language commonly used for Starknet smart contracts.

In plain words
What is it for?
Use it to profile Cairo code, reduce execution steps or gas usage, improve arithmetic and loops, and reduce smart-contract storage use.
Why use it?
It helps locate slow or expensive code before changing it, while checking that optimizations do not alter correct behavior.

Skill for Claude CodeCodex

Written for Claude Code and Codex: allowed-tools in frontmatter, but also agents/openai.yaml present.

Part of the starknet-agentic-skills plugin — 19 skills, 2 commands, 1 plugin shipped together

Good fit Use it to profile Cairo code, reduce execution steps or gas usage, improve arithmetic and loops, and reduce smart-contract storage use.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/keep-starknet-strange/starknet-agentic/cairo-optimization
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.

Any agent
npx skills add keep-starknet-strange/starknet-agentic --skill cairo-optimization
Clone the repo
git clone --depth 1 https://github.com/keep-starknet-strange/starknet-agentic

Made for: Claude Code, Codex.

Or install starknet-agentic-skills, the plugin that ships this one along with the rest of its 19 skills, 2 commands, 1 plugin.

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 cairo-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/keep-starknet-strange/starknet-agentic/cairo-optimization.svg)](https://agentmods.dev/skills/keep-starknet-strange/starknet-agentic/cairo-optimization)
Your own site
<a href="https://agentmods.dev/skills/keep-starknet-strange/starknet-agentic/cairo-optimization"><img src="https://agentmods.dev/badge/skills/keep-starknet-strange/starknet-agentic/cairo-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 55 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,279 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00055 $0.02279
Opus 5 $0.00028 $0.01140
Sonnet 5 $0.00011 $0.00456
Haiku 4.5 $0.00006 $0.00228

Measured 7d ago against content hash a5d5a12847a2, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

cairo-optimization 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 7d ago.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/bounded_int_calc.py, scripts/profile.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

skills/cairo-optimization/SKILL.md · 180 lines

How it starts

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

Cairo Optimization

You are a Cairo optimization assistant. Your job is to profile existing code, identify hotspots, apply targeted optimizations, and verify no regressions were introduced. Apply only after tests pass and behavior is locked.

When to Use

  • Reducing gas/steps in hot paths after correctness is established.
  • Profiling Cairo functions to find bottlenecks.
  • Rewriting expensive arithmetic, loops, or storage patterns.
  • Applying BoundedInt optimizations for limb assembly and modular arithmetic.
  • Packing storage fields to reduce slot usage.

When NOT to Use

  • Early feature prototyping without tests (write tests first with cairo-testing).
  • Contract architecture decisions (cairo-contract-authoring).
  • Security audit (cairo-auditor).
  • Deployment operations (cairo-deploy).

Quick Start

  1. Confirm tests pass with snforge test.
  2. Profile hot paths with python3 skills/cairo-optimization/scripts/profile.py profile.
  3. Load references based on optimization type — see the table in Orchestration.
  4. Apply one optimization class at a time, re-test after each.
  5. Compare before/after profiles and document measurable deltas for changed hotspots.
  6. Encode stable optimization regressions in ../../evals/cases/contract_skill_benchmark.jsonl to prevent benchmark drift.
  7. Emit a handoff block using ../references/skill-handoff.md; optimization → testing is optional for regression hardening, but optimization → auditor is mandatory before merge.

Rationalizations to Reject

  • "Let's optimize before we have tests."
  • "We can skip re-profiling — the change is obviously better."
  • "BoundedInt types are too complex — let's use raw u128 math."
  • "We can calculate bounds by hand instead of using the CLI tool."

Mode Selection

  • profile: User wants to find bottlenecks. Run profiler, identify hotspots.
  • arithmetic: User wants to optimize math (DivRem, loops, Poseidon). Apply rules from legacy-full.md.
  • bounded-int: User wants BoundedInt optimization for limb assembly or modular arithmetic.
  • storage: User wants to pack storage fields or reduce slot usage.

Read the full file on GitHub · 180 lines

Files

What ships with it

9 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 7d ago First seen · 180 lines · 55 tokens per session scan A a5d5a12847a2

Subscribe to this mod's changes

cairo-optimization is a skill published in the GitHub repository keep-starknet-strange/starknet-agentic (80 stars, last pushed 2d ago), licensed MIT. It adds 55 tokens to every session and 2,279 once invoked, about $0.0003 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.