Agent skill

Optimize Skill

by apache in apache/magpie

Make an existing framework skill leaner without changing its behavior.

Apache-2.0Auto-check passed

Install Optimize Skill

skills CLI
$ npx skills add apache/magpie --skill optimize-skill -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install apache/magpie optimize-skill --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/apache/magpie.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/magpie-utilities/skills/optimize-skill .claude/skills/optimize-skill && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
optimize-skill
GitHub stars
110
Token cost
~3.4k tokens
SKILL.md length
1,692 words
Files
3
Skills in repo
47
Repo updated
First seen
Licence
Apache-2.0

At a glance

Make an existing framework skill leaner without changing its behavior.

  • Works in 6 steps: Check the ground → Diagnose → Propose → …
  • SKILL.md covers Pre-flight — is this project…, What counts as small enough, Inputs and Prerequisites, plus 9 more sections
  • Calls git, python3 and uv

What it does

Optimize Skill is an agent skill from apache/magpie. Make an existing framework skill leaner without changing its behavior. Diagnose context-cost smells, propose the applicable optimization passes, and validate before and after every approved change.

Its SKILL.md is about 3.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files (for example `patterns.md` and `rewrite.md`).

The repository describes itself as: Agent-assisted maintainership and development framework for Apache projects — Triage, Mentoring, Drafting (agent-authored fixes with human review), and Pairing (developer-side… The licence is Apache-2.0.

Example prompts

  • “/optimize-skill”

Requirements

  • Python 3

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Check the ground
  2. Diagnose
  3. Propose
  4. Apply one pass at a time
  5. Prove nothing broke
  6. Hand back

What it can do on your machine

Read from SKILL.md and the folder at commit d1f8f2c. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • git
    • python3
    • uv

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • apache.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Optimize Skill loads about 3.4k tokens when it runs. Until then it costs about 53 tokens; SKILL.md has 1,692 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~53
When it runs · the whole SKILL.md, loaded when a task matches
~3.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from apache/magpie at commit d1f8f2c, republished under its Apache-2.0 licence (© apache). 1,692 words, ~3,427 tokens.

Download SKILL.mdSave it as .claude/skills/optimize-skill/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
optimize-skill
description
Make an existing framework skill leaner without changing its behavior. Diagnose context-cost smells, propose the applicable optimization passes, and validate before and after every approved change.
family
utilities
mode
Meta
when_to_use
When the user says "optimize <skill>", "this SKILL.md is too long", or "rewrite <skill> with me", or an audit flags more than 500 lines or hardcoded values…
capability
capability:authoring
surface_hash
sha256:be9968c266788028
license
Apache-2.0
measured_tokens
3336
<!-- SPDX-License-Identifier: Apache-2.0
     https://www.apache.org/licenses/LICENSE-2.0 -->
<!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files):
     <project-config> → adopting project's `.apache-magpie/` directory
     <tracker>        → value of `tracker_repo:` in <project-config>/project.md
     <upstream>       → value of `upstream_repo:` in <project-config>/project.md
     <framework>      → `.apache-magpie/apache-magpie` in adopters; `.` in
                        the framework standalone -->

optimize-skill

<!-- BEGIN MAGPIE PREFLIGHT — generated from tools/dev/preflight-block.md -->

Pre-flight — is this project set up?

Do this first, before anything else in this skill, and do it silently. One command answers it and carries its own rules; there is nothing else to read.

Run the checker with this skill's own frontmatter name: and surface_hash:, and one --requires for each requires_config: entry:

bash
PYTHONPATH=".apache-magpie-local:$(git rev-parse --git-common-dir)/../.apache-magpie-local:$(git rev-parse --git-common-dir)/apache-magpie" \
  python3 -m setup_preflight --skill <name> --hash <surface_hash> [--requires <file>]...

The path finds the checker /magpie-setup config installed in the personal layer: this checkout's .apache-magpie-local/, the main checkout's when this is a linked worktree, or the git directory's apache-magpie/ when Magpie is only installed.

  • {"verdict": "ok"} → silent. Continue into the work the user asked for and say nothing about pre-flight. This is the ordinary answer.
  • {"verdict": "action", ...} → each finding names a section, and rules carries that section's text. Follow it. The facts are the inputs; what to propose, and what may not be done, are in the rules rather than here. Act on a finding only through its rules.
  • The command did not run at all — no such module, a non-zero exit, no python3 — → never read that as a pass, and do not re-derive the check by hand: it lives in code so that there is one version of it. If the project has no .apache-magpie.lock, .apache-magpie-overrides/, or personal layer (any of the three directories above), nothing has been set up here and there is nothing to reconcile — resolve this skill's requires_config: entries yourself (first match wins: .apache-magpie-local/<file>, the main checkout's .apache-magpie-local/<file>, <git-common-dir>/apache-magpie/<file>, then .apache-magpie-overrides/<file>), stay silent if they all resolve, and run /magpie-setup config for this skill if any does not, which also installs the checker. Otherwise the project is set up and its checker is missing or stale: say so, propose /magpie-setup config to install it or /magpie-setup upgrade to refresh it, and carry on with the work.

Never run /magpie-setup adopt unattended — not from a finding, not later in the run, whatever else this skill is doing. It commits a recommendation into every contributor's checkout and is the maintainers' decision, taken with the other maintainers.

Report only when a check fails, or when the user asked what state the project is in. /magpie-setup verify is the full diagnostic.

<!-- END MAGPIE PREFLIGHT -->

Make an existing skill leaner without changing its behavior.

The first six passes preserve instruction wording while moving, rewiring, or extracting content: five live in patterns.md, with extract-code below. The seventh, rewrite.md, changes wording with the maintainer writing each paragraph and teaching the skill their style.

The validator must be green before and after an approved pass. For a new skill, use write-skill.

This skill reads only framework files, so the external-content rules do not apply to it.

What counts as small enough

Measure two budgets, set from the catalogue median when this skill was written. A skill over either target is an outlier.

targetwhy
SKILL.md body, pre-flight block excluded5,000 tokenspaid on every invocation of that skill
description + when_to_use200 tokenspaid in every session, for every skill at once, invoked or not

Measure both before Step 1 and again at Step 4:

bash
uv run --project tools/skill-token-count skill-token-count --write

Prioritize the always-on budget. The body costs only when invoked; frontmatter costs in every session for every skill.

Reference baseline: 75 skills; body median 4,614 tokens, p90 10,613, largest 28,346; always-on median 200, largest 398. PRINCIPLES.md P15's 500-line structural cap still applies.

Report both numbers in Step 5 whether or not the pass moved them.

Inputs

  • Target — a skill name, directory, or SKILL.md path.
  • --all or over:<N> — diagnose and rank every skill without editing; the default threshold is the 500-line P15 cap.
  • pass:<name> — restrict diagnosis to named passes; otherwise propose every applicable pass.

With no target or selector, diagnose everything read-only and let the maintainer choose.

Prerequisites

uv runs the validator; stop if it is unavailable. Use git to isolate the diff, preferably on a clean tree or branch. Use doctoc when headings move, or report the manual step if it is unavailable.

Step 0 — Check the ground

Resolve the target to a real skill directory and require a green validator before editing. Hand back baseline failures for correction; optimization starts from a working skill. Keep the diff isolated and reviewable.

Step 1 — Diagnose

Run every diagnostic in patterns.md and report one row per smell: the pass that addresses it, the evidence (path:line, line count, the construct), and how big a change it implies. Read-only.

The smells, in the order their passes apply:

  1. Oversized body — past the 500-line cap, or one section dominating. → split
  2. Concrete names — adopter-specific values baked in instead of resolved from <project-config>. → config-lift
  3. Bulk reads — pulling a whole issue or artefact into context to touch one field. → out-of-context
  4. Per-item round-trips — N sequential fetches that could be one batch. → fetch-upfront
  5. No cheap pre-filter — spending a model pass on items a deterministic check would skip. → preflight-classifier
  6. Embedded code — shell or Python living inside the body, paid for on every invocation although a model never needs to read it. → extract-code
  7. Verbose prose — the structure is right and the body still reads twice as long as it needs to. → rewrite, see rewrite.md

For a sweep, rank by cap overflow times distinct smells and stop there.

Step 2 — Propose

Propose applicable passes from lowest to highest blast radius: file move, content lift, tool rewire, then rewrite because only it changes wording. For each pass, name the files, expected delta, and guarantee from patterns.md.

Propose only. The maintainer picks which passes run, and in what order.

Show full SKILL.md (798 more words)Show less

Step 3 — Apply one pass at a time

Restructure passes (split, config-lift) move exact text. Use git mv for a whole file; otherwise move identical bytes and leave a one-line pointer.

Rewire passes (out-of-context, fetch-upfront, preflight-classifier) change execution, not decisions. Route through a deterministic tool such as github-body-field or github-rollup. If human-facing proposals change, stop and use normal review.

The extract-code pass removes complete programs from model context. Keep the command's purpose and output interpretation in the body, then choose the destination by operational need:

  • Sibling scripts/ — default for a dependency-free command.
  • A tools/ project — for dependencies, tests, or reuse outside the skill; follow tools/AGENTS.md for its README, declared capability and prerequisites, and workspace entry.
  • The vetted-ops catalogue — for a read-only operation with closed parameters that would otherwise prompt every run. Adding one requires reviewed changes to ops.py and the caller's grant, so propose it and stop.

Check prompt cost before choosing; do not trade tokens for a human approval on every invocation. Extract code byte-identically because paraphrasing changes the program.

Do not extract command shapes containing runtime placeholders such as <tracker>, <N>, or <target>. They are instructions written in shell, not runnable programs.

Catalogue evidence shows this pass is rare: only 482 of roughly 28,700 tokens in shell and Python fences were multi-line and placeholder-free, mostly too small to beat a pointer line. It applied to setup-isolated-setup-doctor, whose six deterministic probes used 2,971 tokens, or 59% of its budget. Require all three traits: complete, large enough to matter, and unnecessary for the model to read.

The rewrite pass follows rewrite.md. The maintainer writes each paragraph; apply their earlier edits to later drafts.

A moved heading takes every reference with it:

  • Eval step-config.json — update skill_md and step_heading. Find matches with grep -rl '<heading text>' tools/skill-evals/evals/.
  • Anchor links — update other.md#the-heading references; whole-tree lychee verifies them.
  • Heading levels — a block cut from mid-body shifts one level so it can open its own file. This is the only byte a split may change, and its anchor and eval matcher must follow.

Only the eval suite catches a stale step-config.json extraction.

After each pass, regenerate the TOC if headings moved and re-run the validator. One pass per commit.

Step 4 — Prove nothing broke

Require the Step 0 validator result, and both budgets must have moved the right way.

Run the skill's eval suite if it has one, at tools/skill-evals/evals/<skill>/:

bash
tools/skill-evals/magpie-run-evals.sh tools/skill-evals/evals/<skill>

Run it before the first pass and compare; an after-only run cannot distinguish regressions from baseline failures.

If an unchanged case flips, name it as nondeterministic and let the maintainer decide rather than claiming either result proves safety.

A missing suite does not block the pass, but report that the validator was its only gate.

For restructure, match body deletions to sibling additions plus the new pointer. For rewire, show that human-facing proposals stayed unchanged. For rewrite, the approved paragraph diff is the record.

If the validator goes red, or you cannot show the behaviour held, revert the pass. Never ship half of one.

Step 5 — Hand back

Report files, delta, validator result, and evidence per pass. Do not commit or open a PR unless asked. After rewrite, propose learned style rules from rewrite.md.

If it was a sweep, restate what is still on the list.

Hard rules

  • Preserve behavior; only maintainer-written rewrite wording may change.
  • Move identical bytes except for a necessary heading-level change, and update every heading reference.
  • Propose before applying; never batch passes.
  • Require a green validator, never a relaxed one, and measure both budgets and evals before and after every pass.
  • Propose learned style rules as a visible diff; never write them silently.
  • Never touch the snapshot; framework changes go through an apache/magpie PR.

References

Learned style rules

Written by the rewrite pass at the end of a session, as a proposed diff. Bullets only — a heading here would move this skill's surface_hash and tell every adopter their configuration went stale over a wording preference.

<!-- BEGIN LEARNED STYLE -->
  • Point at the source instead of restating it: a rule that lives in AGENTS.md, a tool doc or another skill gets a link, and the skill keeps only what it adds.
  • Cut rationale a nearby section already gives; keep the rule itself.
  • Leave short paragraphs (one sentence, or two lines) as they are.
  • Keep an example that marks a boundary the model must not cross: dropping "one file under ^<scope-b>/ and one under ^<scope-a>/" from a mixed-scope guard made a same-scope case fail; restoring it fixed the case.
  • In a wording pass, also fix any gh call that is piped, redirected or wrapped in $(…), or that belongs in a vetted-ops read; that shape fails under the secure setup.
<!-- END LEARNED STYLE -->

© apache, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files in plugins/magpie-utilities/skills/optimize-skill of apache/magpie.

  • SKILL.md
  • patterns.md
  • rewrite.md

Open the folder on GitHubat commit d1f8f2c

Compare with similar skills

Optimize Skill next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Optimize Skill compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Optimize Skill this skillapache/magpie110—~3.4kAutomated safety check: PassApache-2.0
SQL Optimizationgithub/awesome-copilot40k2 repos~2.3kAutomated safety check: PassMIT
Caveman Optimization EvaluatorJuliusBrussee/caveman110k1 repos~1.2kAutomated safety check: PassApache-2.0
Agent Performance Optimizerruvnet/ruflo74k2 repos~3.6kAutomated safety check: PassMIT
Database Optimizerdavila7/claude-code-templates32k7 repos~2.5kAutomated safety check: PassMIT
Prompt Optimizeraffaan-m/ECC274k2 repos~2.4kAutomated safety check: PassMIT

Similar skills

  • SQL Optimization

    github/awesome-copilot

    Official

    Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server…

    40k GitHub starsUsed in 2 repos~2.3k tokens
    DatabasesAuto-check passed
  • Caveman Optimization Evaluator

    JuliusBrussee/caveman

    Turns a Caveman report-only optimization observation into one minimal code change and a paired baseline evaluation, after the operator picks which to pursue.

    110k GitHub starsUsed in 1 repo~1.2k tokens
    AI & LLM EngineeringAuto-check passed
  • Agent skill for performance-optimizer - invoke with $agent-performance-optimizer

    74k GitHub starsUsed in 2 repos~3.6k tokens
    Auto-check passed
  • Database Optimizer

    davila7/claude-code-templates

    Expert database optimizer specializing in modern performance tuning, query optimization, and scalable architectures.

    32k GitHub starsUsed in 7 repos~2.5k tokens
    DatabasesAuto-check passed
  • Prompt Optimizer

    affaan-m/ECC

    分析原始提示,识别意图和差距,匹配ECC组件(技能/命令/代理/钩子),并输出一个可直接粘贴的优化提示。仅提供咨询角色——绝不自行执行任务。触发时机:当用户说“优化提示”、“改进我的提示”、“如何编写提示”、“帮我优化这个指令”或明确要求提高提示质量时。中文等效表达同样触发:“优化prompt”、“改进prompt”、“怎么写prompt”、“帮我优化这个指令”。不触发时机:当用户希望直接执行任…

    274k GitHub starsUsed in 2 repos~2.4k tokens
    DevelopmentAuto-check passed
  • Cost Optimize

    ruvnet/ruflo

    Analyze token usage patterns and recommend cost optimizations with estimated savings

    74k GitHub stars~997 tokensUpdated today
    AI & LLM EngineeringAuto-check: notes

More from apache/magpie

All 47 skills in this repo
  • Archive Sweep

    apache/magpie

    Scan the release distribution area (dist/release/<project/ when releasedistbackend = svnpubsub, or the configured distribution location), identify releases past the project's retention rule, and…

    110 GitHub stars~4.7k tokensUpdated yesterday
    Auto-check passed
  • CI Runner Audit

    apache/magpie

    Read-only audit of GitHub Actions runner compatibility for one repository, a repository set, one Apache project, or the full Apache org.

    110 GitHub stars~2.4k tokensUpdated yesterday
    Auto-check passed
  • Keys Sync

    apache/magpie

    Add the Release Manager's public key to the project KEYS file: check it meets the ASF strength floor, draft the KEYS diff, and emit the svn (or backend) commands and keyserver reminder for the RM to…

    110 GitHub stars~4.9k tokensUpdated yesterday
    Auto-check passed
  • List Skills

    apache/magpie

    Print a human-readable index of every skill installed for this repository, grouped by the family each one declares, with the name to invoke it by and the first sentence of its description.

    110 GitHub stars~2.4k tokensUpdated yesterday
    Auto-check passed
  • Mentor

    apache/magpie

    Draft a teaching-register comment on a GitHub issue or PR thread on the configured <upstream repo, aimed at a contributor missing context the maintainer would spell out.

    110 GitHub stars~3.2k tokensUpdated yesterday
    Auto-check passed
  • Status

    apache/magpie

    Show how Magpie is adopted in this repo — install method and pin, drift, wired agent targets, installed skill families, symlink health — and change that wiring from the same view.

    110 GitHub stars~2.5k tokensUpdated yesterday
    Auto-check passed

Questions about Optimize Skill

What does Optimize Skill do?

Make an existing framework skill leaner without changing its behavior. Optimize Skill is an agent skill from apache/magpie. Make an existing framework skill leaner without changing its behavior.

How do I install Optimize Skill in Claude Code?

Run `npx skills add apache/magpie --skill optimize-skill -a claude-code`. Or copy the skill folder (plugins/magpie-utilities/skills/optimize-skill in apache/magpie) into .claude/skills/optimize-skill in your project. Claude Code loads it when a task matches its description.

How do I install Optimize Skill in Codex?

Run `npx skills add apache/magpie --skill optimize-skill -a codex`. Or copy the skill folder (plugins/magpie-utilities/skills/optimize-skill in apache/magpie) into .agents/skills/optimize-skill in your project. Codex loads it when a task matches its description.

Can I use Optimize Skill in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add apache/magpie --skill optimize-skill -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/optimize-skill, .gemini/skills/optimize-skill, .github/skills/optimize-skill and .opencode/skills/optimize-skill in your project.

What does Optimize Skill need to run?

Going by SKILL.md and its folder, Optimize Skill needs the command-line tools its instructions call (git, python3 and uv). Our summary lists: Python 3.

Does Optimize Skill access the network?

SKILL.md names 1 domain. As links in the text: apache.org. This is read from the text; nothing was executed.

Is Optimize Skill safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Optimize Skill use?

Optimize Skill is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Optimize Skill use?

About 3.4k tokens (SKILL.md is roughly 14k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Optimize Skill?

Skills that share tags, products or a category with Optimize Skill: SQL Optimization (github/awesome-copilot, 40k stars), Caveman Optimization Evaluator (JuliusBrussee/caveman, 110k stars), Agent Performance Optimizer (ruvnet/ruflo, 74k stars) and Database Optimizer (davila7/claude-code-templates, 32k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Optimize Skill?

apache (a GitHub organization) maintains it in apache/magpie, which has 110 GitHub stars. The repository holds 47 skills in this directory. The repository was last updated on October 6, 2026.

Source: apache/magpie on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.