AI Coding Basics

Vibe Coding Best Practices For Cleaner AI-assisted Code

Vibe Coding Best Practices For Cleaner AI-assisted Code

Google’s 2025 DORA report surveyed nearly 5,000 technology professionals and put AI adoption among software development professionals at 90%, a 14% increase from the previous year.

Andrej Karpathy coined vibe coding in February 2025 to describe accepting AI output without reading it. With nine in ten developers now using AI, that habit has moved inside teams that ship to production.

Vibe coding best practices are the habits that keep AI-generated code readable and reversible, and secure enough to ship. They get judged on one question. Does a habit make code you didn’t write line by line cheaper to verify? If it does, keep it. If it only adds ceremony, drop it.

What Counts as Vibe Coding, and Where Best Practices Begin

YouTube player

Karpathy’s February 2025 description was specific. You prompt, you accept what comes back, you give in to the vibes, and you stop thinking about the code at all.

Collins Dictionary named it Word of the Year for 2025, but its definition is much wider: the use of AI, prompted by natural language, to assist with writing code. By that standard, anyone who has ever asked a chatbot for a function is vibe coding.

The original meaning of vibe coding is the narrow one. Simon Willison describes it as a specific approach where you don’t read the AI’s code before running it. He pushed back on the broad usage on March 19, 2025, arguing it dilutes the term, and for production work he holds himself to a rule. Nothing gets committed unless he could explain exactly what it does to someone else.

In practice the difference comes down to what gets accepted. With vibe coding proper, output goes in because the app runs, and the generated code rarely gets read. Reviewed AI-assisted programming starts from the opposite end. The diff gets read and the tests pass first, every committed line can be explained, and the author owns the result no matter who typed it. That second mode suits anything that will be maintained.

Closing the gap between vibe coding and traditional coding is mostly a matter of putting the reading back in. Every practice below does that at a different point.

Even Willison admits the line is soft. On May 6, 2026 he wrote that the two had started to blur for him, having assumed until then that vibe coding meant not looking at the code at all.

Developers themselves are wary. Stack Overflow’s 2025 Developer Survey found that 46% distrust the accuracy of AI output, up from 31% a year earlier, and nearly 72% said vibe coding is not part of their professional work.

Most of the professionals in that survey prompt, read, test and commit. That’s the workflow the rest of this article builds.

Which AI Coding Tool Type Fits Which Project?

YouTube player

The deciding factor is how much of the code you get to see. Editor-based assistants and terminal agents put diffs in front of you, while prompt-to-app builders show a preview first.

Tool typeExamplesCode visibilityBest fit
Editor-based assistantsCursor, Windsurf, GitHub CopilotInline diffs in the editorExisting repositories
Terminal agentsClaude Code, OpenAI CodexDiffs and command outputMulti-file tasks
Prompt-to-app buildersReplit, Lovable, Bolt.new, v0Preview first, code secondPrototypes, UI drafts

Vibe coding in Cursor keeps each change as a diff inside the editor, so review is part of the workflow instead of an extra step. For an existing repository, that’s where I’d start.

Terminal agents work differently. They edit many files per task and run commands on their own, which makes vibe coding with Claude fast on multi-file work and just as fast at wrecking a repo when the Git state is dirty.

Builders stop working the moment a project needs code review, tests in CI or a second developer. Export the code to a repository before that point, not after.

For anything you plan to maintain, choose a tool that shows diffs and works inside Git. Builders are fine for a prototype you’ll throw away.

How to Write Prompts That Return Code You Can Keep

YouTube player

Scope each prompt to one task and put the acceptance rules in the prompt text. A vague request returns code you can’t judge, and a scoped one returns a diff you can review in a few minutes.

“Add login to the app” leaves every decision to the model. Broken into separate instructions, the same request looks like this:

  • Add email and password login to the Express app in src/auth
  • Hash passwords with bcrypt
  • Return 401 on bad credentials
  • Add tests for the failure path
  • Do not change the user model

The status code and the failure-path test double as criteria for accepting the output. If the result misses one, you know before reading a single line.

TechRepublic’s May 2026 vibe coding cheat sheet says to name the languages and frameworks and to include example inputs and outputs.

Context decays. Each Claude Code session begins with a fresh context window, so anything missing from the prompt or a rules file is gone.

Long chats cause the opposite problem. AWS Labs’ MCP guide for vibe coding recommends regularly reviewing and cleaning up conversation history.

Start a new session when the task changes or the agent keeps repeating a mistake. A chat that has passed a dozen rounds of fixes is also done.

One more check before running anything. Confirm that every import and API call exists in the library’s official docs, because a prompt can’t fix a package the model invented.

What Goes in a Rules File Like AGENTS.md or CLAUDE.md

Instead of retyping the stack, commands, conventions and limits in every prompt, you write them once in a Markdown file in the repository, and the AI reads it as standing instructions.

The file name depends on the tool. AGENTS.md is an open format used by over 60,000 open-source projects and read by tools such as Codex, Cursor, GitHub Copilot and Gemini CLI. Claude Code reads CLAUDE.md, not AGENTS.md, per its documentation as of November 2026. Cursor project rules live in .cursor/rules as .mdc files, which are version-controlled and can be scoped by path pattern. The older .cursorrules still works but is deprecated.

AGENTS.md emerged in August 2025 from a collaboration between OpenAI, Amp, Google, Cursor and Factory. In December 2025 it moved to the Agentic AI Foundation under the Linux Foundation, alongside the Model Context Protocol.

That split has a practical effect. A repository used with several tools needs one source of truth, and Claude Code’s import support for CLAUDE.md lets the second file point at the first. Cursor reads CLAUDE.md the same way it reads AGENTS.md, so it needs no extra file.

Order matters inside the file, because the agent needs some things sooner than others.

  • Build, test and lint commands
  • Stack and versions
  • A short layout of the project’s codebase
  • Naming and style conventions
  • Patterns the agent must not use
  • Search for an existing helper before writing a new one

The Model Context Protocol (MCP) is a separate layer. It connects an agent to external tools and docs, so grant read-only access first and widen it only when a task needs it.

Don’t assume the agent obeys all of this. Claude Code treats CLAUDE.md as context rather than enforced configuration, so a rule the agent ignores still needs a linter or a CI check behind it.

The Claude Code docs say specific, concise instructions are followed more consistently. Cursor’s help center suggests each rule file cover a single concern. Short files win.

How to Use Git as the Safety Net for AI Changes

Commit before every prompt and any bad generation can be undone in one command. The loop below keeps each AI change small enough to review.

  1. Commit the current working state with a clear message.
  2. Create a branch for the feature or fix.
  3. Send one scoped prompt.
  4. Read the diff, not the chat summary of what changed.
  5. Run the tests and linters.
  6. Commit if everything passes. If not, revert and rewrite the prompt.

Step four is the one people skip, and it’s tempting to see why. The chat summary reads fine. But the agent’s summary describes what it meant to do, while the diff shows what it did.

When a generation goes wrong, revert the bad commit instead of prompting your way out. Chasing a broken state with follow-up prompts piles new edits on top of the original mistake.

Large, unreviewed commits are where this falls apart. Once ten prompts share one commit, nobody can say which one broke the build, and “accept all” on a multi-file edit is usually where that starts.

How Much Review Does AI-Generated Code Need?

YouTube player

Match review depth to what the code can break. A throwaway script only needs a run-through. Anything touching money or personal data needs a second human, and internal tools sit in between, with tests and a full read of the diff.

Automated checks that run on every change

Automation catches the cheap mistakes so human attention goes to logic and design. Start with a linter pass, then tests, all triggered by a pull request through GitHub Actions.

ESLint flags unused variables, dead code and unsafe patterns in generated files, and Prettier strips style noise from the diff so you’re reading real changes. Jest checks behavior function by function. Playwright drives the running app through login and other critical paths.

SonarQube Server’s 2026.1 documentation recommends a dedicated quality gate for AI code, named Sonar way for AI Code. The same documentation lists seven conditions for it, including no new issues on new code and all new security hotspots reviewed.

Tests written by the same agent that wrote the code can encode the same wrong assumption. Read the assertions yourself, or write the failing test first.

Human review depth by risk tier

InfoWorld’s September 2026 analysis warns that the reviews, security scans and testing practices built for developer-written code may not support the volume and new risks of AI-generated code.

TierExampleMinimum review
ThrowawayOne-off script, demoRun it, skim the diff, discard it
InternalAdmin dashboard, team toolFull diff read, tests on core paths, lint and scan in CI
SensitivePayments, personal data, authLine-by-line review by a second person, security scan, access-control tests

Teams that already run a code review process should send AI-authored pull requests through it unchanged. The reviewer asks two questions in order. Does it do what the prompt asked and nothing else, and is the structure worth keeping?

Veracode, GitClear and METR each measure something different. They still land in the same place. Generating code is cheap, and checking it is the expensive part.

Why Does AI-Generated Code Fail Security Checks?

YouTube player

Developers don’t need to specify security constraints to get working code, which leaves secure coding decisions to the model, according to Veracode. Its 2025 GenAI Code Security Report, published July 30, 2025, analyzed 80 curated coding tasks across more than 100 LLMs.

The headline number is that 45% of code samples failed security tests and introduced OWASP Top 10 vulnerabilities. Java did worst, failing more than 70% of the time. And cross-site scripting (CWE-80) went undefended in 86% of relevant samples.

The tasks asked models to auto-complete a block of code in a secure or insecure way. They were not full vibe-coded applications, so the numbers show function-level behavior, not how a whole app fares.

The same failure class shows up in shipped products. The NVD entry for CVE-2025-48757 records an insufficient database Row-Level Security policy in Lovable, through 2025-04-15, that let unauthenticated attackers read or write arbitrary database tables of generated sites.

Broken Access Control still leads the OWASP Top 10 for 2025. The list, first unveiled as a release candidate on November 6, 2025, also added Software Supply Chain Failures as A03.

The pipeline has to catch what the prompt misses, and a few tools do most of that work.

  • Name the auth and access rules in the task itself, along with how input gets validated, because the model won’t add them on its own
  • Semgrep covers SAST, secrets detection and dependency scanning, and its Guardian product, announced June 23, 2026, scans AI-generated code as it is written inside Claude Code, Cursor and Windsurf
  • Dependabot sends alerts when a repository uses a vulnerable dependency and opens pull requests to fix it, though its separate malware alerts currently cover only npm packages (Snyk covers the same ground)
  • GitHub push protection blocks a push containing a detected secret before it reaches the repository

Hardcoded secrets are the most preventable failure on that list. Put .env files in a .gitignore entry before the first commit, because Git history keeps what you delete.

If a key did land in a commit, treat it as compromised and rotate it first. Then follow the steps to keep API keys out of GitHub repositories from here on.

How to Stop Duplication and Churn Before They Become Technical Debt

GitClear’s Maintainability Gap report (June 2026) found block duplication up 81% since 2023, across 623 million analyzed changes. Moved code, the signature of refactoring, fell sharply over the same period.

The study tracks duplication as five or more consecutive repeated meaningful lines. Churn means lines reverted or edited within two weeks of landing.

GitKraken’s Q4 2025 cohort analysis points the same direction. Heavy AI users wrote more code and rewrote it quickly, at a much higher churn rate than other developers.

“Every time you want something, AI creates a new package for it,” says Bill Harding, CEO of GitClear. Each copy and each extra package is another place a future fix has to land, which is how technical debt compounds in AI-heavy repositories.

A few habits keep it in check.

  • Add a reuse rule to the rules file: search for an existing helper before writing a new one
  • Reject packages the project does not need
  • Fail the SonarQube quality gate when duplication on new code climbs
  • Schedule refactoring passes after each feature merges, not “later”

GitClear reads change patterns across commits, not defect counts, so a rising duplication rate says the maintenance bill is growing. It says nothing about whether the app is broken today.

The New Stack’s September 2026 piece on the data makes a related point. Counting lines of code, pull requests or features delivered shows no clear relationship to value.

When Vibe Coding Does Not Apply

YouTube player

Vibe coding does not apply where a failure is expensive, regulated or hard to undo. That covers payments, authentication, personal data, audited systems and any codebase you can’t explain.

A missed access rule in payments or authentication is a breach, not a bug. Regulated or audited systems need a person who can say what every change does and why. And in a large unfamiliar codebase the agent can’t follow conventions nobody wrote down, while you can’t catch what you don’t recognize.

Software compliance rules ask who approved a change and on what basis. An unread diff can’t answer that.

Code headed for a production environment with customer data is a conditional yes. It passes only after the sensitive review tier, the security scans and the Git loop are all in place.

The evidence on speed points two ways. In July 2025, METR had 16 developers complete 246 tasks in mature projects they had worked on for an average of 5 years, and with AI tools allowed they took 19% longer.

GitClear and GitKraken’s Q4 2025 report compared each developer against their own output a year earlier. It puts AI’s real contribution at roughly 25% year-over-year, across 2,172 developer-weeks.

Part of the gap is who was measured (maintainers of their own repositories vs a broad developer base) and when (February to June 2025 tools vs late 2025). The rest is what was measured, task time vs commit activity. Neither study contradicts the other so much as measures something different.

METR’s February 24, 2026 update said selection effects in its newer study make the central estimate a likely bad proxy for real productivity impact. The group is changing the study design as a result.

METR also wrote that developers are likely more sped up by AI tools in early 2026 than its early-2025 estimates showed. The 19% figure is a dated measurement of specific tools, not a standing verdict.

Neither dataset tested hands-off vibe coding, so neither justifies it. For an experienced developer in a mature repository, scoped assistance, meaning one task and one diff per commit, is the safer default.

Vibe coding is a fine way to explore. It stops being fine when someone else depends on the result.

Vibe Coding Best Practices FAQ

Is agentic coding the same as vibe coding?

No. An agent that plans a task, edits several files and runs commands or tests in a loop is agentic coding, and that says nothing about whether you review the result. Vibe coding is the not-reviewing part. You can run an agent and still read every diff.

Can beginners vibe code safely?

Yes, for throwaway scripts, personal tools and prototypes with no real user data. The risk starts when a beginner ships something that handles logins, payments or personal information without anyone who can review the code checking it.

Do I need to learn to code before I vibe code?

Not to start, but you need enough to read a diff and tell what changed. Without that, you can’t judge what the model produced.

Learn variables, functions, HTTP requests and how your database handles access. That covers most of what a review has to catch.

Will vibe coding replace developers?

Unlikely in the near term. It moves effort from typing code to specifying, reviewing and testing it, and those jobs still need someone who understands the system. Teams get faster drafts, but accountability for what ships stays with a person.

How do I fix a vibe-coded project that is already messy?

Freeze new features first. Commit the current state, then add tests around the behavior you must keep.

Run a security scan early, before the refactoring starts. After that, write a rules file, remove duplicated helpers and unused packages, and refactor one module per branch.

Which Vibe Coding Practices to Adopt First

YouTube player

In a project that already holds unreviewed AI-generated code, the first vibe coding practices to adopt are commits you can revert and automated checks on every change. Commit the current state and branch per task, then add linting, tests and secret scanning to CI. The written rules file and the review tiers come after that.

The order follows the cost of failure. Reversibility limits damage today and checks find defects already in the repository. Rules only reduce new ones once those two exist.

Merges get slower. Every change waits for a pipeline and a reviewer, and that delay is the price of code someone can explain.

Verified on November 22, 2026, the sequence loosens when independent measurements of hands-off vibe coding show defect rates matching reviewed code.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.