Norfolk AI Labs

Shared Content → Claude Leak Report
The Claude Code Leak: Lessons for AI Agent Engineering

The Claude Code Leak: Lessons for AI Agent Engineering

What 512,000 lines of leaked TypeScript revealed about building production AI agents

March 31, 2026

What Happened

Anthropic accidentally shipped a .map sourcemap file in a Claude Code npm update

0 lines of TypeScript exposed within minutes

Mirrored, analyzed, ported to Python (claw-code repo hit 0 stars in hours)

Second Anthropic data mishap in weeks (model spec leak days prior)

Boris Cherny confirmed: plain developer error, not tooling bug

Bun bug (oven-sh/bun#28001) may have caused it - source maps served in production

Key Architectural Discoveries

The Agent Harness Pattern

  • The moat isn't the model - it's the harness (tools, memory, orchestration)
  • Drop DeepSeek or Gemini into the same harness and you may get improved coding ability
  • Live repo context loading every turn, dedicated Grep/Glob tools, LSP access
  • 5 context compaction strategies, 0+ event hooks
  • 3 subagent execution models

Three-Layer Memory System

  • Index layer (always loaded): ~150 chars per line, just pointers
  • Topic files (loaded on demand): actual knowledge
  • Transcripts (never read, only grep'd): never loaded into context
  • Write discipline: write topic file first, then update index
  • If a fact can be re-derived from the codebase, don't store it
  • autoDream: background memory consolidation between sessions

Prompt Cache Economics

  • SYSTEM_PROMPT_DYNAMIC_BOUNDARY splits static vs dynamic prompt
  • Static front half cached and reused across sessions
  • DANGEROUS_uncachedSystemPromptSection marks cache-breaking changes
  • 0 cache-break vectors tracked
  • "Sticky latches" prevent mode toggles from busting cache
  • Forked subagents inherit parent context as byte-identical copies (5 agents cost ~1)

KAIROS: Unreleased Autonomous Agent

  • Background 24/7 agent (similar to OpenClaw)
  • Heartbeat prompt: "anything worth doing right now?"
  • 3 exclusive tools: push notifications, file delivery, PR subscriptions
  • Append-only daily logs, cannot erase own history
  • autoDream: nightly memory distillation and consolidation
  • Separation of initiative from execution

Anti-Distillation Defenses

  • Fake tool injection to poison training data of copycats
  • Connector-text summarization with cryptographic signatures
  • Both bypassed in ~1 hour by determined actors
  • Real protection is legal, not technical

Security Architecture

  • 0 numbered security checks on every bash command
  • Defense against: Zsh builtins, equals expansion, unicode zero-width spaces, IFS null-byte injection
  • Native client attestation via Zig (below JS runtime)
  • DRM for API calls
  • Permission classification via side-query ("critic" pattern)
  • Frustration detection via regex (cheaper than LLM inference for sentiment)

Multi-Agent Orchestration

  • Coordinator algorithm is a PROMPT, not code
  • Instructions like "Do not rubber-stamp weak work"
  • "You must understand findings before directing follow-up work"
  • Three models: fork, teammate, worktree
  • Fork inherits parent context as byte-identical copy for cache efficiency

Context Compaction

  • MicroCompact: local cleanup
  • AutoCompact: near-limit summarization with circuit breaker
  • Full Compact: emergency compression with selective re-injection
  • MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3
  • Fixed 0 wasted API calls/day

Lessons for Our Stack

Apply to OpenClaw/Atlas

Claude Code Pattern Our Current State Action Item
3-layer memory (index → topic → transcript) Flat MEMORY.md + daily notes Consider index/topic split for faster retrieval
Prompt cache boundary Not explicitly managed Audit system prompt for static/dynamic split
autoDream consolidation Manual weekly hygiene Automate memory consolidation via cron
Coordinator as prompt Sub-agent delegation via AGENTS.md Formalize coordinator prompts for sub-agents
Critic pattern for security Allowlist-based exec security Evaluate side-query permission model
Forked subagent context inheritance Each subagent starts fresh Investigate context sharing for related sub-agents
Magic Docs (self-updating) Manual docs Implement idle-time doc refresh agents
250K API call waste fix Unknown waste Add compaction failure circuit breakers

Fun Facts

📄

Monster Function

print.ts: 0 lines, single function of 0 lines, 12 nesting levels deep

Spinner Variety

0 unique spinner verbs for loading states

🎮

April Fools Tamagotchi

0 species, rarity tiers, 0% shiny rate, RPG stats

🔍

Stealth Mode

Species names encoded with String.fromCharCode() to dodge grep

🕵️

Undercover Mode

One-way door, no force-OFF, strips all Anthropic references

🤖

AI-First Documentation

LLM-oriented code comments written for AI agents, not human readers

Sources

  • Engineer's Codex deep dive
  • alex000kim analysis
  • claw-code repo (instructkr)
  • VentureBeat, Guardian, Forbes, Axios coverage