Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Duplicating code instead of reusing it card 4 of 6

The duplicate in the diff

builds on: What the agent cannot see
**Tell:** a module-local regex and helper for email, which the app already handles elsewhere. `$ grep -rn Email src/lib` finds `validateEmail`, which also trims and lowercases the address and returns the normalised form. **Later cost:** signup stores `Bob@X.com` as typed. Login looks up `bob@x.com` and never finds the account. Rules added to `validateEmail` later also skip signup. **Fix:** call `validateEmail` and store what it returns.
// TypeScript
--- a/src/signup/handler.ts
+++ b/src/signup/handler.ts
+const EMAIL_RE = /^\S+@\S+\.\S+$/;
+
+function isValidEmail(s: string) {
+  return EMAIL_RE.test(s);
+}
+
 export async function signup(req: Req) {
-  // TODO: validate email
+  if (!isValidEmail(req.body.email)) {
+    return badRequest("invalid email");
+  }
   await createUser(req.body);
Terms on this card
the diff
The change under review in unified diff format: '-' lines removed, '+' lines added, unprefixed lines unchanged context.
later cost
The concrete damage a shortcut does after merge, such as a hidden bug, silent data corruption or extra maintenance.
helper
A small function that does one common job, such as formatting or checking a value, so other code can call it instead of repeating it.
regex
Regular expression: a pattern language for matching text, such as `^\S+@\S+$` for 'non-whitespace characters, @, non-whitespace characters'.
grep -rn
Shell command that searches all files under a folder (-r) for a text pattern and prints matching lines with line numbers (-n).
Learn this step by step on Bytewise
Lesson goal: Spot a new helper, validator or client that duplicates one already in the codebase that the agent never opened. Explain the later cost when the copies diverge, and when merging the copies would instead create the wrong abstraction. · the whole lesson