This is the most common scenario in software development. You get a working draft, but it needs polish.
The biggest risk here is context bloat. If you just keep saying "fix this, now fix that," Claude's context window will fill up with the history of the old code, the bugs, and the fixes, eventually causing it to lose track of the current state of the file.
Here is the best workflow for iterating on code while keeping Claude's context perfectly clean and up to date.
The most important habit to build is creating checkpoints. When Claude gives you that "OK" initial version, you should treat it as a save point in a video game.
The Workflow:
/clear.Why this works: You don't carry the history of the "bad" code in Claude's memory. It only sees the final, improved version.
When asking for those initial improvements or bug fixes, be highly specific to prevent Claude from rewriting the entire file from scratch (which wastes tokens and can introduce new bugs).
Rule: Tell Claude what to touch, and explicitly tell it what NOT to touch.
auth.py file, deleting other working functions).validate_token function inside auth.py. It fails when the token is expired. Please update only the validate_token function to handle expired tokens gracefully. Do not modify the rest of the file."If the bug requires running the code to see the error, let Claude do the debugging. Do not copy-paste terminal errors into the chat if Claude can run the command itself.
The Workflow:
npm start, the app crashes when I click the submit button."npm start, look at the error, identify the bug in Form.js, and fix it."npm start, read the stack trace from the terminal output directly into its context, find the line in Form.js, and propose the fix.Because Claude reads the terminal output itself, it gets the exact, unmodified error message and the exact file state simultaneously.
CLAUDE.md)If the "improvement" you are making changes the overall architecture or rules of the project, you must update CLAUDE.md after the fix is applied.
Example: You ask Claude to fix a slow database query. It fixes it by adding an index and changing the ORM syntax.
CLAUDE.md under the 'Conventions' section to note that all database queries must use the new indexed syntax we just implemented."This ensures that the next time you /clear the context, Claude won't revert to the old, slow way of doing things.
git diff for ReviewWhen Claude applies the modifications, you shouldn't just trust them. You can ask Claude to review its own changes using Git.
git diff and review the changes you just made. Are there any edge cases you missed? Are there any leftover console logs or debug statements?"Claude will look at the diff (which is very token-efficient compared to reading whole files) and often catch its own minor mistakes before you commit them.
/clear to wipe the history of the bug fix from Claude's memory.CLAUDE.md if the fix introduced a new project rule.ai