What is Claude Code?
Before diving into the leak, let's understand what Claude Code is and why this leak matters. π―
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. π»
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:
- Proprietary prompt engineering: How Anthropic structures prompts to Claude for optimal code generation
- Tool architecture: The permission system, safety checks, and integration patterns
- Unreleased features: Features built but not yet shipped, including the mysterious KAIROS daemon mode
- Business strategy: Feature flags revealing Anthropic's product roadmap
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. π
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. β±οΈ
@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.
@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.
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?
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: π¦
The .map file contains a mapping from the minified JavaScript back to the
original TypeScript source code. Here's what that looks like: π¬
{
"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 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: π οΈ
- Better error messages: Shows original line numbers instead of minified code
- Debugging: Set breakpoints in your original TypeScript code
- Stack traces: Error logs point to real source files
How to Prevent Source Map Leaks
There are two common ways to prevent shipping source maps: π‘οΈ
# .npmignore file
*.map
**/*.map
src/
*.ts
tsconfig.json
// bunfig.toml (Bun's config)
[bundle]
sourcemap = "none" // Options: "none", "inline", "external"
- Add
*.mapto.npmignore - Set
sourcemap = "none"in the Bun config - Add a pre-publish check to verify no
.mapfiles exist
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: β
dist/index.js (bundled, minified)
*.map, src/, *.ts. Only ship
production JavaScript.
.npmignore is working correctly.
npm publish uploads the clean package to npm registry.
What Actually Happened
But here's what happened with version 2.1.88: β
sourcemap wasn't disabled in config.
.npmignore missing *.map entry. Source maps remain in
dist/ directory.
npm pack bundles everything in dist/, including
index.js.map containing all source code.
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: π¨
- β No .npmignore rule:
*.mapwasn't excluded from the package - β No bundler config: Bun's
sourcemapoption wasn't set to"none" - β No pre-publish checks: No automated script to verify
.mapfiles don't exist - β No package size alert: The package was abnormally large (source maps add significant size) but no one noticed
- β No manual review: No one inspected the tarball contents before publishing
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: π¬
- Installing
@anthropic-ai/claude-code@2.1.88via npm - Exploring the
node_modules/@anthropic-ai/claude-code/directory - Noticing
.mapfiles in thedist/folder - Opening one and finding the
sourcesContentfield with complete TypeScript source - Extracting all source files from the map
- Posting his finding on X (Twitter)
# 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! π₯
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
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: π§
// 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: π‘
"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..."
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. π₯€
Anthropic's Response: Damage Control
Once the leak went viral, Anthropic had to respond quickly. Here's how they handled it: π‘οΈ
Official 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. We have since published a corrected version and are implementing additional safeguards to prevent similar issues in the future."
What Anthropic Did Right
- β Fast acknowledgment: Responded within ~6 hours of discovery
- β Transparent explanation: Admitted it was human error, not a hack
- β Quick fix: Published corrected version 2.1.89 the same day
- β No downplaying: Didn't try to minimize or hide the mistake
What Could Have Been Better
- β οΈ No technical details: Didn't explain HOW it happened or what safeguards failed
- β οΈ No post-mortem: No detailed incident report published
- β οΈ No takeaways: Didn't share lessons learned with the community
- β οΈ Second incident: This happened days after accidentally revealing internal project "Mythos" β pattern of operational security issues
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: π
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: π
- π github.com/ssukhawani/claude-leaked-files β Complete extracted source files from the leak
- π github.com/ssukhawani/leaked-claude-code β Full archive preserved for educational purposes
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. π
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
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
*.mapand**/*.mapto.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
.mapfiles to git repos
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
.mapfiles exist - β Check package size (source maps significantly increase size)
- β
Inspect
npm packoutput before publishing - β
Use
npm publish --dry-runto preview what will be published
{
"scripts": {
"prepublishOnly": "npm run check-source-maps && npm run build",
"check-source-maps": "node scripts/check-no-source-maps.js"
}
}
// 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.');
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)
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
# bunfig.toml
[bundle]
# Explicitly disable source maps for production
sourcemap = "none" // Options: "none", "inline", "external"
minify = true
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 packand inspect the.tgzcontents - β Check file sizes (anomalies indicate issues)
- β
Verify
.npmignoreis working correctly - β Test install in a clean environment 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
- βοΈ Add
*.mapto.npmignore - βοΈ Configure bundler to disable source maps for production
- βοΈ Add pre-publish hook to check for
.mapfiles - βοΈ Run
npm packand inspect tarball contents - βοΈ Check package size is reasonable
- βοΈ Test install in clean environment
- βοΈ Use
npm publish --dry-runfirst - βοΈ Review what files will be included
- βοΈ Verify no secrets or credentials in code
References & Resources
π° News Coverage
- The Register: Anthropic accidentally exposes Claude Code source code
- VentureBeat: Claude Code's source code appears to have leaked: here's what we know
- CNBC: Anthropic leaks part of Claude Code's internal source code
- Axios: Anthropic leaked its own Claude source code
- Fortune: Anthropic leaks AI tool's source code in second major security breach
- Gizmodo: Source Code for Anthropic's Claude Code Leaks at the Exact Wrong Time
π¬ Technical Analysis
- The AI Corner: Claude Code Source Code Leaked: What's Inside (2026)
- Alex Kim's Blog: The Claude Code Source Leak - fake tools, frustration regexes, undercover mode
- DEV Community: Claude Code's Entire Source Code Leaked via npm Source Maps
- GitHub: Claude Code Breakdown - How it Works
- Slashdot: Claude Code's Source Code Leaks Via npm Source Maps
π Documentation & Best Practices
- npm Documentation: Keeping files out of your package
- Bun Documentation: Bundler
- MDN: How to use a source map
- Sentry: Uploading Source Maps