Software engineering

Bug fix prompt

A copy-and-paste prompt for ChatGPT, Claude or Gemini that gets a professional bug fix on the first try, plus the cheapest model that does it well.

What most people type

my react component keeps re-rendering infinitely, can you help? here's the code: ```jsx function Profile({ userId }) { const [user, setUser] = useState(null); useEffect(() => { fetch(`/api/users/${userId}`).then(r => r.json()).then(setUser); }); return <div>{user?.name}</div>; } ```

It works, but the AI has to guess your react version, so the first answer usually needs another round. The version below asks for exactly what a professional would deliver.

The better prompt

Debug why this React component re-renders infinitely, and give me the fixed code.

```jsx
function Profile({ userId }) {
  const [user, setUser] = useState(null);
  useEffect(() => {
    fetch(`/api/users/${userId}`).then(r => r.json()).then(setUser);
  });
  return <div>{user?.name}</div>;
}
```

Context: [React version, if relevant].

Please include:
1. The root cause, explained briefly.
2. The corrected component.
3. Any related problems in this code that I should fix too, such as a race condition when userId changes, missing error handling, or a missing cleanup. Keep these short and mark them as optional.

Replace the [brackets] with your details before you send it: user, setUser, React version, if relevant.

Why this version works

  • Stated task and requested fixed code. Gives a clear deliverable instead of 'can you help?'
  • Asked for root cause plus corrected component. Gets explanation and working fix in one answer
  • Added optional related issues to check. Catches race conditions and error handling without bloating the answer
  • Added React version placeholder. Version can affect behavior and advice

What a professional bug fix prompt covers

  • Asks for the cause and the fix
  • Asks for corrected code
  • React version placeholder or constraint

Watch out for

  • Altered code

Best AI model for this prompt

This is a everyday task: common bug (missing useEffect dependency array), but debugging means one wrong step ruins it. You don't need the most expensive model. The cheapest model at each company that handles it well:

CompanyModelPer usePer 1,000 uses
AnthropicClaude Sonnet 5.5$0.0043$4.30
OpenAIGPT-6.1 Terra$0.0022$2.15
GoogleGemini 3.8 Flashcheapest$0.0016$1.61

Pay-per-use list prices for this prompt and its expected answer (about 400 tokens). On a monthly chat plan, the same choice shows up as more messages before you hit your limit. See today's AI prices.

Bug fix prompt for ChatGPT, Claude and Gemini (Software engineering) · PromptSaver