← Back to all posts
Data Leak

Claude Code's 512,000-Line Leak:
When Source Maps Expose Everything 😱

On March 31, 2026, Anthropic accidentally shipped an npm package containing source maps that exposed the entire Claude Code source code β€” 1,900 TypeScript files, 512,000 lines, hidden features, and all. Within hours, it was mirrored 41,500+ times on GitHub. Here's what happened. πŸ’₯

πŸ“… Mar 31, 2026 πŸ—ΊοΈ npm Source Map Leak πŸ“¦ @anthropic-ai/claude-code@2.1.88 πŸ“– 20 min read
Scroll to learn ↓
01

What is Claude Code?

Before diving into the leak, let's understand what Claude Code is and why this leak matters. 🎯

πŸ€– Simple Explanation

Claude Code is Anthropic's AI-powered coding assistant that runs in your terminal. Think of it like having an expert developer pair-programming with you β€” it can read your files, run commands, search the web, and write code to solve your problems. It's Claude (the AI chatbot) but with superpowers: file access, bash execution, and deep IDE integration.

It's distributed as an npm package that developers install locally, giving Claude the ability to interact with your development environment directly. πŸ’»

512K+ Lines of Code Leaked
1,900 TypeScript Files
41,500+ GitHub Forks
~40 Built-in Tools

Why Claude Code Matters

Claude Code represents Anthropic's competitive edge in the AI coding assistant market, competing directly with GitHub Copilot, Cursor, and other AI-powered IDEs. The source code contains:

Why This Leak Is Significant:
Unlike typical open-source projects, Claude Code is a proprietary, closed-source tool. Anthropic explicitly keeps it closed to maintain competitive advantage. This leak effectively open-sourced their entire AI coding assistant, giving competitors and researchers complete visibility into their implementation. πŸ”
02

What Happened: The Leak Timeline

Let's walk through exactly what happened on March 31, 2026, when a simple npm publish became a massive source code leak. ⏱️

Mar 31, ~12:00 UTC
πŸ“¦ Package Published
Anthropic publishes @anthropic-ai/claude-code@2.1.88 to the npm registry. The package includes bundled JavaScript code for the Claude Code CLI tool β€” and something they didn't intend: complete source maps.
Mar 31, 04:23 ET (~09:23 UTC)
πŸ” Leak Discovered
Security researcher Chaofan Shou (@Fried_rice), an intern at Solayer Labs, discovers the source maps embedded in the npm package. He posts on X (Twitter): "Anthropic just accidentally leaked Claude Code's entire source code via npm source maps πŸ’€"
Mar 31, ~10:00 UTC
🌍 Viral Spread
The news spreads rapidly across X, Hacker News, Reddit, and Discord servers. Developers rush to download and archive the package before it's removed. The extracted source code is uploaded to GitHub.
Mar 31, ~12:00 UTC
πŸ“Š Analysis Begins
Developers begin analyzing the 512,000-line codebase. Hidden features, feature flags, and internal tools are documented. Blog posts and breakdown videos start appearing. The GitHub mirror is forked thousands of times.
Mar 31, ~15:00 UTC
πŸ“’ Anthropic Responds
Anthropic publishes a statement: "Earlier today, a Claude Code release included some internal source code. This was a release packaging issue caused by human error, not a security breach. No customer data or credentials were involved or exposed."
Mar 31, ~16:00 UTC
πŸ”§ Fixed Package Published
Anthropic publishes @anthropic-ai/claude-code@2.1.89 without source maps. The version 2.1.88 is unpublished from npm. However, the damage is done β€” the source code is already mirrored 41,500+ times across GitHub.
⚠️ Why This Happened So Fast: The leak window was approximately 4 hours from publish to discovery. However, once discovered and posted on X, the viral spread happened in minutes. By the time Anthropic responded, the source code was already permanently archived across thousands of repositories.
03

Understanding Source Maps: The Root Cause

To understand how this leak happened, we need to understand what source maps are and why they're dangerous when included in production builds. πŸ—ΊοΈ

What Are Source Maps?

πŸ“š Simple Analogy

Imagine you write a book in English, then someone translates it into Chinese and removes all the chapter titles and paragraph breaks. A source map is like a translator's guide that maps each Chinese sentence back to the original English text.

In web development, your TypeScript code (the "English") gets compiled/bundled into JavaScript (the "Chinese"). A source map lets debugging tools show you the original TypeScript code when errors occur, even though the browser is running the compiled JavaScript. πŸ”

How Source Maps Work

When you build a TypeScript project, bundlers like Webpack, Bun, or Rollup create two files: πŸ“¦

Source Map Build Process
TypeScript Source
src/app.ts (readable)
β†’ Bundler
JavaScript Bundle
dist/app.js (minified)
+
Source Map
πŸ’₯ dist/app.js.map

The .map file contains a mapping from the minified JavaScript back to the original TypeScript source code. Here's what that looks like: πŸ”¬

πŸ“„ Example Source Map File (Simplified)
{
  "version": 3,
  "file": "app.js",
  "sources": [
    "../src/app.ts",
    "../src/utils/auth.ts",
    "../src/tools/file-reader.ts"
  ],
  "sourcesContent": [
    // πŸ’₯ This contains the ENTIRE original TypeScript source code!
    "import { authenticate } from './utils/auth';\n\nconst API_KEY = 'sk-proj-...';\n..."
  ],
  "mappings": "AAAA,OAAO,CAAC,MAAM..."  // Base64 encoded position mappings
}
🚨 The Critical Problem

The sourcesContent field contains the complete, unminified original source code. If you ship a source map in your npm package, anyone can extract your entire TypeScript codebase by simply reading the .map file. No decompilation or reverse engineering needed β€” it's right there in plain text! πŸ’₯

Why Include Source Maps at All?

Source maps are incredibly useful during development and debugging: πŸ› οΈ

Best Practice: Source maps should be generated during development but excluded from production builds. If you need production debugging, upload source maps to error tracking services (Sentry, Datadog) privately instead of shipping them publicly. πŸ”

How to Prevent Source Map Leaks

There are two common ways to prevent shipping source maps: πŸ›‘οΈ

πŸ“„ Method 1: Add to .npmignore
# .npmignore file
*.map
**/*.map
src/
*.ts
tsconfig.json
βš™οΈ Method 2: Disable in Bundler Config (Bun Example)
// bunfig.toml (Bun's config)
[bundle]
sourcemap = "none"  // Options: "none", "inline", "external"
πŸ’₯ Anthropic's Mistake: Claude Code is built with Bun's bundler, which generates source maps by default. Someone forgot to either:
  1. Add *.map to .npmignore
  2. Set sourcemap = "none" in the Bun config
  3. Add a pre-publish check to verify no .map files exist
The result? 512,000 lines of proprietary TypeScript source code shipped to npm. 😱
04

The Packaging Mistake: How It Slipped Through

Let's break down exactly what went wrong in Anthropic's release process and how a single oversight led to a massive leak. πŸ”

The Normal Build Process

Here's what should have happened during the Claude Code release: βœ…

Step 1
πŸ”¨ Build TypeScript
Compile TypeScript to JavaScript using Bun bundler. Output: dist/index.js (bundled, minified)
Step 2
🧹 Clean Build Artifacts
Remove development files: *.map, src/, *.ts. Only ship production JavaScript.
Step 3
πŸ“¦ Package for npm
Create tarball with only necessary files. Verify .npmignore is working correctly.
Step 4
πŸš€ Publish to npm
npm publish uploads the clean package to npm registry.

What Actually Happened

But here's what happened with version 2.1.88: ❌

Step 1
πŸ”¨ Build TypeScript
Bun bundler compiles TypeScript. Source maps generated by default because sourcemap wasn't disabled in config.
Step 2
πŸ’₯ Source Maps Not Removed
.npmignore missing *.map entry. Source maps remain in dist/ directory.
Step 3
πŸ“¦ Package Includes .map Files
npm pack bundles everything in dist/, including index.js.map containing all source code.
Step 4
πŸš€ Published with Source Maps
Package goes live on npm registry. Anyone running npm install @anthropic-ai/claude-code now has access to the complete source code.

Why This Wasn't Caught

Several layers of protection should have prevented this, but all failed: 🚨

Failed Safeguards:
  1. ❌ No .npmignore rule: *.map wasn't excluded from the package
  2. ❌ No bundler config: Bun's sourcemap option wasn't set to "none"
  3. ❌ No pre-publish checks: No automated script to verify .map files don't exist
  4. ❌ No package size alert: The package was abnormally large (source maps add significant size) but no one noticed
  5. ❌ No manual review: No one inspected the tarball contents before publishing
🎯 The Root Cause

This wasn't a sophisticated hack or a security vulnerability. It was a simple configuration oversight combined with missing pre-flight checks. Anthropic correctly called it "human error" β€” someone forgot to add one line to .npmignore or disable source maps in the bundler config. 🀦

How It Was Discovered

Chaofan Shou discovered the leak by: πŸ”¬

  1. Installing @anthropic-ai/claude-code@2.1.88 via npm
  2. Exploring the node_modules/@anthropic-ai/claude-code/ directory
  3. Noticing .map files in the dist/ folder
  4. Opening one and finding the sourcesContent field with complete TypeScript source
  5. Extracting all source files from the map
  6. Posting his finding on X (Twitter)
πŸ’» Bash β€” How to Extract Source Maps (Simplified)
# Install the package
npm install @anthropic-ai/claude-code@2.1.88

# Navigate to package directory
cd node_modules/@anthropic-ai/claude-code/dist/

# List .map files
ls *.map

# View source map contents
cat index.js.map | jq '.sourcesContent'

# Extract to files
node << 'EOF'
const fs = require('fs');
const map = JSON.parse(fs.readFileSync('index.js.map'));
map.sources.forEach((path, i) => {
  const content = map.sourcesContent[i];
  fs.mkdirSync(path.substring(0, path.lastIndexOf('/')), {recursive: true});
  fs.writeFileSync(path, content);
});
EOF

# Result: Complete TypeScript source code extracted! πŸ’₯
05

What Was Inside the Leak: 512,000 Lines Exposed

Once the source code was extracted, developers worldwide started analyzing the codebase. Here's what they found: πŸ“Š

The Scale of the Leak

1,900 TypeScript Files
512,047 Lines of Code
~40 Built-in Tools
44 Feature Flags

The Architecture: Tool System

The leaked code reveals that Claude Code is built around a sophisticated tool system where each capability is a discrete, permission-gated tool: πŸ”§

πŸ”¨ TypeScript β€” Base Tool Definition (Simplified)
// Base tool interface (~29,000 lines in full implementation)
interface Tool {
  name: string;
  description: string;
  permissions: Permission[];
  execute(params: ToolParams): Promise<ToolResult>;
  validate(params: ToolParams): ValidationResult;
}

// Permission system
enum Permission {
  READ_FILE = 'read_file',
  WRITE_FILE = 'write_file',
  EXECUTE_BASH = 'execute_bash',
  WEB_FETCH = 'web_fetch',
  LSP_INTEGRATION = 'lsp_integration'
}

The ~40 Built-in Tools

The source code revealed approximately 40 tools that Claude Code uses to interact with your development environment: πŸ› οΈ

Category Tools Permission Required
File System Read, Write, Edit, Glob, Grep read_file, write_file
Shell Bash, TaskOutput, TaskStop execute_bash
Web WebFetch, WebSearch web_fetch
IDE Integration LSP, CodeLens, Diagnostics lsp_integration
Project Management TodoWrite, Agent, Skill project_write
Automation CronCreate, RemoteTrigger automation

Prompt Engineering Revealed

One of the most valuable parts of the leak: the exact prompts Anthropic uses to make Claude effective at coding tasks. Here's an example: πŸ’‘

πŸ“ System Prompt Snippet (Simplified)
"You are Claude Code, Anthropic's official CLI for Claude. You are an expert software engineer..."

"IMPORTANT: Assist with authorized security testing... Refuse destructive techniques..."

"# Using your tools
- Do NOT use the Bash tool to run commands when a relevant dedicated tool is provided
- To read files use Read instead of cat
- To edit files use Edit instead of sed..."

"# Doing tasks
- Do not create files unless they're absolutely necessary
- Avoid giving time estimates..."
🎯 Why This Matters

These prompts represent years of engineering effort to make an AI assistant that's helpful without being destructive. Competitors can now see exactly how Anthropic instructs Claude to behave, what safety guardrails exist, and how tools are prioritized. It's like getting the recipe for Coca-Cola. πŸ₯€

06

Hidden Features Discovered: KAIROS & More

The most exciting part of the leak? Discovery of 44 feature flags revealing unreleased features that are fully built but not yet shipped. Let's explore the most interesting ones: πŸ”

KAIROS: The Autonomous Daemon Mode

The most mysterious and heavily discussed feature is KAIROS, mentioned over 150 times in the source code. Here's what we know: πŸ€–

KAIROS (from Greek ΞΊΞ±ΞΉΟΟŒΟ‚, meaning "the right moment"): An unreleased feature that would allow Claude Code to operate as an always-on background agent that monitors your development environment and proactively suggests improvements, fixes bugs, and automates repetitive tasks β€” even when you're not actively asking it questions.
πŸ”§ KAIROS Feature Flag (Leaked Code)
// Feature flag definition
const FEATURE_FLAGS = {
  KAIROS_DAEMON_MODE: false,  // 🚧 Not yet enabled
  KAIROS_AUTO_FIX: false,
  KAIROS_PROACTIVE_SUGGESTIONS: false,
  KAIROS_BACKGROUND_MONITORING: false
};

// Daemon initialization (if enabled)
async function initKairosDaemon() {
  if (!FEATURE_FLAGS.KAIROS_DAEMON_MODE) return;

  // Watch file changes
  const watcher = createFileWatcher(projectRoot);

  watcher.on('change', async (file) => {
    // Analyze changes for potential issues
    const analysis = await analyzeCode(file);

    if (analysis.hasIssues && FEATURE_FLAGS.KAIROS_AUTO_FIX) {
      await suggestFix(analysis);
    }
  });
}
πŸ€– What KAIROS Would Do

Think of KAIROS like having a senior developer who sits in the background watching your work:

  • You write code: KAIROS notices you're missing error handling
  • You commit: KAIROS suggests running tests first
  • CI fails: KAIROS analyzes logs and proposes a fix
  • Dependency updated: KAIROS checks for breaking changes

All of this happens automatically, in the background, without you having to ask. It's the next evolution of AI coding assistants. πŸš€

Other Hidden Features

Beyond KAIROS, the leak revealed 43 other feature flags: 🚩

🎨 Enhanced UI Mode Rich terminal UI
🌐 Multi-Repo Support Work across projects
🀝 Team Collaboration Shared sessions
πŸ”Œ Plugin System Third-party tools

What This Reveals About Anthropic's Strategy

The 44 feature flags give us a roadmap of Anthropic's product vision: πŸ—ΊοΈ

🎯 Competitive Intelligence

For competitors like GitHub Copilot, Cursor, and Replit, this leak is a goldmine. They now know exactly what Anthropic is building, how far along each feature is, and what the implementation looks like. It's like poker players seeing their opponent's hand mid-game. πŸƒ

07

Anthropic's Response: Damage Control

Once the leak went viral, Anthropic had to respond quickly. Here's how they handled it: πŸ›‘οΈ

Official Statement

Anthropic's Public Statement (March 31, 2026):

"Earlier today, a Claude Code release included some internal source code. This was a release packaging issue caused by human error, not a security breach. No customer data or credentials were involved or exposed. We have since published a corrected version and are implementing additional safeguards to prevent similar issues in the future."

What Anthropic Did Right

What Could Have Been Better

🚨 Context: Second Leak in One Week
This Claude Code leak came just days after Anthropic accidentally revealed details about an internal project called "Mythos" in another operational security lapse. Two major information leaks in one week suggests systemic issues with Anthropic's release processes. 😬

The Permanent Damage

Despite Anthropic's quick response, the damage is permanent: πŸ’”

41,500+ GitHub Forks
Permanent Source Code Now Public
100s Analysis Blog Posts
Lost Competitive Advantage

Once source code is on the internet, it's impossible to un-leak it. The cat is out of the bag. 🐱

Where to Find the Leaked Source Code

If you want to explore the leaked source yourself, here are some GitHub repositories that archived it before Anthropic could take action: πŸ”—

⚠️ Archived Repositories:
πŸ“š What You Can Learn

The leaked source is a goldmine for learning:

  • Prompt engineering: See exactly how Anthropic instructs Claude
  • Tool architecture: How to build an AI agent with 40+ tools
  • Permission system: Safely letting AI modify files
  • TypeScript patterns: Enterprise-grade code organization
  • Testing strategies: How Anthropic tests AI behavior

This is accidental open-source education from one of the world's leading AI companies. πŸŽ“

08

Key Takeaways & Prevention Strategies

What can we learn from Anthropic's mistake? Here are the critical lessons and how to prevent similar leaks in your projects: πŸ’‘

🎯 Key Lessons Learned

1. Source Maps Are Production Security Risks

The Mistake: Shipping source maps in a production npm package exposed 512,000 lines of proprietary code.

The Lesson: Source maps are invaluable for development but dangerous in production. They contain your entire original source code in plain text.

Action Items:

  • βœ… Add *.map and **/*.map to .npmignore
  • βœ… Configure bundlers to disable source maps for production builds
  • βœ… If needed for production debugging, upload maps privately to error tracking services (Sentry, Datadog)
  • βœ… Never commit .map files to git repos
2. Automated Pre-Publish Checks Are Critical

The Mistake: No automated checks caught the source maps before publishing.

The Lesson: Human review is unreliable. Automate security checks in your release pipeline.

Action Items:

  • βœ… Add pre-publish hook to verify no .map files exist
  • βœ… Check package size (source maps significantly increase size)
  • βœ… Inspect npm pack output before publishing
  • βœ… Use npm publish --dry-run to preview what will be published
πŸ“¦ package.json β€” Add Pre-Publish Safety Check
{
  "scripts": {
    "prepublishOnly": "npm run check-source-maps && npm run build",
    "check-source-maps": "node scripts/check-no-source-maps.js"
  }
}
πŸ”’ JavaScript β€” Source Map Detection Script
// scripts/check-no-source-maps.js
const fs = require('fs');
const path = require('path');

function findSourceMaps(dir) {
  const files = fs.readdirSync(dir);
  let found = [];

  files.forEach(file => {
    const filePath = path.join(dir, file);
    const stat = fs.statSync(filePath);

    if (stat.isDirectory()) {
      found = found.concat(findSourceMaps(filePath));
    } else if (file.endsWith('.map')) {
      found.push(filePath);
    }
  });

  return found;
}

const sourceMaps = findSourceMaps('./dist');

if (sourceMaps.length > 0) {
  console.error('🚨 ERROR: Source maps found in dist/:');
  sourceMaps.forEach(file => console.error(`  - ${file}`));
  console.error('\nAdd *.map to .npmignore or disable sourcemaps in bundler config');
  process.exit(1);
}

console.log('βœ… No source maps found. Safe to publish.');
3. Security Is a Process, Not a One-Time Fix

The Mistake: This was Anthropic's second leak in one week, suggesting systemic issues.

The Lesson: Security requires continuous vigilance, training, and process improvements.

Action Items:

  • βœ… Conduct post-mortems for all security incidents
  • βœ… Share lessons learned across the engineering team
  • βœ… Regular security training for all developers
  • βœ… Periodic audits of published packages
  • βœ… Implement defense-in-depth (multiple layers of security checks)
4. Bundler Defaults Matter

The Mistake: Bun's bundler generates source maps by default.

The Lesson: Know your tools' defaults. Production builds should explicitly configure security-sensitive options.

Action Items:

  • βœ… Explicitly disable source maps in production configs
  • βœ… Review all bundler/compiler default settings
  • βœ… Use separate configs for dev vs. production
  • βœ… Document why each config option is set
βš™οΈ Bun Configuration β€” Disable Source Maps
# bunfig.toml
[bundle]
# Explicitly disable source maps for production
sourcemap = "none"  // Options: "none", "inline", "external"
minify = true
5. Package Inspection Should Be Standard Practice

The Mistake: No one manually inspected the package contents before publishing.

The Lesson: Always inspect what you're about to publish, especially for critical releases.

Action Items:

  • βœ… Run npm pack and inspect the .tgz contents
  • βœ… Check file sizes (anomalies indicate issues)
  • βœ… Verify .npmignore is working correctly
  • βœ… Test install in a clean environment before publishing
πŸ’» Bash β€” Inspect Package Before Publishing
# Create package tarball
npm pack

# Extract and inspect contents
tar -tzf anthropic-claude-code-2.1.88.tgz

# Check for .map files
tar -tzf anthropic-claude-code-2.1.88.tgz | grep '\.map$'

# If any .map files found, DO NOT PUBLISH!

πŸ›‘οΈ npm Publishing Security Checklist

Before publishing any npm package:
  • β˜‘οΈ Add *.map to .npmignore
  • β˜‘οΈ Configure bundler to disable source maps for production
  • β˜‘οΈ Add pre-publish hook to check for .map files
  • β˜‘οΈ Run npm pack and inspect tarball contents
  • β˜‘οΈ Check package size is reasonable
  • β˜‘οΈ Test install in clean environment
  • β˜‘οΈ Use npm publish --dry-run first
  • β˜‘οΈ Review what files will be included
  • β˜‘οΈ Verify no secrets or credentials in code
09

References & Resources

πŸ“° News Coverage

πŸ”¬ Technical Analysis

πŸ“š Documentation & Best Practices

πŸ› οΈ Tools & Resources

Found this helpful? Share it! πŸš€