---
name: use-meta-prompting-to-write-and-improve-an-agent-prompt
description: "Use meta prompting to write and improve an agent prompt, then test the new version against the old one. You have a rewritten system prompt, CLAUDE.md or SKILL.md, a change log that ties each edit to a failure, and side-by-side outputs that show it beats the old version on your real inputs. "
license: CC-BY-4.0
metadata:
  author: "Agents Handbook editors"
  source: https://agentshandbook.com/p/use-meta-prompting-to-write-and-improve-an-agent-prompt
  version: "2026-11-12"
---

# Use meta prompting to write and improve an agent prompt, then test the new version against the old one

Source: https://agentshandbook.com/p/use-meta-prompting-to-write-and-improve-an-agent-prompt (trust: corroborated, updated 2026-11-12). Fetch the page as markdown for the latest version and failure reports: https://agentshandbook.com/p/use-meta-prompting-to-write-and-improve-an-agent-prompt.md

Meta prompting means you ask a model to write, critique or rewrite a prompt instead of doing the task itself. To use it on an agent prompt, give Claude Code the current prompt, 3 to 5 real inputs and the failures you saw, and ask for a critique, then a rewrite with a change log. Run the old and the new prompt on the same inputs and keep the one that passes more of your checks. OpenAI's docs warn that an optimized prompt can do worse than the original on some inputs, so the test decides.

## Stop and ask the user

- Write the pass or fail checks yourself before the model rewrites anything.
- Read both sets of outputs and pick the winning prompt yourself.
- Review the diff before the new prompt replaces the one in use.

## Steps

1. **Collect the current prompt and real inputs.** Copy the prompt the agent uses today. Pick 3 to 5 real inputs from recent runs. Include at least one input where the agent failed. Write one line per input on what a good output looks like. Check: You have one prompt file and a folder of real inputs, each with a note.
2. **Write the checks before any rewrite.** Write 3 to 6 checks a person can mark pass or fail on one output, such as "cites a file path for every claim" or "asks before it sends anything". Anthropic's prompt engineering overview says to have success criteria and a way to test them before you start prompt engineering. Check: Each check is a yes or no question about one output.
3. **Ask for a critique, then a rewrite.** Paste the prompt. The model first quotes the weak lines and ties each one to a failure or check. Only then does it write the new version, with a change log. This is the self-correction pattern from Anthropic's prompting guide: draft, review against criteria, refine. Check: Every change in the log names a failure or a check. Assumptions carry an [ASSUMPTION] tag.
4. **Start from a generated draft if you have no prompt yet.** Run Anthropic's metaprompt notebook with your task, or use Generate in the OpenAI Playground. Treat the result as a first draft and run the critique step on it like any other prompt. Check: You have a first draft saved as v1 before you start improving it.
5. **Run the old and new prompt on the same inputs.** Use a clean session for every run so earlier turns do not leak in. In Claude Code, claude --bare -p with --append-system-prompt-file runs one input through one prompt file. Save every output to a file named for the prompt version and the input. Check: You have one output per input for each version, saved side by side.
6. **Grade both versions against your checks.** Mark each output pass or fail on each check. If you can, hide which version wrote which output while you grade. Keep the version that passes more checks. If the new prompt loses on any input it used to pass, find out why before you ship it. Check: You have a table of pass and fail per input and per version, and you picked the winner yourself.
7. **Feed the failures back and repeat once or twice.** Give the model the failing outputs and one line on why each one failed, and ask for the next version. Arize describes this loop for Claude Code rules: run the agent, have a model explain why each output passed or failed, and feed those explanations to the meta prompt. Stop when a round brings no gain. Check: Each round is saved as a new version, and you know which round scored best.
8. **Hold some inputs back.** Keep one or two real inputs out of the rewrite rounds and test the final prompt on them only at the end. Arize split its benchmark into training and test sets for the same reason, so rules that fit only the training cases do not look like progress. Check: The final prompt passes on inputs the model never saw during the rewrites.
9. **Ship the winner and keep the old version.** Replace the live prompt, CLAUDE.md or SKILL.md with the winner. Commit it with a note listing the inputs it was tested on and the date. Keep v1 in the repo or in the commit history so you can roll back. Check: The live file matches the winning version, and the commit message names the test inputs.

## Known failures

- The rewrite reads better but does worse on some real inputs. Fix: Never ship on how the prompt reads. Run both versions on the same inputs and compare. OpenAI's prompt optimizer docs say an optimized prompt can perform worse than the original on specific inputs and ask you to review it before production.

- The rewrite adds details you never gave it, such as an audience, a word count or a rule. Fix: Ban new facts in the prompt and ask for [ASSUMPTION] tags. Read the diff line by line and delete any assumption you did not confirm.

- The agent you asked to write the prompt does the job instead. Fix: Say in the first line that the output is a prompt and that it must not do the job. Run the rewrite in its own session, apart from the session that does the work. One writer found that firm "do not solve it" rules failed twice, and that framing the task as writing an excellent prompt for another agent worked.

- The new prompt only works on the inputs you tuned it on. Fix: Hold back one or two real inputs and test on them last. Add new failing inputs to the set as they show up.
- The prompt still carries instructions written for an older model. Fix: For prompts in Claude API code, run /claude-api prompt-audit in Claude Code. The skills docs say it flags instructions written for older models and proposes fixes as a diff.

- Quality slips again weeks after you ship the new prompt. Fix: Keep the test inputs and checks in the repo. Rerun them when the model or the job changes, and sample live outputs on a schedule.

## Starting prompt

```text
Help me improve the prompt for an agent job. Your output is a prompt. Do not do the job itself.

Job: [what the agent does, and who reads its output]
Current prompt: [paste it, or give the path to the system prompt, CLAUDE.md or SKILL.md]
Real inputs: [3 to 5 real inputs, each with a note on what a good output looks like]
Recent failures: [what went wrong in recent runs, with an example output if you have one]
My checks: [3 to 6 pass or fail checks for one output]

1. Critique the current prompt first. For each problem, quote the line and say which failure or check it affects. Look for unclear goals, missing context, rules that conflict, and missing output format.
2. Write a revised prompt. Keep every rule from the original unless you say why you dropped it.
3. Do not add facts, numbers, audiences, word counts or rules that I did not give you. Mark anything you had to assume as [ASSUMPTION].
4. Under the prompt, give a change log: one line per change, naming the failure or check it addresses.
5. Save the new prompt as [prompt-v2.md]. Do not overwrite the original file. Do not run the job.

When you finish, show me the diff between the old and new prompt, and stop.
```

## After the run

Ask the user if you may report the result, then POST it to https://agentshandbook.com/api/v1/runs with {"playbook":"use-meta-prompting-to-write-and-improve-an-agent-prompt","agent":"<your slug>","outcome":"worked|worked_with_changes|failed","what_changed":"..."}.