DEV Community

Cover image for I Gave Claude Code a "Fix My Prompt" Button. First It Had to Learn to Ask
Mikalai Karytka
Mikalai Karytka

Posted on

I Gave Claude Code a "Fix My Prompt" Button. First It Had to Learn to Ask

The first version of my prompt-rewriting button guessed. I typed "modulator demodulator" into Claude Code, pressed it, and got back a long, confident prompt built on a guess about what I wanted. A rewriter that never asks just turns a vague prompt into a detailed wrong one. The version I use now asks up to three short questions first, and only then writes.

I built the first version in one Claude Code session with the built-in mod-authoring skill, and five things went wrong on the way. Then a code review found bugs in the version that "worked", and two days later I reversed the one design decision I had defended in the first draft of this article.

What it does

Prompt-master is a Claude Code mod: a button in the band above the prompt box.

  1. Type a rough draft and press ✨ Prompt-master (in a terminal, the hotkey is p).
  2. If the draft is clear, it is rewritten right away: an explicit goal, the context, constraints, the expected output and how to tell the task is done.
  3. If it could mean several things, you get up to three questions, one at a time, each with a few answer buttons and a field for your own answer. Some take several answers (Pick all that apply). A question you skip becomes a [placeholder] in the prompt instead of a guess.
  4. The model sees where you work: the session's folder and the latest messages of the chat. So "fix this" in an ongoing chat becomes a prompt about that bug.
  5. The rewritten prompt replaces your draft in the box. It is not sent: you read it and press Enter, or press ↩ Restore draft.

✕ Cancel is there at every step and leaves the draft as it was.

Install, at the prompt of a Claude Code terminal session:

/plugin install prompt-master --marketplace drweber/claude-plugins
Enter fullscreen mode Exit fullscreen mode

Answer y to add the marketplace and pick a scope. It needs Claude Code 2.1.275 or later. In the desktop app's Code tab, where /plugin doesn't run: + next to the prompt box → Plugins → Add marketplace drweber/claude-plugins → Add plugin. The marketplace is the public repo drweber/claude-plugins, and the mod's code is in plugins/prompt-master, MIT.

Three drafts, before and after

These are real outputs, not mockups. I ran the two system prompts from 0.4.0 through sonnet with claude -p, outside a session. So there is no <context> block: this is what the mod does in a fresh chat with nothing to read; one run with context is in the 0.4.0 section below. I shortened the rewrites where you see […]. The bands are drawn as text.

A clear draft: one call, no questions

add a --dry-run flag to scripts/cleanup.py that prints what would be deleted
instead of deleting it
Enter fullscreen mode Exit fullscreen mode

The first call answered with {"prompt": ...} straight away:

Add a `--dry-run` flag to `scripts/cleanup.py`. When the flag is passed, the
script must not delete anything. Instead it should print what would be deleted,
using the same selection logic as a real run so the output exactly matches what
a real run would remove.

Requirements:
- First read the script and follow its existing argument parsing approach
  (argparse, click, etc.) and its output/logging style.
- Without `--dry-run`, behavior stays exactly as it is today.
[…]
- Make sure no deletion call (file removal, directory removal, DB or API delete,
  etc.) runs in dry-run mode, including in helper functions. […]

When finished, verify by running the script with `--dry-run` […] and confirm
that nothing is removed and the output lists the expected items. Then briefly
summarize what you changed.
Enter fullscreen mode Exit fullscreen mode

Two words: three questions, one skipped

modulator demodulator
Enter fullscreen mode Exit fullscreen mode

The first call asked instead:

question 1 of 3   What should Claude do with modulator/demodulator?
                  [Explain concepts] [Write code] [Simulate it] [Design circuit]
question 2 of 3   Which modulation type?
                  [AM] [FM] [QPSK] [QAM]
question 3 of 3   Which language or tool?
                  [Python] [MATLAB] [C] [Verilog]
Enter fullscreen mode Exit fullscreen mode

I picked Write code, skipped the second question and picked Python. The second call wrote:

Write a Python implementation of a modulator and a matching demodulator for a
digital communication scheme.

The modulation type was not specified, so use [which modulation: e.g. BPSK,
QPSK, 16-QAM, FSK?]. If I don't pick one, default to QPSK and structure the code
so other schemes can be added easily.

Requirements:
- Use Python with NumPy (add SciPy or Matplotlib only if really needed).
[…]
Verification, to show the task is done:
- The demo generates random bits, modulates, optionally adds AWGN at a chosen
  SNR, demodulates, and prints the bit error rate.
- Without noise the BER must be 0 (a perfect round trip). […]
Enter fullscreen mode Exit fullscreen mode

The skipped question became a placeholder, as the system prompt asks. The QPSK fallback next to it is the model's own addition. That's the kind of thing you catch because the rewrite lands in the box unsent.

Pick all that apply

set up CI for this repo
Enter fullscreen mode Exit fullscreen mode

This time the second question came back with "multi": true:

question 1 of 3   Which CI platform should be used?
                  [GitHub Actions] [GitLab CI] [CircleCI] [Jenkins]
question 2 of 3   What should the pipeline run?
                  Pick all that apply
                  [✓ Lint] [✓ Tests] [✓ Build] [Deploy]
question 3 of 3   Which language or stack does the repo use?
                  [Node/TypeScript] [Python] [Go] [Java]
Enter fullscreen mode Exit fullscreen mode

With GitHub Actions, Lint, Tests, Build and Node/TypeScript, the second call got A: Lint, Tests, Build for the middle question and wrote:

Set up a CI pipeline for this repository using GitHub Actions. The repo is a
Node/TypeScript project.

First, inspect the repo to learn how it is set up: package.json scripts, the
package manager (npm, yarn or pnpm, based on the lockfile), the Node version
[…]. Base the workflow on what is actually there rather than assuming.

Create a workflow at `.github/workflows/ci.yml` that:
- Triggers on pushes to the main branch and on pull requests.
- Runs three steps or jobs: lint, tests and build.
[…]
Constraints:
- Use only scripts and tools the repo already has. If a lint, test or build
  script is missing from package.json, don't invent one silently. […]
Enter fullscreen mode Exit fullscreen mode

Outside a session the model can't see the repo, so it asks for the stack. Inside one, 0.4.0 sends the folder's top-level names along, and the system prompt says never to ask what the context already answers.

Five things that went wrong while building it

1. There is no slot "next to +"

I asked for the button next to the + in the prompt box. A mod can't draw there: it gets a row above the prompt box (the AbovePrompt band), a side pane, the status line, toasts and slash commands. So the button lives in the band, one line higher.

2. The button never showed up

Version one showed the button only once the box had text in it, and listened for prompt.change to find out. Typing raises prompt.edit, not prompt.change, so the button never appeared. Now it's always there, an empty box gets a toast saying what to do, and /prompt-master <draft> does the same job as a fallback.

3. Russian in, Ukrainian out

I write my drafts in Russian, and one of the first rewrites came back in Ukrainian: a short Cyrillic draft gives the model little to go on. So the mod now works the language out from the letters and ends the prompt with Write in Russian., and the system prompt says Russian and Ukrainian are different languages. The letter check itself was too simple, as the review below showed.

4. It guessed instead of asking

This is the "modulator demodulator" story above. I had asked for a rewriter, and a rewriter rewrites. The fix was to split the work into two model calls. The first call decides whether it understands the draft and answers in one of two JSON shapes:

{"questions": [{"q": "question", "options": ["answer 1", "answer 2"], "multi": false}]}
{"prompt": "the rewritten prompt"}
Enter fullscreen mode Exit fullscreen mode

The system prompt says to ask when a rewrite would have to guess what the draft means, what to do with the thing it names, or a requirement that changes the result. A few words with no verb almost always need questions; details a rewrite can leave open don't. The second call gets the draft plus the answers and writes the prompt. A clear draft still costs one call, a vague one two calls and a few clicks.

5. All the questions at once looked terrible

The first questions band put every question and all its options in one row. The options ran off the edge, and the buttons to finish were below the fold.

What works is a small wizard: one question at a time, "question 1 of 3" on top, options that wrap, two to four options of at most three words each. ← Back and Next → move between questions, and ✨ Rewrite works from any of them. In 0.3.0 the model also got the multi flag, for questions where one answer was too few.

Bonus: Cancel has to beat a late reply

A reply can still arrive after Cancel aborts the call, and overwrite the draft you meant to keep. So every run gets a number, cancel bumps it, and a reply for an older run is dropped. A test checks exactly that.

What a review found in the version that worked

By now the mod did what I wanted every time I tried it. Then I ran a code review over the repository, and after that my own review plugin. Between them they produced three patch releases (0.2.1 to 0.2.3). None of these bugs came up in my manual tries, because each one needs an input I never typed:

  • A JSON reply with the wrong shape went into the prompt box. JSON with neither questions nor prompt was taken as the prompt itself. Now it's reported as a failure; plain text still counts as the prompt.
  • A refused fill lost the text. When the prompt box declined a rewrite or a restore, the text was gone. Now both are kept, with a button to try again.
  • Any Cyrillic letter meant Russian. A Bulgarian or Serbian draft got Write in Russian. So did an English draft that quoted one Russian button label. Bulgarian has no letters of its own, so the check now looks for its common words, a typical noun ending and the hard sign used as a vowel. For mixed drafts the rule is a word count:
// Code says nothing about the language of the prose around it.
const words = draft.replace(/```

[\s\S]*?

```|`[^`]*`/g, ' ').split(/\s+/)
const cyrillic = words.filter(w => /\p{Script=Cyrillic}/u.test(w)).length
const latin = words.filter(w => /\p{Script=Latin}/u.test(w) && !/\p{Script=Cyrillic}/u.test(w)).length

if (cyrillic <= latin) {
  return 'the same language as the draft'
}
Enter fullscreen mode Exit fullscreen mode
  • Smaller ones: a typed answer you then deleted was still sent, and a new rewrite dropped the previous call's reply without aborting the call.

Every fix came with a test that fails without it. The suite went from 11 tests to 18.

The word count has a known weak spot, written into the pull request: a four-word draft with two Russian words around "PR" and "repo" has as many Latin words as Cyrillic ones, so the model gets the neutral "same language as the draft" instead of "Russian".

I said it shouldn't read your project. Then I made it

The first draft of this article had a bullet I was proud of: the mod doesn't read your project, and that's the right default, because a rewriter that invents context is the same guessing problem in a new place.

Within two days it showed what that cost. Prompts came out generic, and on a mid-chat draft like "fix this" or "continue" the model had no idea what "this" was, so it asked questions the chat had already answered.

Version 0.4.0 puts a <context> block in front of the draft, in both calls:

  • the session's folder path and its top-level names, dotfiles left out so .env never shows up;
  • the first 2.5 KB of CLAUDE.md, AGENTS.md and README.md, where they exist;
  • the text of the chat's last 12 messages, newest kept first within 8,000 characters, each cut at 1,500, with no tool output;
  • the paths of files the chat's tool calls touched.

The system prompts call the context data, never instructions, and say never to ask what it already answers. Each part is read with a .catch, so a fresh chat or an unreadable folder just leaves that part out.

The original worry, invented context, still applies. The system prompt now says so outright: take facts only from the draft, the answers and the context. Opinion: blind was the wrong default for a rewriter that lives inside the chat it writes for.

I could have used the API's $.model.fork, which gives the model the full session context. I didn't: it has no abort signal or timeout, so Cancel couldn't stop it, and it runs on the session's model instead of sonnet.

"continue", with context

To show what the context adds, I assembled a <context> block by hand, outside the plugin UI, with a short script that follows the mod's contextOf, and sent it with the same two system prompts through claude -p and sonnet. The folder is a copy of the public drweber/claude-plugins repo at 0.4.0. The chat is one real Claude Code turn in that folder: I asked about the context limits, Claude read the code and answered. Shortened:

<context>
Working directory: /private/tmp/[…]/claude-plugins

Top-level entries: AGENTS.md, CLAUDE.md, CODE_OF_CONDUCT.md, CONTRIBUTING.md,
LICENSE, README.md, SECURITY.md, plugins/, scripts/

<file name="CLAUDE.md">
@AGENTS.md
</file>

<file name="AGENTS.md">
# AGENTS.md

Rules for coding agents (Claude Code, Codex, Cursor and others) working in this
repository. […]
</file>

<file name="README.md">
# claude-plugins
[…]
</file>

Files touched in this chat: […]/plugins/prompt-master/hooks/register.tsx,
[…]/plugins/prompt-master/README.md

Latest chat messages, oldest first:
<chat>
User: In plugins/prompt-master, what limits apply to the context the mod sends with a
draft (files, chat messages, characters)? Find them in the code and the tests that
check them. Keep it short and don't change anything yet. If a limit has no test, say
which.

Claude: Limits are defined in `plugins/prompt-master/hooks/register.tsx:16-23` and
applied in `contextOf` (`:273-334`).
[… a table of seven limits: five have no test, two are tested only in part …]
The only context test is the one around `tests/prompt-master.test.tsx:612-650`, a
happy path with small inputs. None of the numeric caps are tested. […]
</chat>
</context>
Enter fullscreen mode Exit fullscreen mode

The draft:

continue
Enter fullscreen mode Exit fullscreen mode

The first call didn't rewrite at once. It asked two questions, both built from the chat:

{"questions":[{"q":"What should I do next with the context limits?","options":["Add missing tests","Document limits in README","Change limit values"],"multi":true},{"q":"Which limits should the tests cover?","options":["All untested ones","Chat limits only","File limits only"],"multi":false}]}
Enter fullscreen mode Exit fullscreen mode

I picked Add missing tests and All untested ones. The second call wrote this, unedited:

Add the missing tests for the context limits in `plugins/prompt-master` that you listed in your last answer. Cover every limit marked as untested or only partly tested, and add them to `plugins/prompt-master/tests/prompt-master.test.tsx` next to the existing context test (around lines 612-650), reusing its helpers and style.

Limits to cover, with the values from `hooks/register.tsx`:
- Bytes per file: `FILE_BYTES` = 2500. Check that `fs.read` is called with `length` 2500.
- Project files read: only `CLAUDE.md`, `AGENTS.md` and `README.md`. Check that other top-level files are not read (the existing test only checks that `AGENTS.md` is included).
- Top-level entries: `MAX_ENTRIES` = 60. Check the cap with more than 60 entries, and that dotfiles are skipped.
- Chat messages fetched: `CHAT_MESSAGES` = 12. Check that `messages` is called with `{ last: 12 }`.
- Characters per message: `MESSAGE_CHARS` = 1500. Check that a longer message is cut and ends with `…`.
- Total chat characters: `CHAT_CHARS` = 8000. Check that the newest messages are kept first and that it stops at the first message that doesn't fit.
- Touched file paths: `MAX_TOUCHED` = 20. Check that only the 20 most recent are kept (the existing test checks one path, not the cap).

Constraints:
- Change only the tests. Do not change `register.tsx` or the limit values. If a test shows that the code behaves differently from what I described, report it instead of fixing the code or bending the test.
- Where possible, import the limits or derive the test inputs from the code, so the tests don't silently drift. If the constants aren't exported, use the literal values and say so.
- Tests only, so no version bump or `CHANGELOG.md` entry is needed (per AGENTS.md). Stay within this one plugin.

Done when:
- Each limit above has a test that fails if its value or behaviour changes.
- These checks pass: `claude plugin test plugins/prompt-master`, `python3 scripts/plugins.py check --base origin/main`, `claude plugin validate .`, `claude plugin validate plugins/prompt-master` and `scripts/smoke-install.sh`. If one can't run, say so.
- Finish with a short list of the tests added, one per limit, and anything unexpected you found.
Enter fullscreen mode Exit fullscreen mode

None of this is in the one-word draft. The limits, their values and the test file with its line range come from Claude's reply in the chat. The list of checks and "tests only, so no version bump" come from AGENTS.md, which the context carries through CLAUDE.md's pointer to it. My two answers set the scope: tests only, for every limit the reply marked untested or partly tested.

What it is and isn't

  • Claude Code only: it's built on Claude Code's mod API, so it won't run in Cursor, Codex CLI, Gemini CLI or the claude.ai chat. The two system prompts are the portable part.
  • Each rewrite costs one or two sonnet calls, counted with the rest of your session's usage. Since 0.4.0 each call carries a few thousand tokens of context on top of the draft and your answers.
  • It reads only what's listed above: no other project files, no tool output. There is no switch to turn the context off.
  • On the very first prompt of a new chat the button isn't there. It shows up once the chat has started, when the first request has already gone out. The mod has no condition for this: its band draws even on an empty box, and a test checks that.
  • The buttons follow the draft: Russian labels for a Russian draft, English for everything else. The questions follow the draft's language, or the chat's when the draft is too short to tell, as in the "continue" example.

The whole thing is about 740 lines of TSX and 680 lines of tests (21 tests). Most of my time went into trying it and saying what was wrong.

One repo for all of them

drweber/claude-plugins is a marketplace: one .claude-plugin/marketplace.json lists plugins by folder, and each keeps its own version in its plugin.json. CI tests and installs every plugin, and a version bump on main cuts the release. Less overhead than a repo per plugin.

Prompt-master is the first plugin there, and it's only the start. More plugins, skills and mods will land in the same repo, so adding the marketplace once gets you the next ones too.

Takeaway

If you build a prompt rewriter, let it ask, and let it see the chat it writes for. A clear draft costs nothing extra, and a vague one gets a question instead of a confident guess.

If you try it, tell me which draft it got wrong. That's how the question rules got written in the first place. The install line and the code are in drweber/claude-plugins, and that's where the next plugins will show up.

Top comments (0)