How AI Coding Agents Silently Leak Production Secrets on Your Laptop
If you use Claude Code, Cursor, Codex, Gemini CLI, or MCP servers daily, you probably already have .env in your .gitignore and a secret scanner running in CI. That used to be enough. In 2026, it leaves a massive blind s
If you use Claude Code, Cursor, Codex, Gemini CLI, or MCP servers daily, you probably already have .env in your .gitignore and a secret scanner running in CI.
That used to be enough. In 2026, it leaves a massive blind spot right on your laptop.
While auditing my own developer workstation recently, I discovered three places where AI coding agents silently accumulate months of plaintext credentials β places that traditional git-focused secret scanners rarely inspect.
Leak Surface #1: .claude/settings.local.json
Whenever Claude Code runs a shell command and you click "Yes, and don't ask again", it saves the exact command pattern into .claude/settings.local.json inside your repository so it won't prompt you next time.
That works great for Bash(npm test). It works terribly when the approved command contained an inline credential:
{
"permissions": {
"allow": [
"Bash(PGPASSWORD=ProdDb9xK4mQ2vR8wZ7nL3 psql -h prod-db.internal -U admin -c 'SELECT count(*) FROM users;')",
"Bash(curl -H \"Authorization: Bearer eyJhbGciOi...\" https://api.internal/health)"
]
}
}
Two things make this especially dangerous:
- It lives inside your Git working tree, yet many repos never added
.claude/settings.local.jsonto.gitignore. - Even if it stays local, it persists production database passwords and bearer tokens in plaintext indefinitely.
Leak Surface #2: Append-Only Agent .jsonl Transcripts
AI coding agents keep rich local session logs so you can resume conversations later:
~/.claude/projects/**/*.jsonl~/.codex/sessions/**/*.jsonl~/.gemini/tmp/**.aider.chat.history.md
Every time you paste a snippet of .env while debugging a failing migration, dump a curl response containing an API token, or ask an agent to inspect a failing webhook secret, that plaintext value is permanently appended to a JSONL file on disk.
Unlike .env, you cannot simply delete a line with sed or run a naive regex search-and-replace over raw JSONL β one unescaped quote or truncated line corrupts the entire session file.
Leak Surface #3: Hardcoded Tokens in MCP Configs
The Model Context Protocol (MCP) makes connecting agents to GitHub, Postgres, Supabase, Slack, and Sentry effortless. Unfortunately, most quickstart snippets encourage dropping raw tokens straight into JSON configs:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_8Kx9mP2qR4vW7yZ3bN5cF6hJ1dL0sT4uV9wX"
}
}
}
}
Multiply that across .cursor/mcp.json, .mcp.json, .vscode/mcp.json, cline_mcp_settings.json, and claude_desktop_config.json, and a single workstation easily ends up with dozens of long-lived tokens scattered across hidden dotfiles.
Why Traditional Secret Scanners Miss This
Tools like gitleaks, trufflehog, and detect-secrets are battle-tested for Git commits and CI pipelines. However, AI agent secret sprawl introduces three different requirements:
- Auto-discovery outside Git: Scanners need to know where 14+ AI agent and MCP clients store local state across macOS, Linux, and Windows.
-
Lossless JSON/JSONL redaction: Simply flagging a secret in a 4,000-line
~/.claude/.../session.jsonlfile leaves you manually editing minified JSON. Redaction must operate on parsed AST string nodes and verify syntax integrity viaJSON.parsebefore writing back. -
Real-time prevention before logging: Waiting until
git pushis too late once a secret is already written into local agent transcripts. You need a preventive hook right before the agent executes a tool call.
Closing the Gap with clawleak (0 Dependencies, 100% Offline)
To solve all three layers cleanly, I built clawleak β an MIT-licensed TypeScript CLI with zero runtime dependencies and zero network calls.
1. Audit your machine in 2 seconds (read-only, masked output)
npx clawleak scan --agents-only
clawleak scans across 14 AI agent & MCP sources using 160 built-in detectors (plus entropy and placeholder filtering) and masks every secret (sk-ant****9a2f) in its report along with a 0β100 hygiene score.
2. Losslessly scrub leaked JSON and JSONL files
# Dry-run preview first
npx clawleak clean
# Apply AST-level redaction with .clawleak.bak backups
npx clawleak clean --write
Every modified JSON object and every JSONL line is validated with JSON.parse (validJSON=true) before atomic replacement β so your Claude Code sessions and Cursor MCP configs stay 100% intact. (And of course: always rotate any exposed production credentials at their provider!)
3. Block future leaks in real time with PreToolUse hooks
npx clawleak guard install
This hardens .gitignore, adds a Git pre-commit hook, and installs a Claude Code PreToolUse hook (clawleak guard check-stdin) that returns exit code 2 whenever a tool call attempts to inline credentials or read .env / ~/.aws/credentials / SSH private keys into session transcripts.
Skeptical of Running an Unknown Security CLI?
You should be! That is why clawleak has zero runtime dependencies (dependencies: {}), never touches the network, and compiles the exact same engine into a 100% offline Browser Playground so you can inspect and scrub a single file with zero uploads first:
- Offline Browser Playground: https://tranhoangtu-it.github.io/clawleak/
- GitHub Repository (MIT): https://github.com/tranhoangtu-it/clawleak
-
CI / GitHub Action:
tranhoangtu-it/clawleak@v1(with SARIF 2.1.0 output for GitHub Code Scanning)
Run npx clawleak scan --agents-only on your laptop today β and if it catches a forgotten token in .claude/settings.local.json or .cursor/mcp.json, drop a comment or open an issue for any agent store you want added next.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.