To use AI for coding well, give it a small, specific task, the context it can't guess (files, conventions, constraints), and a check it can run, such as a failing test; then review the resulting diff as carefully as a colleague's pull request. The quality of the result depends far more on the task definition and the verification step than on which model you use.
A prompt that works: "In src/auth/session.ts, users are logged out after a token refresh. Write a failing test that reproduces it, then fix it. Run the test suite and show me the output."
Pick the right kind of AI tool for the task
"AI for coding" covers three different tools. GitHub's Copilot guidance makes the split between the first two; agents add a third:
| Tool type | Good for | Weak at |
|---|---|---|
| Inline completion | Finishing the line or block you are typing, repetitive code, code from a comment, tests while doing TDD | Anything needing knowledge of files you don't have open |
| Chat | Explaining code, answering questions, drafting a larger section you then refine, regular expressions | Changes spread across many files; it can't run your code |
| Agent (edits files, runs commands) | Multi-step tasks with a clear finish line: fix a failing test, migrate an API, add a feature across files | Vague goals with no way to check success; long sessions that fill its context |
Copilot's docs list what it does best: writing tests and repetitive code, debugging and correcting syntax, explaining code and generating regular expressions. They also note it doesn't replace your expertise: "Remember that you are in charge."
Give it a way to verify its own work
This is the biggest single improvement. The Claude Code docs put it plainly: "Claude stops when the work looks done. Without a check it can run, 'looks done' is the only signal available, and you become the verification loop." A check is anything that returns pass or fail: a test suite, a build exit code, a linter, a script that compares output to a fixture, a screenshot compared to a design.
| Weak prompt | Better prompt |
|---|---|
| "implement a function that validates email addresses" | "write a validateEmail function. test cases: [email protected] is true, invalid is false, [email protected] is false. run the tests after implementing" |
| "the build is failing" | "the build fails with this error: [paste]. fix it and verify the build succeeds. address the root cause, don't suppress the error" |
Both examples come from the Claude Code docs, which also recommend asking for evidence (the command it ran and its output) rather than a claim of success. With chat-only tools that can't run code, you run the check yourself and paste the result back.
Explore, plan, then code
For anything bigger than a one-line fix, separate understanding from changing. The Claude Code docs describe four phases:
- Explore. Ask it to read the relevant code and explain how it works, without changing anything. "Read
src/authand explain how sessions are created and refreshed." - Plan. Ask for a plan: which files change, what the flow will be, what could break. Edit the plan yourself; this is the cheapest point to catch a wrong approach.
- Implement against the plan, with tests.
- Commit with a descriptive message, after you have reviewed the diff.
The same docs give a sensible limit on when to bother: "If you could describe the diff in one sentence, skip the plan."
Provide the context it can't infer
A model knows common languages and libraries, not your project. Copilot's guidance says to "break down complex tasks" and "be specific about your requirements"; the Claude Code docs say to reference specific files, mention constraints and point to example patterns. In practice:
- Name the files. "In
billing/invoice.py" instead of "in the billing code". - Point to an example to copy. "Follow the pattern in
HotDogWidget.php" beats a description of your conventions. - State constraints. No new dependencies, keep the public API unchanged, must run on Python 3.10, avoid mocks in tests.
- Paste the exact error, with the stack trace, not a paraphrase.
- Write down project rules once. Many tools read an instructions file automatically (Claude Code reads
CLAUDE.md; Copilot supports custom instruction files). Put build and test commands, code style that differs from defaults, and project quirks there. Keep it short: the Claude Code docs warn that "bloated CLAUDE.md files cause Claude to ignore your actual instructions".
For general prompt technique, see how to write a good prompt.
Keep sessions short and focused
Everything in a session (your messages, every file read, every command output) occupies the model's context window, and the Claude Code docs note that "performance degrades as it fills". Practical habits:
- Start a fresh session for each unrelated task.
- If you've corrected the same mistake twice, stop. Start over with a better first prompt that includes what you learned. The docs observe that a clean session with a better prompt "almost always outperforms a long session with accumulated corrections".
- Scope investigations. "Find where we parse dates in the API layer" is better than "look into dates".
Review everything before it ships
Copilot's docs say you "should always validate the code it suggests": understand it, review it for functionality, security, readability and maintainability, and run automated checks. GitHub's separate review guide adds the AI-specific failure modes: "hallucinated APIs, ignored constraints, or incorrect logic", and packages that don't exist. Look at the actual diff (git diff), not the assistant's summary of it, and watch for unrequested edits, deleted tests and suppressed errors. The full checklist is in how to review AI-generated code.
Keep security boundaries
- Treat output as untrusted. OWASP's guidance for LLM output is a "zero-trust approach": don't pipe model output straight into a shell,
evalor a database query. - Check every suggested package exists and is the one you meant before installing it. OWASP warns that models "may also hallucinate non-existent software packages", which attackers can register.
- Limit what agents can run. Agents that execute commands should have an allowlist or sandbox and no access to production credentials. Content they read (web pages, issues, files) can contain instructions aimed at the model; see prompt injection explained.
- Keep secrets out of prompts. Strip API keys, tokens and customer data before pasting code or logs.
Tasks AI coding tools handle well
- Explaining unfamiliar code or an error message, and asking follow-up questions you'd hesitate to ask a colleague.
- Writing tests for existing code, especially edge cases you list.
- Boilerplate: data classes, CLI argument parsing, API clients from a spec, config files.
- Mechanical changes across many files with a clear rule and a test suite to confirm them.
- First drafts of scripts and one-off tools where you can check the output directly.
They need the most supervision on design decisions, security-sensitive code, performance-critical paths and anything where "it runs" is not the same as "it's correct". Use them there too, but as a drafting partner whose every line you check.
Frequently asked questions
- Will AI coding tools make me a worse programmer?
- They can if you accept code you don't understand. Use them in a way that keeps you reading: ask for explanations of unfamiliar code, review every diff, and write or at least check the tests yourself. GitHub's own guidance says Copilot doesn't replace your expertise and that you are in charge.
- Is it safe to paste company code into an AI tool?
- That depends on the tool's data terms and your employer's policy, not on the code. Check whether your plan uses inputs for training, how long data is retained, and whether your organisation has approved the tool. Never paste secrets such as API keys or passwords; remove them first.
- Which is better for coding, autocomplete or chat or agents?
- They suit different jobs. Inline completion is best for finishing code as you type and repetitive patterns. Chat is better for questions, explanations and generating a larger section you then refine. Agents that can edit files and run commands suit multi-step tasks with a clear check, such as making a failing test pass.
- Why does the AI get worse the longer the conversation goes?
- The whole conversation, including every file it read and every command output, sits in the model's context window, and performance degrades as it fills. Start a fresh session between unrelated tasks, and if you have corrected the same mistake twice, restart with a better first prompt.