agentleFS
patonkikhpatonkikh/APES/skills/ai/prompt-optimizer/skill.md

prompt-optimizer

Skill3 starsChanged 4 months agoMITView on GitHub

Optimize prompts for token efficiency, latency, and output quality while preserving task behavior. Use when working on prompt engineering, AI workflows, agents, context design, or LLM optimization.

72 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use agent-architecture-audit, continuous-agent-loop and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • ronmkrSkill

    agent-architecture-audit

    Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature.

    Also in 3 projects that use this

  • junimnjwSkill

    continuous-agent-loop

    Patterns for continuous autonomous agent loops with quality gates, evals, and recovery controls.

    Also in 3 projects that use this

  • junimnjwSkill

    agent-harness-construction

    Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates.

    Also in 3 projects that use this

  • get-proofpilotSkill

    context-budget

    Audits Claude Code context window consumption across agents, skills, MCP servers, and rules. Identifies bloat, redundant components, and produces prioritized token-savings recommendations.

    Also in 5 projects that use this

  • LangChainSkill

    docker-patterns

    Best practices for Docker containerization and multi-stage builds

    Also in 4 projects that use this

  • royaluniondesign-sysSkill

    deployment-patterns

    Deployment workflows, CI/CD pipeline patterns, Docker containerization, health checks, rollback strategies, and production readiness checklists for web applications.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 58 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never remove safety constraints for token savings

    line 54
  2. Distinctive:

    Never remove output format contract

    line 55
  3. Distinctive:

    Use shorter synonyms and bullet lists over prose.

    line 118

“Common” is measured: kept by at least 6 in 10 of the 58 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
skill.md

Prompt Optimizer

Purpose

Optimize prompts for token efficiency, latency, and output quality while preserving task behavior.

Input: Prompt specification (reviewed), test cases, optimization goal (cost/latency/quality)
Output: Optimized prompt with change log, token comparison, and regression test plan Examples: See examples.md for worked input/output.


Workflow

Step 1: Baseline measurement

Document current prompt:

MetricValue
Template tokens (estimate)
Example tokens
Total typical request tokens
Optimization goalcost / latency / quality

Step 2: Identify optimization opportunities

Categories:

  • Redundancy — repeated instructions
  • Verbosity — instructions expressible more concisely
  • Example efficiency — fewer/shorter few-shot examples
  • Structure — reorder for model attention
  • Variable compression — summarize context inputs

Step 3: Apply optimizations

For each change:

ChangeTokens savedQuality riskRationale

Rules:

  • Never remove safety constraints for token savings
  • Never remove output format contract
  • Preserve test case pass behavior

Step 4: Produce optimized prompt

Deliver side-by-side or diff-style comparison:

  • Original section → Optimized section
  • Net token change

Step 5: Regression test plan

Map each test case from prompt-engineer:

Test IDMust still passRisk if fails

Recommend A/B test if quality risk is Medium+.

Step 6: Validate

Run Validation checklist.


Decision Rules

ConditionAction
No test cases availableStop; request from prompt-engineer
Optimization breaks safety constraintRevert change; safety > tokens
Quality risk High for a changeFlag; require A/B test before deploy
<10% token savingsReport low ROI; may not be worth complexity
Customer-facing promptNever remove refusal or delimiter rules

Validation

  • Baseline token metrics documented
  • ≥3 optimization changes with rationale
  • Optimized prompt preserves output format contract
  • Safety constraints unchanged
  • Token savings quantified (before/after)
  • Regression test plan covers all original test cases
  • Changes with quality risk flagged
  • No Role Play introduced

Anti-patterns

  • Strip safety for tokens — removing constraints to save tokens.
  • Optimize without tests — changes without regression verification.
  • Over-compress — ambiguous instructions that hurt quality.
  • Remove all examples — zero-shot when few-shot was needed.
  • False precision — exact token counts without noting estimation uncertainty.

Best Practices

  • Optimize iteratively; one change category at a time.
  • Use shorter synonyms and bullet lists over prose.
  • Move critical instructions to end of prompt (recency).
  • Track prompt versions with measured metrics.
  • Pair with prompt-reviewer after optimization.

Output Structure

# Prompt Optimization: [Prompt Name]

## Baseline
| Metric | Before |
|--------|--------|
| Template tokens | |
| Total typical | |

## Changes
| # | Change | Tokens saved | Risk |
|---|--------|--------------|------|

## Optimized Prompt
[Full optimized template]

## Comparison
| Metric | Before | After | Delta |
|--------|--------|-------|-------|

## Regression Tests
| Test ID | Must pass | Status |
|---------|-----------|--------|

## Recommendation
Deploy | A/B test first | Revert [change #]

Next Skills

OutcomeRecommended Skill
Re-review optimized promptai/prompt-reviewer
Context still too largeai/context-engineering
Quality degradedai/prompt-engineer
Cost at architecture levelai/ai-cost-optimizer

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.