Agentic AI Coding: Best Practice Patterns for Speed with Quality
Source: CodeScene Blog Author: Adam Tornhill (CTO, CodeScene — 40 years coding, 30 professionally) Key insight: 100% of production code at CodeScene is now written and maintained by AI agents. Result: 2–3× speedup.
Speed amplifies both good design and bad decisions. Code health, automated safeguards, and short feedback loops become the real enablers of progress.
Core Problem
Agents lack reliable understanding of maintainability and change risk. They:
- Operate in “self-harm mode” — write code they can’t maintain later
- Happily modify spaghetti code with low success probability
- Cannot verify if refactoring is objectively better
Root cause: AI lacks an objective way of measuring “good”.
6 Operational Patterns
1. Pull Risk Forward: Assess AI Readiness
Problem: Low Code Health → worse AI performance. Agents get confused by the same patterns as humans.
Solution: Aim for Code Health ≥ 9.5 (ideally 10.0). Healthy code is AI-friendly. Unhealthy code needs refactoring before agentic work.
| Code Health Score | AI Performance |
|---|---|
| 10.0 (perfect) | Optimal |
| 9.5+ | Good |
| < 9.5 | Degraded — higher token burn, more errors |
2. Safeguard Generated Code
Problem: AI code mirrors its training data — which includes a lot of low-quality code. Small quality issues accumulate quickly at AI speed.
Solution: Three levels of automated safeguarding via Code Health MCP:
- Continuous review —
code_health_reviewas each snippet is generated - Pre-commit safeguard —
pre_commit_code_health_safeguardon staged files before each commit - PR pre-flight —
analyze_change_seton full branch vs base ref before opening PR
These tools enforce a refactoring loop on any quality issues.
3. Refactor to Expand AI-Ready Surface
Problem: Large, complex legacy functions inflate error rates and token spend.
Solution: Objective feedback changes the dynamic:
- Code Health score gives agents an explicit, measurable goal
- Detailed review offers concrete direction via maintainability issues
- Workflow: review → plan → refactor → re-measure
Breaking large functions into smaller, cohesive units increases modularity and the safe operating surface for agents.
4. Encode Principles via AGENTS.md
Problem: MCP exposes powerful individual tools but not the workflow connecting them. Agents use tools opportunistically or not at all.
Solution: AGENTS.md documents sequencing and decision logic so agents combine MCP tools into a coherent workflow:
- Pull risk forward with
code_health_review - Safeguard changes via pre-commit and PR pre-flight
- Enter refactoring loops when health regresses
Abstract engineering principles → executable guidance for agents.
5. Code Coverage as a Behavioral Guardrail
Problem: Healthy structure ≠ correct behavior. Agents may delete failing tests.
Solution: Use coverage as a regression signal, not a vanity metric:
- Hard coverage gates on PRs make behavioral erosion visible
- Agentic speed makes this non-negotiable
- Works alongside Code Health safeguards
6. Automate Checks End to End
Problem: Manual verification becomes the bottleneck at agentic speed.
Solution:
- Unit tests — foundation for fast iteration (CodeScene: ~99% coverage)
- End-to-end tests — validate the packaged product in realistic scenarios
- Build distributable product, create/modify Git repos, inject code smells, verify detection
“This level of automation was always desirable. With AI speed, it becomes non-negotiable.”
Key Takeaway
The real shift isn’t AI — it’s engineering discipline. The patterns form a feedback system that keeps agentic speed aligned with engineering quality. Code Health + MCP safeguards + AGENTS.md form the infrastructure layer:
- Code Health → objective signals about maintainability & risk
- MCP → exposes signals as actionable tools
- AGENTS.md → encodes how tools combine into predictable workflows
Get that foundation right, and agents become a reliable accelerator for meaningful software development.