Free 15-minute callFree 15-minute call →
艾维禾砺Vibe Coding LabIvheli · 1:1 coaching
Practical path

How to reduce rework when writing code with AI

Letting AI write directly often produces results, but more easily produces code that looks right but is not. Get verification, planning and context right, and there is much less rework.

Updated 2026-11-113 min readFree guides · 79/96

One premise: context fills up

What AI sees while writing code is: the conversation, the files it has read, the command output. These all occupy context, and the fuller the context, the more easily it forgets earlier requirements and makes basic mistakes.

So almost all best practices revolve around one thing: in a limited context, getting it to do the right thing and check itself.

First priority: give it a way to verify itself

This is the most time-saving step. Without acceptance criteria, AI can only hand over “looks right” work, and you become the only check.

Three common approaches:

  • Give tests: state the expected input and output clearly, and have it run them after writing
  • Give screenshots: for UI tasks, have it compare the screenshot after changes with the original, list the differences and fix them
  • Give commands: build, format checks and type checks as the criteria for “done”

Example: instead of just saying “make an email validation function”, say “user@example.com returns true, invalid returns false; run the tests after writing”.

Explore first, then plan, then write

The recommended order:

  1. Explore: have it read the relevant files and answer “how is this implemented now”
  2. Plan: have it list which files to change, how many steps, and where the risks are
  3. Implement: write according to the plan, checking against acceptance criteria as it goes
  4. Commit: write a clear commit message for the change

Small changes with a clear scope (edit copy, add one log line) can skip planning; for multi-file changes and unfamiliar areas of the code, planning saves a lot of rework.

Give the prompt concrete context

  • Point at files: use @file or a path instead of “that login place”
  • Give constraints: no new dependencies, must stay compatible with old data, do not change the interface
  • Give examples: have it follow how an existing page is written
  • Give symptoms: the original error text, reproduction steps, what counts as fixed

Vague questions are useful too, but only for exploration: “where do you think this file could be improved?”

Environment setup is worth the time

  • Project note file: state the stack, directories, commands and conventions (Claude Code uses CLAUDE.md, other tools call it AGENTS.md); shorter is more effective, put details in links
  • Permissions: allow which commands it may run, to avoid confirming every time
  • Tool access: database, browser, internal systems (MCP or the command line)
  • Automated checks: formatting, types, tests as the gate before committing

Managing conversations

  • Correct early: interrupt as soon as the direction looks wrong, do not wait for it to finish
  • Compact context: one task per conversation; start a new one when done
  • Split sub-tasks: send research and lookup to sub-agents and bring only the conclusion back to the main conversation
  • Checkpoints: save state at key moments so you can roll back if something breaks

When not to use AI coding

  • You cannot judge whether the result is right at all: build the acceptance criteria first
  • Core logic involving money, permissions or client data: must have human review
  • The team has no tests and no version control: fix the basics first, otherwise changes cannot be traced

Checklist

  • Every task has executable acceptance criteria
  • Multi-file changes have AI produce a plan first
  • Prompts name the files, constraints and examples
  • There is a short project note file
  • One conversation per task, compacted promptly
  • Key changes get human review
  • Problems can roll back to the last checkpoint

Reference: key points adapted from Anthropic’s official documentation “Best practices for Claude Code”, rewritten for general AI coding tools.

Questions

Do I have to use a tool like Claude Code?

The method here applies to any AI coding tool that can read and write files and run commands; Claude Code is just an example. The key difference is whether it can verify results itself, not the brand.

Why plan before writing code?

Letting AI act directly easily solves the wrong problem. First have it read the code and state which files to change and how; after you confirm, it writes, avoiding large-scale rework. Small changes with a clear scope can skip planning.

What if context keeps running out?

The context window is a limited resource, and the fuller it gets, the more easily things are forgotten. The approach: one conversation per task, compact history promptly, delegate research to sub-agents, and save checkpoints at key moments.

Want to apply this to your own work?

Read next

Share this article

Where should your idea start?

Bring an idea or a question to a free 15-minute call. Confirm the conversation language and time when booking.

Book a free 15-minute call

Where should your idea start?

Free 15-minute call →Free guides

Book a free 15-minute call

Contact

Booking formEnterprise AI implementation & system developmentSee enterprise services (official site)
Add us on WeChat, mention Vibe Coding and tell us what you want to do
Add us on WeChat, mention Vibe Coding and tell us what you want to do