Study guide · Programming with AI assistants
Programming with AI Assistants: Context, Plans, Tests and Review
In many teams, AI assistants now write a large share of the code. They are fast, but they guess. On this page you learn which kinds of tools exist and how to give them the right context. You learn to scope tasks so that you end up with a small, reviewed diff. On top of that come tests as guardrails, reviewing AI code, the typical mistakes models make, and a safe workflow with Git.
A running example is a small team building the web app Invoicebox. The app creates invoices and has a frontend, a backend with a database, and a test suite in the CI pipeline.
Three kinds of tools
In daily work you meet three kinds of AI help. The lines between them are blurry, and many products offer all three.
- Autocomplete in the editor suggests how the current line or function continues while you type. You accept the suggestion with one key or simply keep typing.
- A chat assistant answers questions and returns code suggestions as text. It only sees what you give it, and you carry the result into the project yourself.
- A coding agent works inside the project. It reads files, changes them, and runs commands such as tests or the build.
An agent works in a loop. It reads files to understand the existing code. Then it changes code, often in several places. After that it runs the tests or the build, evaluates the result, and fixes what is still wrong. Approvals and deployments are not part of this loop. They stay with a human or with the team's pipeline.
Well-known examples are Claude Code, GitHub Copilot and Cursor. The products change all the time, but the way of working behind them stays the same. At their core, all suggestions come from a large language model. It produces likely continuations of a text. Plausible does not mean proven correct. That is why you must check every result.
Which tool fits when? If a developer on Invoicebox wants to finish a short helper function while typing, autocomplete is enough. It works locally at the cursor. But if an outdated logging library has to be replaced in 60 files, and all tests must pass afterwards, that is a typical job for an agent. It then works on its own branch, presents a plan first, runs the tests, and at the end someone reads the diff. Working directly on the main branch leaves no way back.
Giving context
In any single request, a language model only knows what is in its context window. That is the amount of text the model can take into account at once for one request. It is measured in tokens. Instructions, files and the conversation so far all have to fit. Whatever is not in there, the model does not know for that request.
Targeted context improves the suggestions. Name the affected files or functions explicitly, or attach them. Leave out files that do not matter. Irrelevant files confuse the model and use up space. Dumping a whole repository into the window only fills it.
When the build fails, the most helpful thing for the assistant is the complete error message, including the stack trace. It names the file, the line and the cause. A vague description such as "the build is broken" forces it to guess.
The history of a session is part of the context too. If a chat has grown long and is about a different topic than the new task, it is better to start a new session or clear the history. Old, unrelated context is a distraction. When an agent session fills the window, tools summarize older content or drop it. Details get lost along the way, and early instructions can fade.
If a session keeps going in circles after two failed attempts at a fix, a fresh start is usually the most effective step. Otherwise the failed attempts stay in the history and keep steering the model in the wrong direction. Start over with a more precise task and what you learned from the attempts.
Project rules in a file
Many tools automatically load an instructions file from the repository into every session. In Claude Code it is called CLAUDE.md. GitHub Copilot uses copilot-instructions.md in the folder for GitHub settings, and Cursor has rules. The file gives the assistant lasting project rules and hints.
What belongs in it? Mainly what the assistant cannot read from the code by itself:
- The commands to build, test and lint the project.
- Conventions that do not follow directly from the code, for example how migrations are named.
- Mandatory steps, for example that the tests run before every commit.
Secrets such as passwords or API keys do not belong in it, and neither do copies of the code. Generic advice such as "Write clean, readable code" does not help either. The model aims for that anyway. What is valuable are concrete, project-specific details.
Keep the file short. It is loaded into every session and takes up space in the context window there. An overloaded file dilutes the rules that matter.
If a project has different conventions for frontend and backend, path-specific rules help. Many tools allow rules that apply only to certain paths or file types, for example only to all TypeScript files. The assistant then gets the matching instructions depending on which file it is editing. Personal preferences that do not apply to the whole team belong in a local setting that is not checked in. That can be a local file that Git ignores, or the tool's user settings.
The Invoicebox rules file says: "Never run database migrations." Even so, the agent starts a migration one day. The right conclusion: whatever must never happen has to be enforced technically. The means for that are permission rules that forbid certain commands, a sandbox, restricted access, or hooks that check a command before it runs and block it.