
Stop Writing Code. Start Managing the Machine That Does.
Why AI coding agents keep going off the rails — and what your team can do about it
Stop Writing Code. Start Managing the Machine That Does.
Why AI coding agents keep going off the rails — and what your team can do about it
If you've spent any real time working with AI coding agents, you know the pattern.
You hand the agent a well-scoped task. Implement this service method. Fix this bug. Wire up this endpoint. The codebase has clear conventions. There's a repository pattern abstracting the ORM. Dependency injection is handled through a factory. The architecture is deliberate, built up over months or years by people who understood the tradeoffs.
The agent ignores all of it.
Instead of using the repository pattern, it writes raw SQL statements. Instead of going through the dependency injection framework, it instantiates services directly. Instead of following the established project structure, it forges a new path — new folders, new naming conventions, a parallel architecture that exists nowhere else in the codebase.
Or worse: you ask it to build out a feature and it delivers something that looks complete. The endpoints are there. The types are clean. The tests pass. You stand it up for QA and discover that nothing is hitting the actual database. The agent put in mock implementations — in-memory data sources with hardcoded responses — because somewhere in its training data that's what "implement" meant in a tutorial context. The entire feature is a facade.
Or this one: the UI is done. Pixel-perfect to the designer's spec. Responsive, accessible, polished. Then you ask the agent to fix a minor bug — a tooltip that's misaligned, a button that doesn't disable correctly — and it rebuilds the entire component layout. What was a one-line CSS fix becomes a structural rewrite that breaks the design system integration, changes the component hierarchy, and introduces new visual regressions across three breakpoints.
These aren't hypothetical scenarios. They're Tuesday.
The agent has the same problems you do — plus new ones
Atlassian's 2025 State of Developer Experience survey — 3,500 developers across six countries — found that the top sources of wasted time for developers are finding information, adapting to new technology, and context switching between tools. Half of respondents reported losing ten or more hours per week to these non-coding inefficiencies.
Here's the thing: AI coding agents suffer from exactly the same problems, and they're worse at dealing with them.
A developer who's new to a codebase can ask a colleague where the database abstraction lives. They can search for usage patterns. They can read the architecture decision records. They build up a mental model over days and weeks, and once they have it, they don't forget it.
An agent starts fresh every session. It doesn't know you have a repository pattern. It doesn't know the factory exists. It doesn't know that the UserService three directories over already handles the exact scenario it's about to reimplement from scratch. It has no institutional memory, no understanding of why things are the way they are, no sense of the conventions that took your team months to establish.
It gets worse. The agent isn't just uninformed about your codebase — it's often working from outdated knowledge of the tools themselves. It writes code targeting an API surface that was deprecated two major versions ago. It uses patterns from library docs that no longer exist. The code doesn't compile, or it compiles and introduces subtle bugs because there's a better, safer path in the current version that the agent has never seen.
So you end up with a compounding problem. The agent doesn't know your architecture. It doesn't know your conventions. And its knowledge of the underlying libraries may be out of date. Left to its own devices, it will confidently produce code that looks professional, passes a surface-level review, and is architecturally wrong in ways that don't become obvious until integration testing — or production.
This is the real friction. Not "I can't find the documentation." It's "the agent found some documentation, ignored my architecture, and now I'm spending two hours unwinding a change that was supposed to take fifteen minutes."
Why most teams plateau at "fancy autocomplete"
Dan Shapiro, CEO of Glowforge, published a framework in January 2026 that maps AI-assisted programming onto the same maturity model the NHTSA uses for autonomous vehicles. His observation, after watching dozens of companies try to put AI to work: most developers plateau at Level 2 out of five.
Level 2 is the pair programming sweet spot. You're in flow state, the AI is completing your thoughts, you're shipping faster than ever. It feels like the ceiling.
It's not. It's a local maximum.
The leap to Level 3 requires something uncomfortable: you stop writing code and start reviewing it. The agent handles implementation; you become the quality gate. Shapiro describes this as the "Waymo with a safety driver" phase — your life becomes diffs. For a lot of developers, this feels like a demotion. The creative satisfaction of writing code gives way to the tedium of managing someone else's output. Many people retreat back to Level 2 because Level 3 feels worse.
But here's the thing — Level 3 feels bad largely because the agent keeps going off the rails in exactly the ways I described above. You review a diff and the agent used raw SQL instead of the repository pattern. You review another and it restructured a component you didn't ask it to touch. You review a third and the mock data is still there. Each review becomes a correction session rather than a validation step.
No wonder people give up. If every review surfaces architectural drift, you're not reviewing — you're rewriting. And rewriting the agent's output is slower than having written it yourself.
The path to Level 4 — where you operate as a product manager, define specs, and step away while the agent implements — requires that Level 3 actually works. That means the agent needs to stay on the rails. It needs to know your patterns, respect your structure, use your libraries correctly, and not blow up working code when making small changes.
You don't get there through willpower. You get there through infrastructure.
Guardrails, not handcuffs
This is the core problem that CC-Toolkit exists to solve.
The premise is straightforward: the reason agents go off the rails is that they lack the contextual knowledge a human developer accumulates naturally. The fix isn't to supervise every keystroke — that defeats the purpose of having an agent. The fix is to encode your team's knowledge into the tooling itself, so the agent receives the context it needs automatically, produces output that conforms to your standards by default, and gets checked by automated gates before anything lands.
The building blocks are simpler than they sound.
Rules: teaching the agent your architecture
The most direct solution to "the agent ignores my repository pattern" is to tell it about the repository pattern. Not once per session in a chat message that gets forgotten, but in persistent, version-controlled rule files that load automatically based on what the agent is working on.
When the agent touches files under src/api/, it gets the API rules — your endpoint naming conventions, your middleware patterns, your database query approach. When it touches component files, it gets the frontend rules — your state management conventions, your component structure, your design system integration. When it touches test files, it gets the testing conventions.
Path-scoped rules mean the agent gets precisely the context that's relevant to the code at hand. It learns that you have a UserRepository before it decides to write raw SQL. It learns that the UI follows a specific component hierarchy before it restructures a layout for a one-line bug fix. It learns that you use a dependency injection factory before it starts instantiating services directly.
The maintenance pattern matters: add rules reactively. When the agent makes the same mistake twice, that's a rule. When a code review surfaces the same drift pattern again, that's a rule. Don't preemptively write rules for problems that haven't occurred — that wastes context. Keep the rules in version control so the whole team shares the same guardrails.
CLAUDE.md: the agent's institutional memory
Beyond path-specific rules, every project needs a core set of non-negotiable standards that apply everywhere. Your build commands. Your test runner. Your known gotchas. The patterns the agent must follow regardless of which files it's touching.
The key is to keep this minimal but powerful. Every token in this file is consumed before the agent processes its first instruction. A bloated configuration wastes context on things that may never be relevant in a given session. A focused one gives the agent exactly the guardrails it needs.
In practice: start with your build/test/lint commands and two or three non-negotiable rules. Add to it only when you observe a repeated problem. "Don't put mock implementations in production code paths" is the kind of rule that earns its place after you've been burned. "Always use the repository pattern for data access" prevents an entire category of architectural drift.
Hooks: automated quality gates
Some problems shouldn't wait for code review to surface. When the agent writes a file, it should be auto-formatted to match your project's style — no approval dialog, no manual step, no CI failure over a missing semicolon. When the agent finishes an implementation, the test suite should run automatically. When a session starts, the agent should already know the state of the repository — what's changed, what's in progress, what branch you're on.
Hooks handle this by triggering scripts on specific agent events. A PostToolUse hook runs your formatter on every file write. A Stop hook runs tests when the agent completes its work. A SessionStart hook injects git context so the agent doesn't start from zero. A PermissionRequest hook auto-approves commands you've already decided are safe — npm test doesn't need manual approval for the four hundredth time.
The goal isn't to remove humans from the loop. It's to remove interruptions from the loop. Each automated check is one less context switch. Each auto-approved safe command is one less flow state disruption. The developer stays focused on the actual problem while the machinery handles the mechanics.
Commands: consistent processes, not ad hoc prompting
When planning, scaffolding, PR creation, and issue resolution are packaged as slash commands, two things happen. First, the quality becomes consistent — every developer on the team follows the same process, produces the same output format, meets the same standard. Second, the institutional knowledge embedded in those commands protects against the agent's tendency to improvise.
A /spec command doesn't just plan faster — it forces the kind of thorough analysis that catches misinterpreted requirements before they become bugs. A /scaffold command doesn't just create files faster — it creates them in the right places, with the right patterns, following the conventions the agent would otherwise ignore. A /fix-issue command doesn't just patch bugs faster — it constrains the agent to a minimal, focused change instead of the structural rewrites it gravitates toward when left unconstrained.
The command becomes the guardrail. It says "follow this process" instead of hoping the agent figures out the right process on its own.
The security dimension
There's another category of agent drift that deserves its own attention.
Apiiro published research in September 2025, based on analysis of code across Fortune 50 enterprises, that quantified what many developers already suspected. AI-assisted developers were producing three to four times more commits than their peers. Surface-level quality improved — syntax errors dropped 76%, logic bugs fell over 60%. But deeper architectural risks surged. Privilege escalation paths increased 322%. Architectural design flaws rose 153%.
The pattern should sound familiar: the agent is good at the surface and bad at the structure. It writes syntactically correct code that introduces security vulnerabilities at the architectural level — broken auth flows, missing authorization checks, hardcoded credentials in generated configuration files. These are exactly the kinds of issues that code reviewers struggle to spot, especially when the volume of AI-generated code outpaces the review capacity.
This is why CC-Toolkit includes security scanning as a first-class feature. A stop-gate hook runs Gitleaks and Semgrep automatically. A /security-scan command orchestrates deeper analysis with Trivy, Knip, and Madge. The tools are open source and free. They skip gracefully when not installed. But when they're present, they catch the hardcoded API key in the AI-generated config file, the dependency with a known CVE, the auth handler that checks login status but not permission level.
The heavier your reliance on AI for code generation, the more essential automated security scanning becomes. These safeguards need to execute every time, not just when someone remembers.
Lightweight beats monolithic
Earlier in my exploration of this space, I built a much larger system — a plugin suite with over fifty agents, extensive configuration, and broad orchestration capabilities. It worked, but the overhead of the system itself became a new source of friction. Every session loaded agents that weren't relevant. The configuration was complex enough that onboarding required its own documentation. The system that was supposed to reduce friction was generating its own kind.
CC-Toolkit goes the other direction. Two agents instead of fifty — an architect (planning only, read-only tools) and an implementer (code execution, constrained permissions). Path-scoped rules instead of a global configuration monolith. A scaffolder that detects your stack and generates a tailored setup, then gets out of the way. Seven slash commands covering the workflows that actually save time, based on real usage rather than speculative brainstorming.
The scaffolder asks your stack — Next.js, Python, Rust, Go, plain Node — and generates only the hooks and rules that make sense for what it finds. A Python project doesn't get React rules. A Node project doesn't get Go formatting hooks. Start lean, add on demand.
If something hasn't been used in two weeks, retire it. Commands and hooks should emerge from real friction, not from a planning session.
The compound effect
No individual piece of this is revolutionary. Auto-formatting has existed for years. Slash commands are packaged prompts. Rules are scoped documentation. Hooks are event-driven scripts.
The value is in how they compound — and specifically, how they compound to solve the problem of agents going off the rails.
When the agent knows your repository pattern exists, it stops writing raw SQL. When it knows the component hierarchy, it stops restructuring layouts for one-line fixes. When security scanning runs automatically, it stops shipping hardcoded credentials. When tests run on every completion, mock implementations get caught before QA. When formatting is automatic, you stop having style conversations in reviews.
Each piece prevents one category of drift. Together, they create the infrastructure that makes it possible to actually operate at the higher levels of Shapiro's framework — where you're defining what needs to be built and the agent handles how, within guardrails that keep it on the rails.
The teams that figure this out first aren't just going to be faster. They're going to be operating in a fundamentally different mode than teams still fighting the same agent drift problems every session. The gap between "fancy autocomplete" and "autonomous implementation" isn't incremental. It's structural. And the tooling you build around the agent is what determines which side of that gap you end up on.
Getting started
CC-Toolkit is open source and designed to get out of your way:
# Install
curl -fsSL https://raw.githubusercontent.com/squirrelsoft-dev/cc-toolkit/main/install.sh | bash
# Scaffold any project
cd your-project
ccinit
Start with the hooks. Just the hooks. Auto-format on write, auto-run tests on stop. Sit with that for a few days. You'll notice the difference. Then add a rule the next time the agent ignores a convention. Then add a command the next time you find yourself typing the same prompt for the third time.
Each addition is a guardrail you'll never have to enforce manually again.
github.com/squirrelsoft-dev/cc-toolkit
Sources referenced in this post:
- Atlassian, "State of Developer Experience 2025" — survey of 3,500 developers across six countries. atlassian.com
- Apiiro, "4x Velocity, 10x Vulnerabilities: AI Coding Assistants Are Shipping More Risks" — analysis of Fortune 50 enterprise codebases, September 2025. apiiro.com
- Dan Shapiro, "The Five Levels: from Spicy Autocomplete to the Dark Factory" — January 2026. danshapiro.com