<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[TranHoangTu]]></title><description><![CDATA[TranHoangTu]]></description><link>https://tutranhoang.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Dec 2026 00:10:28 GMT</lastBuildDate><atom:link href="https://tutranhoang.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How AI Coding Agents Silently Leak Production Secrets on Your Laptop]]></title><description><![CDATA[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…]]></description><link>https://tutranhoang.hashnode.dev/how-ai-coding-agents-silently-leak-production-secrets-on-your-laptop</link><guid isPermaLink="true">https://tutranhoang.hashnode.dev/how-ai-coding-agents-silently-leak-production-secrets-on-your-laptop</guid><category><![CDATA[Security]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[DevSecOps]]></category><category><![CDATA[open source]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Tu Tran Hoang]]></dc:creator><pubDate>Tue, 01 Dec 2026 06:39:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/69c96af15282e6ac9cd76d85/b829b738-e130-45dd-88c1-409b63a2dd20.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you use Claude Code, Cursor, Codex, Gemini CLI, or MCP servers daily, you probably already have <code>.env</code> in your <code>.gitignore</code> and a secret scanner running in CI.</p>
<p>That used to be enough. In 2026, it leaves a massive blind spot right on your laptop.</p>
<p>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.</p>
<hr />
<h2>Leak Surface #1: <code>.claude/settings.local.json</code></h2>
<p>Whenever Claude Code runs a shell command and you click <strong>"Yes, and don't ask again"</strong>, it saves the exact command pattern into <code>.claude/settings.local.json</code> inside your repository so it won't prompt you next time.</p>
<p>That works great for <code>Bash(npm test)</code>. It works terribly when the approved command contained an inline credential:</p>
<pre><code class="language-json">{
  "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)"
    ]
  }
}
</code></pre>
<p>Two things make this especially dangerous:</p>
<ol>
<li>It lives <strong>inside your Git working tree</strong>, yet many repos never added <code>.claude/settings.local.json</code> to <code>.gitignore</code>.</li>
<li>Even if it stays local, it persists production database passwords and bearer tokens in plaintext indefinitely.</li>
</ol>
<hr />
<h2>Leak Surface #2: Append-Only Agent <code>.jsonl</code> Transcripts</h2>
<p>AI coding agents keep rich local session logs so you can resume conversations later:</p>
<ul>
<li><code>~/.claude/projects/**/*.jsonl</code></li>
<li><code>~/.codex/sessions/**/*.jsonl</code></li>
<li><code>~/.gemini/tmp/**</code></li>
<li><code>.aider.chat.history.md</code></li>
</ul>
<p>Every time you paste a snippet of <code>.env</code> while debugging a failing migration, dump a <code>curl</code> 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.</p>
<p>Unlike <code>.env</code>, you cannot simply delete a line with <code>sed</code> or run a naive regex search-and-replace over raw JSONL — one unescaped quote or truncated line corrupts the entire session file.</p>
<hr />
<h2>Leak Surface #3: Hardcoded Tokens in MCP Configs</h2>
<p>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:</p>
<pre><code class="language-json">{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_8Kx9mP2qR4vW7yZ3bN5cF6hJ1dL0sT4uV9wX"
      }
    }
  }
}
</code></pre>
<p>Multiply that across <code>.cursor/mcp.json</code>, <code>.mcp.json</code>, <code>.vscode/mcp.json</code>, <code>cline_mcp_settings.json</code>, and <code>claude_desktop_config.json</code>, and a single workstation easily ends up with dozens of long-lived tokens scattered across hidden dotfiles.</p>
<hr />
<h2>Why Traditional Secret Scanners Miss This</h2>
<p>Tools like <code>gitleaks</code>, <code>trufflehog</code>, and <code>detect-secrets</code> are battle-tested for Git commits and CI pipelines. However, AI agent secret sprawl introduces three different requirements:</p>
<ol>
<li><strong>Auto-discovery outside Git:</strong> Scanners need to know where 14+ AI agent and MCP clients store local state across macOS, Linux, and Windows.</li>
<li><strong>Lossless JSON/JSONL redaction:</strong> Simply flagging a secret in a 4,000-line <code>~/.claude/.../session.jsonl</code> file leaves you manually editing minified JSON. Redaction must operate on parsed AST string nodes and verify syntax integrity via <code>JSON.parse</code> before writing back.</li>
<li><strong>Real-time prevention before logging:</strong> Waiting until <code>git push</code> is 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.</li>
</ol>
<hr />
<h2>Closing the Gap with <code>clawleak</code> (0 Dependencies, 100% Offline)</h2>
<p>To solve all three layers cleanly, I built <a href="https://github.com/tranhoangtu-it/clawleak"><strong><code>clawleak</code></strong></a> — an MIT-licensed TypeScript CLI with <strong>zero runtime dependencies</strong> and <strong>zero network calls</strong>.</p>
<h3>1. Audit your machine in 2 seconds (read-only, masked output)</h3>
<pre><code class="language-bash">npx clawleak scan --agents-only
</code></pre>
<p><code>clawleak</code> scans across 14 AI agent &amp; MCP sources using <strong>160 built-in detectors</strong> (plus entropy and placeholder filtering) and masks every secret (<code>sk-ant****9a2f</code>) in its report along with a 0–100 hygiene score.</p>
<h3>2. Losslessly scrub leaked JSON and JSONL files</h3>
<pre><code class="language-bash"># Dry-run preview first
npx clawleak clean

# Apply AST-level redaction with .clawleak.bak backups
npx clawleak clean --write
</code></pre>
<p>Every modified JSON object and every JSONL line is validated with <code>JSON.parse</code> (<code>validJSON=true</code>) before atomic replacement — so your Claude Code sessions and Cursor MCP configs stay 100% intact. <em>(And of course: always rotate any exposed production credentials at their provider!)</em></p>
<h3>3. Block future leaks in real time with <code>PreToolUse</code> hooks</h3>
<pre><code class="language-bash">npx clawleak guard install
</code></pre>
<p>This hardens <code>.gitignore</code>, adds a Git <code>pre-commit</code> hook, and installs a <strong>Claude Code <code>PreToolUse</code> hook</strong> (<code>clawleak guard check-stdin</code>) that returns exit code <code>2</code> whenever a tool call attempts to inline credentials or read <code>.env</code> / <code>~/.aws/credentials</code> / SSH private keys into session transcripts.</p>
<hr />
<h2>Skeptical of Running an Unknown Security CLI?</h2>
<p>You should be! That is why <code>clawleak</code> has zero runtime dependencies (<code>dependencies: {}</code>), never touches the network, and compiles the exact same engine into a <strong>100% offline Browser Playground</strong> so you can inspect and scrub a single file with zero uploads first:</p>
<ul>
<li><strong>Offline Browser Playground:</strong> <a href="https://tranhoangtu-it.github.io/clawleak/">https://tranhoangtu-it.github.io/clawleak/</a></li>
<li><strong>GitHub Repository (MIT):</strong> <a href="https://github.com/tranhoangtu-it/clawleak">https://github.com/tranhoangtu-it/clawleak</a></li>
<li><strong>CI / GitHub Action:</strong> <code>tranhoangtu-it/clawleak@v1</code> (with SARIF 2.1.0 output for GitHub Code Scanning)</li>
</ul>
<p>Run <code>npx clawleak scan --agents-only</code> on your laptop today — and if it catches a forgotten token in <code>.claude/settings.local.json</code> or <code>.cursor/mcp.json</code>, drop a comment or open an issue for any agent store you want added next.</p>
]]></content:encoded></item></channel></rss>