tolgacelik.net
All posts
·3 min read

Working With AI While Writing Code: What Actually Matters

I've been using Cursor and Claude Code in production for a year. As important as the speed gains are the rules I keep — hallucination, context hygiene, security, and production stability.

aicursorclaudecode-reviewsecurity

Writing code with AI was a novelty a few months ago. Now it's the standard practice. But from what I've seen, a lot of people pass the "how do I do this?" stage only to get stuck on "how do I avoid doing it badly?" This post walks through what I've run into over the past year and the rules I've set for myself — not theory, desk notes.

1. Treat AI as a very confident junior

This is the most important mental model. Don't picture a senior approving the output — picture a junior sitting next to you, offering suggestions. You listen, you evaluate, you decide.

A junior is brave; a junior might suggest "just flush the entire Redis key set and rebuild it." The same is true of AI: confidence exceeds knowledge. You are the adult in the room.

2. Hallucinations are real and catchable

AI can invent an API function that doesn't exist and tell you to use it. That's not a small mistake — it crashes in production.

Anti-patterns:

  • Using an API the AI suggested without checking the docs
  • Merging without tests
  • Calling it done because it ran once locally

If you're avoiding those three, hallucinations usually don't bite you. Your process becomes an implicit "AI verifier."

3. Context window = AI's memory

How well the AI understands your codebase is directly tied to the context you provide. For a bigger refactor:

  • Include the target file and the files that depend on it
  • Show your conventions once (e.g. a sample of how logger is used in this project)
  • Don't dump unrelated files — they pollute focus

Clean context is 50% of AI productivity.

4. Don't just accept code — ask why

When code comes out, make it a habit to answer three questions:

  1. Why was this approach chosen?
  2. What alternative was there?
  3. If this crashed in production, where's the most likely spot?

The questions are for you; you just route them through the AI. You get better code, and you end up practicing system thinking by reflex.

5. Be more cautious about security

AI is notoriously lax about SQL injection, XSS, misconfigured CORS, and friends. Security bugs don't fail loudly — they appear to work and then they bite.

My rule: any AI-written code that touches user input gets an extra careful read. Specifically:

  • SQL queries → parameterized?
  • API endpoints → auth middleware wired in?
  • File uploads → size + mime type checks?
  • Env var reading → what's the default fallback if missing?

6. Ask the AI to code-review its own code

Nice trick: ask the AI to critique its own output. 80% of the time it dismisses everything as fine. But 20% of the time it flags 2–3 real issues. It becomes a surprisingly honest mirror when operating in the reviewer persona.

7. Pin your repeated prompts

Cursor has a rules file; Claude Code has CLAUDE.md. Use them. Instead of repeating "use logger, wrap errors, add error boundaries, snake_case fields" on every file, write it once.

8. Move AI away as you approach production

AI is excellent at prototype and MVP. Where it struggles is the last-mile work — performance optimization, race conditions, genuine edge cases. Human judgment is still clearly ahead there. In that zone, treat AI as a suggestion engine. You make the calls.

9. Don't atrophy your own skill

Important one. If you spend three months purely hitting "accept" on AI output, at the end of those three months you've regressed as an engineer. When you're learning a new concept, block out a couple of hours a week to work without AI. Keep the muscle working.

Takeaway

Writing code with AI is doable — it's happening. Making it safe takes some discipline. These nine habits are what I learned this past year. You don't need to adopt all of them at once; pick three and practice, and your code quality will measurably change.

In the end, the tool is a tool. You're the one aiming it. That hasn't shifted — the tool just got more capable.

ShareLinkedInX
Get the next one in your inbox

Long-form notes on distributed systems, production stability, AI-assisted shipping. No spam, easy to unsubscribe.

Email only. Stored on this server. Never sold or shared.

Comments

No comments yet. Be the first.

Leave a comment

Never shown publicly. Only used if I need to reply.