Disclaimer: These ideas don't represent my current employer's position (Lattice). These are my thoughts from building in the AI trenches for last few years and my attempt to keep up with AI advances these days. Feel free to tear them apart that’s how we learn.

TL;DR

Problem: AI coding fails in enterprise because it lacks context; your patterns, conventions, architectural decisions.

Solution: Train AI on your specific codebase through systematic context engineering:

  • /primer command for deep codebase exploration

  • Semantic memory via Serena integration

  • Learning documents that capture what works in YOUR context

  • Collective intelligence across all teams

Result: AI understands your codebase better than most engineers → complete features in hours, not days.

Bottom Line: Companies doing this now build compounding technical moats while competitors still schedule meetings.


The Crisis That Changed Everything

In May, my startup (hyprbm) got hit with a sophisticated bot attack that threatened to kill our business. Bots were systematically clicking through our affiliate links, generating fake traffic that was burning through our ad spend and destroying our relationships with affiliate networks (you can read more here).

What made this particularly devastating was that our traffic was generally behind authentication; we didn't anticipate bot attacks from authenticated users. The attackers had found a way to create legitimate accounts and automate clicks through our publishers' authenticated flows.

In the affiliate marketing world, partner trust is everything. Once partners lose confidence in your traffic quality, they drop you fast. We had maybe 5 hours before our critical partnerships could be terminated.

While our competitors would have needed days just to scope the technical requirements and schedule engineering meetings, we shipped three defensive features in four hours: a Cloudflare-based bot detection system, real-time behavioral ML classifier, and automated traffic quality monitoring. These weren't patches; they were full features with proper testing, documentation, and monitoring.

The reason? Our AI code assistant (Cursor) understood our codebase, infrastructure patterns, and business logic better than most senior engineers.

This wasn't because we had some magical AI model. We were using the same AI code assistant as everyone else. The difference was maybe we were intentional about treating it, like an engineer over a longer period of time. Both of us were seasoned EMs @ Pinterest. So onboarding new engineers was something we were very familiar with. We got the idea that starter projects with a dash of context + iterative learning could be a way to unlock cumulative gains in coding assistants, rather than just expecting it to learn right out of the box.

We learned A LOT, so I thought I’d share our approach and adapt it using some neat features in Claude Code.

The Enterprise Context Problem

Here's what nobody talks about: AI code assistance works great for "vibe coding"; those greenfield projects where you're building from scratch with zero constraints. This all falls apart in enterprise codebases with millions of lines of code, established patterns, legacy systems, and institutional knowledge that took years to develop.

When you're starting a new project, there's nothing to understand. No coding conventions, no established protocols. The AI can just... code. But in mature enterprise environments, context is everything.

Your AI needs to understand:

  • How your team structures database migrations

  • Which testing patterns you've standardized on

  • What your code review process actually catches

  • How different services communicate

  • Where performance bottlenecks typically hide

  • What architectural decisions were made and why

Engineers absorb this context implicitly over months through code reviews, post-mortems, huddles, and senior engineer guidance. But AI assistants start from scratch every single time.

An Iterative Learning Solution

Here's my core thesis:

AI code assistance can match senior engineer performance on enterprise codebases through systematic context engineering that combines codebase exploration tools with iterative learning cycles. As more projects ship, the learnings and documentation of the code base scale, creating a highly efficient collective intelligence across the entire codebase.

Instead of treating AI as a junior developer who needs constant guidance, you build a system where every engineer contributes to training AI on your specific enterprise context:

See the complete process flow diagram in excalidraw

Phase 1: Deep Context Seeding

This isn't just dumping docs in a folder. The real breakthrough comes from combining multiple context engineering approaches:

The /primer Command: Create a systematic codebase exploration command that goes far beyond traditional documentation. Here's the actual implementation we used (inspired by Cole Medin's context engineering work):

# Prime Context for Claude Code

Use the command `tree` to get an understanding of the project structure.

Read the .claude/agents files

Read the .claude/commands files also.

Start with reading the CLAUDE.md file if it exists to get an understanding of the project.

Read the README.md file to get an understanding of the project.

Use Serena to scan relevant code and use memories to understand code structure & conventions.

Read key files in the src/, docs/, or root directory

Explain back to me:
- Project structure
- Project purpose and goals
- Key files and their purposes
- Any important dependencies
- Any important configuration files

Serena Integration: The command explicitly uses Serena to scan code and build semantic "memories" through the Model Context Protocol (MCP). This creates persistent knowledge that goes beyond what any documentation can capture - understanding of actual code relationships, patterns, and conventions as they exist in practice.

*IMPORTANT* Living Documentation: Your docs folder contains not just current standards, but the learning documents from previous AI implementation attempts. These capture the evolution of implementation approaches that no traditional documentation includes:

  • "When I first tried implementing authentication integration, I planned to use middleware approach X, but discovered it conflicts with our session management. Future auth features should plan for approach Y from the beginning."

  • "Database migration attempt #1 failed because I didn't account for foreign key constraints in the user service. Migration attempt #2 succeeded by checking these dependencies first; this should be standard for all future migrations."

These learnings help the AI restructure its approach from the beginning rather than discovering problems mid-implementation and applying bandaid solutions.

Phase 2: Confidence Building Through Semantic Understanding

Before implementing anything, Claude Code leverages both /primer exploration and Serena's semantic understanding to ask sophisticated questions informed by deep codebase knowledge:

"I see that user authentication flows through three different services. The learning docs mention that Session Service had scaling issues in Q2. Should this feature use the new caching pattern from the billing team's recent work?"

"Serena shows that similar database migrations in the payments module required custom rollback logic. Based on the learning docs from that implementation, should I prepare similar safeguards?"

Phase 3: Learning Extraction & Documentation

After implementation, the reflection process captures not just what worked, but why it worked within your specific context:

  • Technical Learnings: "The new caching layer reduced response times by 200ms, but required custom Redis configuration that isn't documented in our standard patterns."

  • Process Insights: "Feature flagging this change revealed that our A/B testing framework conflicts with user session management in subtle ways."

  • Architectural Discoveries: "This feature exposed that our logging service can't handle the volume from batch operations—future features should implement backpressure."

These learnings get structured and added to the documentation folder, becoming context for future iterations.

Phase 4: Collective Intelligence Scaling

Here's where it gets interesting for enterprises:

Every engineer using this process contributes to organizational intelligence.

Over time, you're not just training individual AI sessions; you're building institutional knowledge that compounds across teams because it has access to learnings from every implementation across every team:

  • The payments team's learning about database transaction patterns informs the user management team's work

  • Frontend performance optimizations discovered in one feature get automatically surfaced for similar implementations

  • Security patterns validated in one service become available as tested approaches for other teams

The Self-Improving Flywheel

As teams implement features across different parts of the codebase, the learning documents accumulate.

Yes, this creates documentation bloat.

After 50-100 feature implementations across different teams, something powerful emerges: the learning documents themselves become a diagnostic tool for systemic improvements.

Pattern Recognition Across Teams: Agents analyze learning documents to identify recurring themes:

  • "The authentication service appears in 23 different learning documents as a performance bottleneck"

  • "Database migration issues are mentioned in 67% of backend feature implementations"

  • "API rate limiting problems surface in every team that integrates with the billing system"

Technical Debt Visibility: Instead of technical debt hiding in individual engineer frustrations, it gets systematically identified through accumulated implementation experience across the entire organization.

The Self-Reinforcing Cycle: Once agents identify systemic issues, they get fed back through the same implementation process:

  1. Agent identifies: "Rate limiting causes problems across 15 different services"

  2. Context engineering: Research all learning documents about rate limiting issues

  3. Implementation: Build comprehensive rate limiting solution

  4. Learning extraction: Document how the systemic fix impacts different services

  5. New context: These learnings become available for future related work

Intelligent PR Planning and Modularity: As the AI accumulates learning documents and understands your codebase patterns better, it gets dramatically better at breaking down complex features into reviewable chunks. The key challenge with AI-generated "full features" is that they often produce thousands of lines of code that are nearly impossible for humans to review effectively. But with accumulated context, the AI learns to plan implementations as a series of smaller, logical PRs that tell a clear story:

  • First PR: Database schema changes with proper migrations

  • Second PR: Core business logic with comprehensive tests

  • Third PR: API endpoints with proper error handling

  • Fourth PR: Frontend integration with existing patterns

  • Fifth PR: Monitoring and observability additions

The Implementation Reality

Set Up the Technical Foundation:

  • Implement the /primer command for systematic codebase exploration

  • Integrate Serena through Model Context Protocol for semantic memory

  • Create structured learning document templates that capture technical insights, process discoveries, and architectural learnings

  • Establish version control for both code and context (treat learning docs with the same rigor as source code)

Alternative Approaches: While our methodology focuses on iterative learning and context accumulation, other tools are tackling systematic context engineering from different angles. Kiro takes a spec-driven approach, emphasizing comprehensive upfront planning where AI generates detailed user stories, technical specifications, and implementation plans before writing any code. As one developer noted:

"Most tools are great at generating code, but Kiro gives structure to the chaos before you write a single line."

This validates that the industry is moving toward systematic context engineering, whether through iterative learning or comprehensive upfront specification.

My Advice

Start with Systematic Exploration: Spend serious time on dry runs where Claude Code explores different parts of your codebase just to understand patterns. These exploration sessions generate initial learning documents that become the foundation for actual feature work.

Scale Through Specialization: Different engineers working on different parts create specialized training data. Each domain contributes to collective intelligence.

Invest in Learning Extraction Quality: Valuable learnings are specific: "Authentication middleware in our Node.js services requires custom error handling because our frontend expects specific JWT error codes that don't match OAuth2 standards."

How We'll Know It's Working

Cross-Team Knowledge Transfer: Engineers getting specific, actionable insights within minutes instead of scheduling meetings or digging through outdated documentation.

Compound Feature Velocity: The 10th authentication integration is 10x faster than the first because all previous learnings are immediately available.

Proactive Technical Debt Resolution: Agents identify systemic issues before they become critical: "I've analyzed 47 recent implementations and found that database connection pooling is a recurring bottleneck across 6 different services."

The Bottom Line

This represents a fundamental shift from individual AI assistance to organizational AI intelligence. Companies that figure this out first won't just ship faster; they'll build learning systems that get exponentially better at implementing their specific technical vision.

The future isn't about replacing engineers with AI. It's about creating systems where institutional knowledge gets systematically captured, refined, and applied rather than siloed and lost.

Today, that bot attack that nearly killed our startup would be a ten-minute fix, because our AI would instantly recognize the pattern from accumulated organizational memory and deploy the exact countermeasures we've refined across dozens of similar incidents.

The companies building these learning systems now aren't just preparing for a more efficient future; they're creating technical moats that will be nearly impossible to replicate later.

Either that or we'll all become PMs 🚀


Want to try this approach? Check out Cole Medin's context engineering guide for the foundational concepts, view the complete process flow diagram, then start with a single simple feature, document everything, and see what patterns emerge. The learning curve may be steep, but the compound effects are well worth it. Trust me 🤝