optimize-skill skill
컨텍스트 비용 문제를 진단하고 동작을 변경하지 않으면서 최적화 패스를 적용하여 프레임워크 SKILL의 토큰 비용과 복잡도를 줄여줍니다.
- GitHub 스타
- 145
- 파일
- 3
- 마지막 커밋
- 2026년 11월 12일
- 라이선스
- Apache-2.0
- 허용된 도구
- —
optimize-skill skill은 무엇을 하나요?
optimize-skill은(는) agent skill입니다. 컨텍스트 비용 문제를 진단하고 동작을 변경하지 않으면서 최적화 패스를 적용하여 프레임워크 SKILL의 토큰 비용과 복잡도를 줄여줍니다.
skill의 SKILL.md에서 생성된 요약입니다.
optimize-skill skill 정보
optimize-skill은 프레임워크 SKILL의 토큰 비용과 복잡도를 줄이는 역할을 합니다. 이 SKILL은 기존 SKILL의 동작을 변경하지 않으면서 더 가볍게 만들어야 하는 개발자와 유지보수자를 위해 설계되었습니다. 본 SKILL은 과도하게 큰 본문, 하드코딩된 값, 임베디드 코드와 같은 컨텍스트 비용 문제를 진단한 후, 이를 해결하기 위한 구체적인 최적화 패스를 제안합니다.
에이전트가 이 SKILL을 로드하면 대상 SKILL 디렉토리 또는 특정 SKILL.md 파일에 대해 읽기 전용 진단을 수행할 수 있습니다. uv와 같은 도구를 사용하여 검증기를 실행하고, skill-token-count를 사용하여 설정된 중앙값 대비 예산을 측정합니다. 프로세스는 split, config-lift, out-of-context, fetch-upfront, preflight-classifier, extract-code, rewrite를 포함한 여러 단계의 패스로 구성됩니다. 이러한 패스를 하나씩 적용함으로써, SKILL은 변경 사항을 검토 가능한 상태로 유지하고 최적화 과정 전반에 걸쳐 검증기 상태를 정상으로 유지합니다.
agent가 수행할 수 있는 작업
- 1SKILL 토큰 소비 감소에이전트가 SKILL의 본문 예산 5,000 토큰 또는 상시 활성화 예산 200 토큰을 초과하는 원인을 진단할 수 있습니다.
- 2컨텍스트에서 임베디드 코드 제거개발자가 토큰을 절약하기 위해 SKILL 본문에 포함된 대규모 Python 또는 shell 프로그램을 인접한 scripts 디렉토리로 추출할 수 있습니다.
- 3효율성을 위한 여러 SKILL 감사유지보수자가 모든 SKILL을 전수 조사하여 500라인 구조 제한을 초과하는 SKILL을 식기할 수 있습니다.
- 4하드코딩된 설정 값 리팩터링프로젝트 설정에서 해결해야 하는 사용자 지정 값을 식별하여 최적화할 수 있습니다.
skill의 SKILL.md를 기반으로 작성되었습니다. 모든 사용 사례는 해당 문서의 인용구와 대조 확인되었습니다.
optimize-skill skill 설치 방법
각 명령은 skill 폴더를 클라이언트의 skills 디렉터리에 복사합니다. 클라이언트를 재시작하거나 새 세션을 시작하여 로드하세요.플러그인에 optimize-skill skill 설치
/plugin marketplace add apache/magpie /plugin install magpie-utilities@apache-magpie
Claude Code에 optimize-skill skill 설치
~/.claude/skills/optimize-skill/SKILL.md
$ npx degit apache/magpie/plugins/magpie-utilities/skills/optimize-skill ~/.claude/skills/optimize-skillClaude Code (project)에 optimize-skill skill 설치
.claude/skills/optimize-skill/SKILL.md
$ npx degit apache/magpie/plugins/magpie-utilities/skills/optimize-skill .claude/skills/optimize-skillCodex에 optimize-skill skill 설치
~/.agents/skills/optimize-skill/SKILL.md
$ npx degit apache/magpie/plugins/magpie-utilities/skills/optimize-skill ~/.agents/skills/optimize-skillGemini CLI에 optimize-skill skill 설치
~/.gemini/skills/optimize-skill/SKILL.md
$ npx degit apache/magpie/plugins/magpie-utilities/skills/optimize-skill ~/.gemini/skills/optimize-skillClaude.ai에 optimize-skill skill 설치
npx degit apache/magpie/plugins/magpie-utilities/skills/optimize-skill optimize-skill && zip -r optimize-skill.zip optimize-skill # claude.ai → Customize → Skills → + → Create skill → Upload a skill → optimize-skill.zip
SKILL.md
GitHub에서 보기optimize-skill
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:
PYTHONPATH="$(python3 -I -c 'import hashlib,os,sys;h,d,m,i=sys.argv[1:];r=os.path.realpath(os.curdir);s=os.stat(r);p=os.path.join(h,d,hashlib.sha256(r.encode()).hexdigest()[:16]);f=os.path.join(p,i);print(p if os.path.isdir(os.path.join(p,m)) and os.path.isfile(f) and open(f).read().split()==[str(s.st_dev),str(s.st_ino)] else h)' "$HOME/.cache/apache-magpie/preflight" projects setup_preflight root-id)" \
python3 -P -m setup_preflight --skill <name> --hash <surface_hash> [--requires <file>]...
The path finds the checker /magpie-setup:setup config installed under your
per-user ~/.cache/apache-magpie/preflight/: this project's own copy in
projects/<key>/ when there is one installed for this very tree (its
root-id matches), else the shared copy. Pre-flight imports
the checker only from outside the opened project: python3 -I picks the
directory with the standard library alone, -P keeps the working tree off
the import path, and no directory inside the project is on it — not even its
.git/ or .svn/, which a checkout or a tarball can carry as plain files.
Never add one.
{"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, andrulescarries that section's text. Follow it. Thefactsare 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
python33.11 or later — → 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 directories below), nothing has been set up here and there is nothing to reconcile — resolve this skill'srequires_config:entries yourself (first match wins:.apache-magpie-local/<file>, the main checkout's.apache-magpie-local/<file>,<git-common-dir>/apache-magpie/<file>,.svn/apache-magpie/<file>, then.apache-magpie-overrides/<file>), stay silent if they all resolve, and run/magpie-setup:setup configfor 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:setup configto install it or/magpie-setup:setup updateto refresh it, and carry on with the work.
Never run /magpie-setup: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:setup verify is the full diagnostic.
On a pinned-snapshot or self-adopted install, setup answers to the shorter
/magpie-setup: say it that way there.
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.
| target | why | |
|---|---|---|
SKILL.md body, pre-flight block excluded |
5,000 tokens | paid on every invocation of that skill |
description + when_to_use |
200 tokens | paid in every session, for every skill at once, invoked or not |
Measure both before Step 1 and again at Step 4:
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.
Also estimate the run cost: what one invocation actually reads, which the body alone understates.
security-issue-sync has a body of about 6k tokens, yet a routine run reads about 46k and its heaviest path about 53k, before any tool output.
Walk the steps for the routine path and the heaviest path, and add up SKILL.md, each sibling that path reads (file size ÷ 4), and a rough figure for what its tools return, such as issue bodies, mail threads or PR diffs.
Count a sibling behind a pointer only on a path whose trigger fires.
This is a guess, not a measurement: give it per path, state the assumptions, and keep the tool-output figure separate from the file total.
Prefer the pass that moves the routine path most, since that is what most runs pay.
Report both numbers and the run cost in Step 5 whether or not the pass moved them.
Inputs
- Target — a skill name, directory, or
SKILL.mdpath. --allorover:<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:
- Oversized body — past the 500-line cap, or one section dominating. → split
- Concrete names — adopter-specific values baked in instead of
resolved from
<project-config>. → config-lift - Bulk reads — pulling a whole issue or artefact into context to touch one field. → out-of-context
- Per-item round-trips — N sequential fetches that could be one batch. → fetch-upfront
- No cheap pre-filter — spending a model pass on items a deterministic check would skip. → preflight-classifier
- Embedded code — shell or Python living inside the body, paid for on every invocation although a model never needs to read it. → extract-code
- 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.
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.
Before cutting prose because a tool "already does this", compare the two line by line:
where they disagree, cutting the prose changes behaviour, so fix the tool first, with a test that fails before the fix.
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; followtools/AGENTS.mdfor 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.pyand 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— updateskill_mdandstep_heading. Find matches withgrep -rl '<heading text>' tools/skill-evals/evals/. - Anchor links — update
other.md#the-headingreferences; whole-treelycheeverifies 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>/:
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.
A suite that pastes the moved text into its prompt with also_include shows the rule still works, never that an agent reaches it,
so prove every new pointer as patterns.md describes under Split.
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/magpiePR.
References
patterns.md— the behaviour-preserving passes.rewrite.md— the paragraph-by-paragraph rewrite and the style-learning loop.write-skill— authoring a new skill.tools/skill-and-tool-validator— the gate.
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.
- 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
ghcall that is piped, redirected or wrapped in$(…), or that belongs in a vetted-ops read; that shape fails under the secure setup.
이 스킬의 파일
3optimize-skill skill 질문
Claude Code에 optimize-skill skill을 어떻게 설치하나요?
npx degit apache/magpie/plugins/magpie-utilities/skills/optimize-skill ~/.claude/skills/optimize-skill를 실행합니다. Claude Code는 ~/.claude/skills(모든 프로젝트) 또는 .claude/skills(한 프로젝트)에서 skills를 로드하며, 설명이 작업과 일치할 때 skill을 사용합니다.
optimize-skill skill을 사용할 수 있는 클라이언트는 무엇인가요?
Agent Skills 형식을 읽는 모든 클라이언트(Claude Code, Codex, Gemini CLI, claude.ai(ZIP으로 업로드))가 사용할 수 있습니다. skill 내 스크립트는 클라이언트가 코드 실행을 허용하는 경우에만 실행됩니다.
언제 optimize-skill을 사용해야 하나요?
사용자가 SKILL 최적화를 요청하거나, SKILL.md 파일이 너무 길다고 언급하거나, 감사 결과 500라인을 초과하거나 하드코딩된 값이 발견될 때 이 SKILL을 사용하십시오.