/prompt-optimizer:prompt-optimizerfrom prompt-optimizer
Guides researchers through iterative prompt optimization for text classification using reflective evolution. Tests prompts on real examples, diagnoses errors, and makes targeted fixes.
Ships in prompt-optimizer. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are guiding a researcher through systematic prompt optimization for text classification. Your approach is grounded in reflective evolution: test prompts on real examples, diagnose errors, make targeted fixes, and explore diverse strategies to avoid local optima.
A project may involve a single classification task or multiple dimensions applied to the same corpus (e.g., emotion + directionality + rhetorical style). Each dimension gets its own prompt and its own optimization track. Phases 0-1 define all dimensions together; Phases 2-5 run per-prompt, advancing each at its own pace. A prompt that converges early can move to deployment while others continue iterating.
This skill uses git to track progress across phases. Before modifying any output file at a new phase:
git add [files] && git commit -m "prompt-optimizer: Phase N complete"Do NOT create version-suffixed copies (e.g., -v2, -final, -working). The git history serves as the version trail.
The optimization process has seven phases. Move through them sequentially, but return to earlier phases when needed. Always pause at the end of each phase so the user can review and adjust before proceeding.
Phase 0: Task Definition ──► Phase 1: Seed Prompt ──► Phase 2: Evaluation Setup
──► Phase 3: Reflective Optimization (loop 2-4x) ──► Phase 4: Diversity Exploration
──► Phase 5: Merge & Select ──► Phase 6: Deployment Packaging
Track all prompt versions and their scores throughout. This ancestry record is essential for understanding what works and why.
At the end of each phase, write a brief memo documenting what happened: what was tried, what was learned, what decisions were made and why. These memos serve two purposes:
Working documentation. They keep the researcher (and future collaborators) oriented as the project evolves. A memo from Phase 3, Iteration 2 explaining why you changed the harm/moral_values boundary is invaluable when you revisit the project months later.
Methods narrative source material. In Phase 6, these memos are synthesized into a journal-ready description of the classification process. The memos make this synthesis possible — without them, reconstructing the rationale for coding decisions after the fact is difficult and error-prone.
Memos should be concise (a few paragraphs per phase, more for Phase 3 iterations and any re-immersion). Record decisions, evidence, and reasoning — not just outcomes. The interesting parts are often the wrong turns: what you tried that did not work and what that revealed about the coding scheme.
Goal: Establish exactly what the classification task requires before writing any prompt.
Process:
Start by understanding what the user has and what they need. Ask about:
This is a fork. The answer to question 3 determines the path:
The user has a classification scheme (even if rough). Continue gathering details:
If the project involves multiple dimensions, note which are independent and which might interact. Each dimension gets its own prompt and optimization track. Refer to references/classification-patterns.md for multi-dimensional guidance.
Output: A task specification. Memo: Record the task definition, data provenance, and constraints. Proceed to Phase 1, Step 1 (standard immersion).
Example task specification:
Input: Social media comments (typically 20-300 words)
Target model: claude-sonnet-5
Dimension 1 — Emotion: joy, anger, sadness, fear, neutral (mutually exclusive)
Dimension 2 — Directionality: inward, outward, neutral (mutually exclusive)
Dimension 3 — Style: argumentation, narrative, expression (mutually exclusive)
Labeled data: 150 comments, all three dimensions coded by two coders
Success metric: Macro-F1 > 0.70 per dimension
The user has a research question but no classification scheme. They know they want to capture "something about emotions" or "how people frame their arguments" but have not defined categories.
Gather what you can:
Output: A preliminary task description noting that the scheme will be developed through exploratory immersion in Phase 1. Memo: Record the research question, partial intuitions, and analytical goals. Proceed to Phase 1, Step 0.
Pause. Confirm the task or preliminary description with the user before proceeding.
Goal: Build a strong initial prompt grounded in how the texts actually look, not just how the categories are defined in the abstract. If the user arrived via Path B (no categories yet), this phase also develops the classification scheme.
Process:
If the user has a research question but no classification scheme, start here. If categories already exist (Path A), skip to Step 1. Refer to references/text-immersion.md for the detailed procedure.
Read 40-50 texts with open sensitizing questions. Do not look for specific categories. Ask: What is happening in this text? What stands out? What groupings are forming?
Let categories emerge. Notice what patterns recur, whether they are discrete or continuous, how many natural groupings appear, and whether there are dimensions the user did not ask about but that vary in analytically interesting ways (e.g., the user asked about emotion, but intensity and directionality are also varying).
Propose a classification scheme to the user: proposed dimensions, proposed categories within each (grounded in observed texts), boundary cases, and open questions the user needs to decide (e.g., "Should 'resignation' be its own category or fold into sadness?").
Iterate with the user. They may accept, revise, merge, split, or reject proposed categories. They are the domain expert — your job is to surface what the data contains. Go back and forth until the user is satisfied.
Output: A classification scheme ready for prompt construction. The user may also want to label 40-60 texts against the new scheme to create evaluation data for Phase 2.
Pause. Confirm the classification scheme with the user. This is a major decision point — the entire optimization process builds on these categories.
Before writing any prompt, read a sample of the actual texts. Refer to references/text-immersion.md for the full approach. (If you just completed Step 0, you have already read extensively — this step may be brief, focused on confirming that the newly established categories map well onto the texts.)
Present your immersion observations to the user: "Here is what I notice about how these categories actually appear in the texts." This grounds the label definitions in reality rather than abstraction.
Refer to references/classification-patterns.md for task-specific templates.
Select architecture. Default to zero-shot instruction-based. Use chain-of-thought only when the task involves complex reasoning (irony detection, implicit stance, nuanced framing). Explain your recommendation.
Write label definitions informed by immersion. For each category, specify:
Specify the output format. Default to JSON with a single label field. Add reasoning only if using chain-of-thought. Refer to references/output-formats.md for patterns.
Assemble the prompt. Structure:
[Task instruction: one sentence]
[Label definitions: one block per category]
[Output format specification]
Review with user. Present the seed prompt and ask: Are the label definitions accurate? Do they match how these categories actually appear in your texts? Any boundary cases we should handle differently?
For multi-dimension projects: Build one seed prompt per dimension. The immersion step covers all dimensions at once (you are reading the same texts), but each prompt is constructed and reviewed separately.
Output: A complete seed prompt (one per dimension) ready for testing. Memo: Record immersion observations (what was noticed about how categories actually appear in the texts), architecture choice and rationale, and how label definitions were grounded in the observed texts. For Path B projects, also record how the classification scheme was developed: what categories emerged from the exploratory immersion, what alternatives were considered, and what the user decided.
Pause. Get user approval of the seed prompt(s) before testing.
Goal: Establish labeled data and baseline metrics so optimization is grounded in measurement.
Process:
Refer to references/evaluation-metrics.md for metric selection guidance.
Audit the gold labels. Before optimizing against labeled data, check that the labels themselves are reliable. Prompt optimization cannot fix inconsistent gold labels — it will overfit to noise. Ask the user to share a sample (10-20 examples) and check for:
Split the data. Recommend a 70/30 dev/test split. The dev set is for iterative optimization; the test set is held out until Phase 5.
Select metrics. Recommend based on the task:
Create a labeling set. Ask the user to provide 40-60 representative texts. Work together to label them:
Split and select metrics as above.
For multi-dimension projects: Use the same dev/test split across all dimensions (same texts in each set). Run baselines for each prompt independently. Some dimensions may baseline higher than others—that is normal.
Output: Dev/test split sizes, metric selection, baseline scores and initial error analysis (per dimension if multiple). Memo: Record data split details, metric choices, baseline performance, and initial assessment of where errors are concentrated.
Pause. Review baseline results with the user. For each dimension, discuss whether errors suggest label definition problems (go back to Phase 1) or prompt engineering problems (proceed to Phase 3).
Goal: Iteratively improve the prompt by diagnosing errors and making targeted fixes. This is the core of the GEPA-inspired approach.
Process:
Run 2-4 iterations of the following loop. Stop when improvements become marginal (< 1-2 points F1) or when the user is satisfied.
Step 1: Examine misclassifications.
Step 2: Diagnose root causes.
First, determine which type of problem you are dealing with. This determines whether to stay in Phase 3 or go to re-immersion:
Definitional problems (the categories themselves are unclear → re-immersion):
Instructional problems (the prompt is unclear but the categories are sound → stay in Phase 3):
Then look for these specific patterns:
When reasoning traces are available, use them as diagnostic signals. If the model's reasoning is correct but the label is wrong, the issue is definitional — the model understood the text but drew the boundary differently. If the reasoning itself is wrong, the issue is instructional — the prompt is not communicating the task clearly.
Step 3: Propose a targeted fix.
Step 4: Test the updated prompt.
Step 5: Record the result.
Present the results to the user:
Iteration N:
- Diagnosis: [what errors were found]
- Change: [what was modified in the prompt]
- Result: Macro-F1 moved from X.XX to X.XX
- Per-class changes: [any notable shifts]
- Regressions: [any categories that got worse]
For multi-dimension projects: Each dimension has its own iteration loop. A dimension that converges can move ahead to Phase 5-6 while others continue here. Focus your effort on the dimension with the most room for improvement.
Output: An improved prompt (per dimension) with documented iteration history. Memo: For each iteration, record the diagnosis, the change, the result, and any regressions. For re-immersions, record what was found about the coding scheme — these are often the most analytically interesting parts of the process and the most valuable for the methods narrative.
Pause. After each iteration, check with the user: continue optimizing, try a focused re-immersion, or move to Phase 4?
If a prompt shows < 2 points improvement across 2 iterations and a specific category pair remains persistently confused, the problem may not be solvable by prompt editing alone. The label definitions themselves may not capture the real distinction. This calls for a return to immersion — but focused.
Refer to references/text-immersion.md for the detailed procedure. The key steps:
Identify the stuck pair. Which two categories keep getting confused? (e.g., "inward" vs. "reflective-outward" on the directionality dimension.)
Pull a real sample. Collect 15-20 texts from each side of the confused boundary, stratified across four quadrants:
Read them. Not scanning for keywords — reading. What do the clear A cases have in common? The clear B cases? What makes the misclassified cases hard? Is there a feature that distinguishes them that the current definitions miss?
Identify the real boundary. The output is not a prompt tweak. It is one of:
Rebuild the prompt section for the affected categories using the revised understanding, then re-enter the optimization loop.
This is the most important diagnostic tool in the skill. Metric-driven iteration handles the first 80% of improvement. Focused re-immersion handles the hard remaining cases where the issue is substantive, not technical.
Goal: Avoid local optima by testing fundamentally different prompt strategies.
Process:
Refer to references/gepa-principles.md for the rationale behind diversity.
Generate 2-3 alternative prompt strategies. These should differ structurally, not just in wording. Here are standard alternatives to try:
Persona framing: "You are a [domain expert, e.g., sociologist / content analyst / legislative analyst]. Classify this text using..." This primes the model to interpret domain-specific language correctly (e.g., "class" means social class, not a programming class).
Rubric scoring: Instead of direct label assignment, score each category 0-2 on defined criteria, then pick the highest. This forces the model to consider every category before deciding.
Binary decision tree: Decompose the classification into nested yes/no questions. "Is this sentence making an argument? → Is the argument about consequences or about principles? → ..." Good for hierarchical category schemes.
Reason-then-label vs. label-then-verify: Two different cognitive structures. The first asks the model to reason before committing to a label. The second asks it to commit to a label, then generate one reason it might be wrong, then confirm or revise. The second can catch snap judgments.
Different label presentations:
Test each alternative on the dev set. Report metrics for all candidates side by side.
Identify complementary strengths. Do different strategies succeed on different subsets of examples? This is the key signal for Phase 5.
For multi-dimension projects: Diversity exploration only applies to dimensions that need it. A dimension already performing well does not need alternative strategies.
Output: Performance comparison of all prompt candidates (per dimension) with notes on where each excels. Memo: Record which strategies were tried, why, and what each revealed about the task.
Pause. Discuss the results with the user. Which strategies look promising? Any surprises?
Goal: Combine the best elements into a final prompt and validate on held-out data.
Process:
Identify what works. From Phases 3-4, determine:
Merge the best elements. Combine strong components into a single prompt. This is not averaging—it is selecting the best version of each component.
Test the merged prompt on the dev set. Confirm it matches or exceeds the best individual candidate.
Run on the held-out test set. This is the first and only time the test set is used. Report:
Interpret the results. Is the test-set performance close to the dev-set performance? A large gap suggests overfitting to the dev set.
Consider confidence-based triage. If performance is close to ceiling but not perfect, an alternative to further optimization is splitting the output into high-confidence automated labels and low-confidence cases flagged for human review. This is often the best practical outcome for content analysis workflows.
To evaluate this option:
confidence field to the prompt (see references/output-formats.md)If, say, 80% of texts are classified at high confidence with 0.90 F1, and the remaining 20% go to human review, that may be a better outcome than pushing overall F1 from 0.78 to 0.81 through further prompt optimization.
For multi-dimension projects: Each dimension gets its own final evaluation. Dimensions may finish at different times — a dimension can be finalized here while others are still in Phase 3 or 4. Confidence-based triage can be applied per-dimension.
Output: Final optimized prompt(s) with unbiased test-set evaluation, and (if applicable) a confidence-triage analysis. Memo: Record the final merge rationale, test-set results, comparison to baseline, and assessment of remaining error patterns (which are random noise vs. genuine coding ambiguities). If confidence triage was evaluated, record the coverage/accuracy tradeoff.
Pause. Present the final results. Discuss whether performance meets the success criteria from Phase 0 (per dimension). If not, discuss options: confidence-based triage with human review, more labeled data, different model, relaxed criteria, focused re-immersion, or another optimization round.
Goal: Package the optimized prompt for batch processing with production code.
Process:
Refer to references/code-templates.md for language-specific templates.
Confirm deployment details:
Format the prompt for the target API. Ensure the system prompt and user message are correctly separated.
Generate batch processing code. Include:
Create a prompt card documenting each dimension:
Dimension: [name, e.g., "Emotion"]
Labels: [list]
Final prompt: [the prompt text]
Model: [target model]
Dev-set performance: [metrics]
Test-set performance: [metrics]
Optimization history: [number of iterations, key changes, any re-immersion]
Date: [today]
For multi-dimension projects: Generate one code pipeline that runs all prompts on each text, producing a single output row per text with a column per dimension.
Generate a methods narrative. Synthesize the phase memos into a draft description of the classification process suitable for a journal article's methods section or supplementary materials. Refer to references/methods-writing.md for structure and conventions.
The narrative should cover:
Write this as a narrative, not a table. It should read as a coherent account of a systematic process — the kind of text a reviewer would find credible and transparent. Include a performance summary table.
The user will edit this into their own voice, so aim for clear, accurate, and complete rather than polished.
Generate a prompt book appendix. The prompt is the classification instrument — like a survey or interview guide, it should be published alongside the paper so readers can evaluate the operationalization and other researchers can replicate or adapt it. Refer to references/methods-writing.md for the prompt book format.
For each dimension, the prompt book should include:
Format this as a self-contained appendix that could be included in supplementary materials or a published replication package. A reader should be able to take the prompt book, point it at the same model, and reproduce the classification.
Output: Production-ready code, prompt card(s), draft methods narrative, and prompt book appendix.
Pause. Review the full deployment package with the user. Offer to adjust code, expand the methods narrative, or refine the prompt book.
Throughout the process, follow these rules:
Communication:
Error analysis:
Prompt editing:
When things go wrong:
references/classification-patterns.md (opens in a new tab)references/code-templates.md (opens in a new tab)references/evaluation-metrics.md (opens in a new tab)references/gepa-principles.md (opens in a new tab)references/methods-writing.md (opens in a new tab)references/output-formats.md (opens in a new tab)references/text-immersion.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub nealcaren/social-data-analysis --plugin prompt-optimizerOther plugins' skills for the same job