How I Stopped AI Coding Assistants From Drifting — And Saved Millions of Tokens Doing It
If you've been building with AI coding assistants — Claude Code, Cursor, Copilot, Windsurf — you've hit this wall.
You start a new session. The AI doesn't know your architecture. It doesn't know your patterns. It doesn't know the decisions you made three weeks ago when you chose server components over client components, or why you're using Drizzle instead of Prisma.
So it guesses. And it drifts.
Over sessions, your codebase slowly diverges from its own conventions. Files get inconsistent. Patterns split. You spend more time correcting the AI than actually building.
I got tired of it. So I built a structural fix.
The Problem Is Context, Not Capability
The AI isn't bad at coding. It's bad at remembering your specific context across sessions.
Every session is a blank slate. You can paste in context manually — but that burns tokens, takes time, and you'll inevitably forget something. And as your codebase grows, "explain your architecture to the AI" becomes a 10-minute ritual before every session.
There had to be a better way.
The Solution: A Structured Rule Layer
I built AI-Native Boilerplate — a configurable, token-efficient discipline layer for AI coding agents.
The idea is simple: encode your architecture, patterns, and conventions once, in a structured format your AI agent actually reads and follows. Then generate a single context file from that structure, tuned to your exact stack and features.
No more re-explaining. No more drift.
The Architecture
The boilerplate has 6 layers:
Layer 1: Core Rules (always loaded)
The fundamentals that apply to every project:
- Git discipline (commit message format, branch naming, PR conventions)
- Testing requirements (coverage thresholds, test file structure)
- Security baseline (no secrets in code, input validation, auth patterns)
- Architecture invariants (folder structure, import rules, naming conventions)
Layer 2: Stack Rules (loaded by your stack)
Specific rules for your technology choices:
- React, Next.js (App Router vs Pages Router), Vue, Svelte, Remix
- Node.js, Python, Go, Rust
- TypeScript strictness rules
- Database patterns (Drizzle, Prisma, Mongoose)
- Styling (Tailwind, CSS Modules, styled-components)
Layer 3: Feature Rules (loaded by flag)
Only loaded when you enable the feature:
- Stripe payments (webhook handling, idempotency, error handling)
- Authentication (session management, OAuth, JWT patterns)
- SEO (metadata API, structured data, sitemap)
- Internationalization (i18n patterns, locale routing)
- Analytics, real-time, file uploads, email, error tracking
Layer 4: Design System
Typography tokens, color scales, spacing values, component conventions — all encoded. Your AI agent references these instead of inventing its own values.
Layer 5: Custom Rules (your overrides)
Your project-specific rules, loaded last. They always win over base layers. This is where you encode decisions that are specific to your codebase.
Layer 6: Compliance
Pre-written rule packs for GDPR, HIPAA, SOC2, PCI DSS, and EU AI Act. Your AI agent follows them from day one — not after the audit flags something.
The Token Math
This is where it gets interesting.
The generator concatenates all relevant rule files into a single CLAUDE.md. Your agent loads this once at session start.
| Config | Rules Loaded | ~Tokens |
|---|---|---|
| Minimal | 7 | ~2K |
| Web-only | ~20 | ~9K |
| Agent+Web | ~24 | ~10.5K |
| Full-stack | ~30 | ~13K |
Compare this to manually pasting context every session. At 10 sessions a day, across a team of 5, the savings compound fast. Teams report saving millions of tokens per month.
Getting Started
bash
npx ai-native-boilerplate init
Top comments (0)