So verhindern Coding-Assistenten das Leaken von API-Schlüsseln: Vierstufige Verteidigung
KI-Coding-Agenten wie Cursor oder Claude Code greifen beim Debuggen oft automatisch auf Dateien wie .env zu und können so live API-Schlüssel etwa für Stripe in Logs oder Repos leaken. Ein mehrstufiger Ansatz hilft, geheimen Schlüsseln den Schutz zu geben, den sie brauchen.

Du debuggst eine fehlgeschlagene Stripe-Zahlung in einer Flutter-App. Du fragst Cursor oder Claude Code, was schiefgelaufen ist, und der Agent tut das Naheliegende: Er liest die Debug Console, öffnet.env, um die Konfiguration zu prüfen, und führt flutter run erneut aus, um den Fehler zu reproduzieren. Nach etwa zehn Sekunden wurden dein echter Secret Key, das JWT eines Nutzers und das Keystore-Passwort aus key.properties allesamt als Prompt-Kontext an ein Cloud-Modell gesendet.
Für all das braucht es keinen Bug im KI-Tool. Agents lesen alles, was im Workspace liegt, und alles, was dein Code ausgibt. Dieser Leitfaden behandelt die Stellen, an denen Schlüssel während KI-gestützter Flutter- und Web-Entwicklung leaken, die Konfiguration, die jede dieser Stellen schließt, und wie sich das Setup automatisieren lässt, ohne deine Secrets in einen Vault zu verschieben.
GitGuardians Bericht State of Secrets Sprawl 2026, veröffentlicht am 17. März 2026, zählte 28,65 Millionen neue hartcodierte Secrets in öffentlichen GitHub-Commits im Jahr 2025. Das ist ein Anstieg von 34 Prozent gegenüber 2024 und laut GitGuardian der größte einjährige Sprung, der jemals erfasst wurde. Mehrere Befunde deuten direkt auf KI-Tools hin:
"AI agents need local credentials to connect across systems, turning developer laptops into a massive attack surface", sagte Eric Fourrier, CEO von GitGuardian, in der Ankündigung des Berichts.
Diese Zahlen erfassen nur Secrets, die in öffentliche Repositories committet wurden. Die unten beschriebenen Lecks umfassen zusätzlich Debug-Ausgaben, Terminal-Sitzungen und Chat-Prompts, die kein Repository-Scan jemals zu sehen bekommt.
Zwei Schwachstellenklassen decken nahezu jeden Fall ab. CWE-798 bezeichnet die Verwendung hartcodierter Zugangsdaten. CWE-532 bezeichnet sensible Informationen, die in eine Log-Datei geschrieben werden. KI-Assistenten verschärfen beides, denn sie lesen Quelldateien und Log-Ausgaben als Kontext. Ein Secret, das früher nur du gesehen hast, erreicht jetzt also ein Modell eines Drittanbieters.
In einem typischen Flutter-Projekt stammen die Lecks aus fünf Quellen:
Jedes KI-Tool liest seine eigene Ignore- oder Deny-Konfiguration. Du brauchst eine pro Tool, das dein Team verwendet.
Für Cursor, JetBrains und Gemini funktioniert eine Liste im Stil von gitignore:
#.cursorignore (dieser Inhalt funktioniert auch für.aiignore und.aiexclude).env.env.* *.env local.properties key.properties google-services.json GoogleService-Info.plist *credentials*.json *secret*.json *.pem *.key *.p12 *.keystore *.jks Enter fullscreen mode Exit fullscreen mode Claude Code ignoriert diese Dateien nicht. Es verwendet stattdessen Berechtigungsregeln in.claude/settings.json:
{ "permissions": { "deny": [ "Read(.env)", "Read(.env.*)", "Read(**/*.env)", "Read(**/key.properties)", "Read(**/local.properties)", "Read(**/google-services.json)", "Read(**/GoogleService-Info.plist)", "Read(**/*.keystore)", "Read(**/*.jks)", "Read(**/*.pem)", "Read(**/*.key)", "Edit(.env)", "Edit(.env.*)", "Write(.env)", "Write(.env.*)" ] } } Enter fullscreen mode Exit fullscreen mode Diese Regeln blockieren die Tools Read, Edit und Write. Sie hindern einen Agenten mit Shell-Zugriff jedoch nicht daran, cat.env auszuführen. Deshalb sind die nächsten beiden Ebenen wichtig, selbst wenn diese bereits eingerichtet ist.
Deine App muss den echten Schlüssel weiterhin laden, um die API aufzurufen, und alles, was ihn ausgibt, landet in der Konsole, die der Agent liest. OWASPs Logging Cheat Sheet führt "Access tokens", "Authentication passwords", "Database connection strings" und "Encryption keys and other primary secrets" unter den Daten auf, die "in der Regel nicht direkt in Logs aufgezeichnet werden sollten", und empfiehlt stattdessen, sie zu "entfernen, zu maskieren, zu bereinigen, zu hashen oder zu verschlüsseln". Das Secrets Management Cheat Sheet ist noch strenger: Secrets sollten "Never be logged". Wenn ein KI-Agent deine Debug Console liest, wird jeder geloggte Schlüssel zu einem CWE-532-Leck an einen Drittanbieter.
Die Lösung ganz ohne Codeänderungen besteht darin, auf IDE-Ebene zu filtern:
Für Befehle, die ein Agent in einem Terminal startet, schaltest du einen zeilengepufferten Filter zwischen den Prozess und den Agenten. Der Child-Prozess erhält weiterhin die echte Umgebung, API-Aufrufe funktionieren also, aber stdout und stderr werden Zeile für Zeile bereinigt, bevor irgendetwas sie liest.
Mit der TraceCloak-CLI (@tracecloak/core auf npm, Node 20+):
# Einmal installieren, oder dies überspringen und Befehle praefixieren mit: npx @tracecloak/core npm install -g @tracecloak/core # Teilweise Maskierung: sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890 -> sk_live_****7890 tracecloak run -- node scripts/fetch-stripe.js # Volle Shape-Maskierung, wenn ein KI-Agent die Ausgabe liest tracecloak run --mode=full -- curl -v https://api.example.com/auth # Flutter, plus ein eigener Schluesselname, den dein Backend verwendet tracecloak run --mode=full --keys=xyz_key -- flutter run Enter fullscreen mode Exit fullscreen mode Die CLI laedt zudem.env*- und local.properties-Werte transient im Speicher, sodass sie deine exakten Secrets erkennen kann, auch wenn sie nicht wie ein bekanntes Provider-Format aussehen.
IDE-Filter erfassen Konsolentext. Sie können nicht helfen, wenn ein Secret in einen KI-Prompt gelangt, den deine App selbst erzeugt, in einen Crash-Report oder in ein Dio-Log. Für diese Fälle verwende das Paket tracecloak auf pub.dev. Es ist reines Dart (ohne nativen Android- oder iOS-Code) und unter 60 KB komprimiert.
flutter pub add tracecloak Enter fullscreen mode Exit fullscreen mode Umschließe runApp, damit jedes print() innerhalb der Zone maskiert wird, einschließlich Ausgaben von Paketen, async Callbacks und Timern:
import 'package:flutter/material.dart'; import 'package:tracecloak/tracecloak.dart'; void main ( ) { TraceCloak. run ( ( ) => runApp ( const MyApp ( ) ) ); } // An beliebiger Stelle in der App: print ( 'Calling Stripe API with: sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890' ); // Debug Console: Calling Stripe API with: sk_live_****7890 Enter fullscreen mode Exit fullscreen mode Fuege den Dio-Interceptor hinzu. Er loggt eine bereinigte Kopie jedes Requests und laesst den echten Request unangetastet, sodass der Server weiterhin den originalen Authorization-Header erhaelt:
import 'package:dio/dio.dart'; import 'package:tracecloak/tracecloak.dart'; final dio = Dio ( ).. interceptors. add ( TraceCloak. dioInterceptor ( ) ); // Konsole: // [INFO] [DIO-REQ] --> POST https://api.stripe.com/v1/charges | // metadata: {headers: {Authorization: Bearer sk_live_****7890},...} Enter fullscreen mode Exit fullscreen mode Umschliesse langlebige Schluessel mit SecureKey, sodass String-Interpolation und jsonEncode nur jemals die Maske erzeugen:
final stripeKey = SecureKey ( 'sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890' ); print ( 'Config: $stripeKey' ); // Config: sk_live_****7890 jsonEncode ( { 'key': stripeKey } ); // {"key":"sk_live_****7890"} // Nur fuer den echten Netzwerk-Aufruf enthuellen: dio. options. headers [ 'Authorization' ] = 'Bearer ${stripeKey.exposeRaw()}'; Enter fullscreen mode Exit fullscreen mode Wenn deine App Debug-Zustand an ein LLM sendet (ein Support-Bot, ein In-App-Button "explain this error"), bereinige ihn zuerst:
final safePrompt = rawContext. aiSafe; // Strings final safeData = TraceCloak. aiSafe ( debugStateMap ); // Maps, Listen, Objekte Enter fullscreen mode Exit fullscreen mode Generiere abschliessend die Ignore-Dateien der Ebene 1 von der Kommandozeile aus:
dart run tracecloak --shield-ai # schreibt.aiignore,.aiexclude,.cursorignore usw. dart run tracecloak # durchsucht das Projekt nach hartcodierten Schluesseln (CWE-798), CI-freundlicher Exit-Code Enter fullscreen mode Exit fullscreen mode Zwei Einschraenkungen solltest du kennen. TraceCloak.run() fängt stdout.write, dart:developer log() oder Code in einem anderen Isolate nicht ab, es sei denn, du umschliesst auch den Einstiegspunkt dieses Isolates. Und TraceCloak.install() speichert nur Einstellungen; run() ist es, was print() abfaengt.
Standardmaessig (enableInRelease: false) ruft ein Release-Build dein body() direkt ohne Zone auf, und strukturierte Logs erzeugen keine Ausgabe. Die Pruefung verwendet kDebugMode, sodass der Dart-Compiler den Debug-Pfad per Tree-Shaking entfernen kann. Die Testsuite des Pakets verifiziert dies, indem sie ein Fixture im Release-Modus AOT-kompiliert. Explizite Aufrufe von redact() und aiSafe() behalten die Maskierung auch in Production bei, was genau das ist, was du fuer Prompts und Crash-Reports willst.
Die teilweise Maskierung behaelt ein bekanntes Provider-Praefix und die letzten Zeichen bei, sodass du beim Debuggen zwei Schluessel weiterhin unterscheiden kannst:
sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890 -> sk_live_****7890 Enter fullscreen mode Exit fullscreen mode Die volle Shape-Maskierung ersetzt jeden Buchstaben und jede Ziffer durch einen Klassen-Platzhalter und behaelt Trennzeichen bei:
sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890 -> aa_aaaa_00aa00aa0a0aa0aa0baaaaa0000000001 Enter fullscreen mode Exit fullscreen mode Der Platzhalter wird so gewaehlt, dass er nie dem Originalzeichen entspricht (ein a in der Eingabe wird zu b, eine 0 wird zu 1), und automatisierte Tests stellen fuer jede Regel 0 Prozent Zeichenueberschneidung zwischen Ein- und Ausgabe sicher. Verwende den vollen Modus fuer Screen-Shares, Demos und jede Ausgabe, die ein KI-Agent lesen wird. Die VS-Code-Erweiterung schaltet automatisch in den vollen Modus, wenn sie erkennt, dass Zoom, OBS oder Loom laeuft.
Die VS-Code-Erweiterung und das JetBrains-Plugin buendeln die Ebenen 1 bis 3 in einer Installation, ganz ohne Konfigurationsdatei:
code --install-extension tracecloak.tracecloak Enter fullscreen mode Exit fullscreen mode Erhaeltlich im VS Code Marketplace oder ueber Open VSX fuer Cursor, Windsurf und VSCodium. Fuer Android Studio und IntelliJ installiere TraceCloak - Secret Redaction aus dem JetBrains Marketplace.
Was du in VS Code bekommst, nach dem Namen im Command Palette:
Die Erkennung kombiniert Muster von Providern (Stripe, AWS, GitHub, Slack, Google, OpenAI, Anthropic, JWTs, PEM-Private-Keys, Datenbank-URIs), angelehnt an die MIT-lizenzierte Gitleaks-Regelmenge, mit einem Entropie-Fallback für unbekannte Token und exaktem Abgleich mit den Werten in Ihrer eigenen.env-Datei.
Wenn Sie bereits einen Secrets Manager betreiben, behalten Sie ihn. TraceCloak speichert nichts und kann daher ohne Konflikt neben einem Vault bestehen: Der Vault steuert, wo Secrets liegen, und TraceCloak steuert, was ausgegeben wird und was die KI lesen darf.
TraceCloak ist ein kostenloses, local-first Tool, das API-Keys, Tokens und Passwörter maskiert, bevor KI-Coding-Assistenten sie lesen können. Es erscheint als VS Code- und Open VSX-Erweiterung, als JetBrains-Plugin, als Flutter/Dart-Paket auf pub.dev und als npm-CLI. Es speichert keine Secrets und fügt den Release-Builds nichts hinzu.
Laut dem State of Secrets Sprawl 2026 Report von GitGuardian wiesen Claude Code unterstützte Commits auf öffentlichem GitHub im Jahr 2025 eine Leak-Rate bei Secrets von 3,2 Prozent auf, gegenüber einem Basiswert von 1,5 Prozent für alle öffentlichen Commits. Leaked Keys von KI-Diensten stiegen im selben Jahr um 81 Prozent, und die Gesamtzahl neuer hartcodierter Secrets wuchs um 34 Prozent auf 28,65 Millionen.
Erstellen Sie eine.cursorignore-Datei im Projektstammverzeichnis und tragen Sie.env,.env.* und *.env ein, zusätzlich zu weiteren Secret-Dateien wie local.properties oder google-services.json. Cursor schließt diese Dateien dann von der Indizierung und dem KI-Kontext aus. Der Befehl "Sync AI Guardrails" von TraceCloak schreibt und pflegt diese Datei automatisch für Sie.
Fügen Sie permissions.deny-Regeln zur.claude/settings.json hinzu, etwa Read(.env), Read(.env.*) und Read(**/local.properties). Diese blockieren die Read-, Edit- und Write-Tools von Claude Code für die betreffenden Dateien. Sie blockieren keine Shell-Befehle wie cat.env, ummanteln Sie daher agentengesteuerte Befehle zusätzlich mit tracecloak run --mode=full.
Der Ausgabestream des Debug Adapter Protocol wird abgefangen, bevor die Konsole ihn rendert. Ein DebugAdapterTracker kann den Text von OutputEvents an Ort und Stelle umschreiben und Keys maskieren, ohne Ihren Quellcode anzutasten. Die TraceCloak-Erweiterung tut dies für jede Sprache, mittels Provider-Mustern, Entropie-Erkennung und exaktem Abgleich mit den Werten in Ihren lokalen.env-Dateien.
CWE-798 ist der MITRE-Eintrag für Schwachstellen der Klasse hartcodierte Zugangsdaten: Passwörter, API-Keys oder Tokens, die direkt im Quellcode stehen. Mit KI-Coding-Assistenten ist das besonders relevant, weil der Assistent diesen Quellcode als Kontext liest und den Key an ein Cloud-Modell senden kann. Verlagern Sie solche Werte in die.env-Datei und scannen Sie nach Überbleibseln.
Nein..gitignore steuert nur, was Git verfolgt. KI-Editoren und Agenten lesen die Dateien auf der Festplatte, daher bleibt eine ignorierte.env-Datei für sie sichtbar. Jedes Tool braucht eine eigene Konfiguration:.cursorignore für Cursor,.aiignore für den JetBrains AI Assistant,.aiexclude für Gemini in Android Studio und permissions.deny für Claude Code.
Fügen Sie das Paket tracecloak hinzu und ummanteln Sie Ihre App mit TraceCloak.run(() => runApp(const MyApp())). Jedes print() innerhalb der Zone wird geschwärzt, einschließlich Ausgaben aus Paketen und asynchronen Callbacks. Für Netzwerk-Logs fügen Sie TraceCloak.dioInterceptor() zu Dio hinzu, wodurch die protokollierte Kopie maskiert wird, während der echte Authorization-Header an den Server gesendet wird.
Mit der Standardeinstellung enableInRelease: false überspringen Release-Builds die Zone vollständig, und TraceCloak.run() ruft Ihren Code direkt auf. Strukturierte Logs erzeugen keine Ausgabe. Das Gate nutzt kDebugMode, das der Dart-Compiler durch Tree-Shaking entfernen kann. Explizite redact()- und aiSafe()-Aufrufe funktionieren weiterhin, sodass Prompts und Crash-Reports in Produktion maskiert bleiben.
Nein. TraceCloak hält Secret-Werte nur für einen einzelnen Maskierungsdurchlauf im Speicher und schreibt überall nur maskierte Formen. In der Standardbuild-Variante tätigt es keine Netzwerkaufrufe. Das optionale Dashboard und der MCP-Server binden an 127.0.0.1 und verlangen ein zufälliges 32-Byte-Token, das pro Sitzung erzeugt wird.
Der Name lautet TraceCloak, wie beim Vermummen eines Traces oder einer Log-Zeile. Wer ihn laut hört, sucht oft nach "TraceClock", was auf dasselbe Projekt verweist. Das Flutter- und Dart-Paket finden Sie unter pub.dev/packages/tracecloak und die VS Code-Erweiterung, indem Sie in der Extensions-Ansicht nach "TraceCloak" suchen.
Ich bin Vinit Tailor, und ich habe TraceCloak gebaut, nachdem ich einmal zu oft einen Screen-Share mit offener.env-Datei erlebt hatte. Wenn Sie ein Key-Format entdecken, das fehlt, öffnen Sie ein Issue, und ich ergänze eine Regel.
Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.
Original (Englisch) anzeigen
You're debugging a failed Stripe charge in a Flutter app. You ask Cursor or Claude Code what went wrong, and the agent does the sensible thing: it reads the Debug Console, opens.env to check the config, and runs flutter run again to reproduce the error. In about ten seconds, your live secret key, a user's JWT, and the keystore password from key.properties have all been sent to a cloud model as prompt context.
None of this needs a bug in the AI tool. Agents read whatever is in the workspace and whatever your code prints. This guide covers the places keys leak during AI-assisted Flutter and web development, the config that closes each one, and how to automate the setup without moving your secrets into a vault.
GitGuardian's State of Secrets Sprawl 2026 report, published March 17, 2026, counted 28.65 million new hardcoded secrets in public GitHub commits in 2025. That is a 34% increase over 2024 and, according to GitGuardian, the largest single-year jump it has recorded. Several findings point at AI tooling directly:
"AI agents need local credentials to connect across systems, turning developer laptops into a massive attack surface," said Eric Fourrier, GitGuardian's CEO, in the report announcement.
Those numbers only count secrets committed to public repositories. The leaks below also include debug output, terminal sessions and chat prompts, which no repository scan ever sees.
Two weakness classes cover almost every case. CWE-798 is the use of hard-coded credentials. CWE-532 is sensitive information written to a log file. AI assistants make both worse because they read source files and log output as context, so a secret that only you used to see now reaches a third-party model.
In a typical Flutter project, the leaks come from five places:
Each AI tool reads its own ignore or deny config. You need one per tool your team uses.
For Cursor, JetBrains, and Gemini, a gitignore-style list works:
#.cursorignore (same content works for.aiignore and.aiexclude).env.env.* *.env local.properties key.properties google-services.json GoogleService-Info.plist *credentials*.json *secret*.json *.pem *.key *.p12 *.keystore *.jks Enter fullscreen mode Exit fullscreen mode Claude Code ignores those files. It uses permission rules in.claude/settings.json instead:
{ "permissions": { "deny": [ "Read(.env)", "Read(.env.*)", "Read(**/*.env)", "Read(**/key.properties)", "Read(**/local.properties)", "Read(**/google-services.json)", "Read(**/GoogleService-Info.plist)", "Read(**/*.keystore)", "Read(**/*.jks)", "Read(**/*.pem)", "Read(**/*.key)", "Edit(.env)", "Edit(.env.*)", "Write(.env)", "Write(.env.*)" ] } } Enter fullscreen mode Exit fullscreen mode These rules stop the Read, Edit, and Write tools. They don't stop an agent with shell access from running cat.env, which is why the next two layers matter even after this one is in place.
Your app still has to load the real key to call the API, and anything that prints it ends up in the console the agent reads. OWASP's Logging Cheat Sheet lists "Access tokens", "Authentication passwords", "Database connection strings" and "Encryption keys and other primary secrets" among data that "should usually not be recorded directly in the logs", and says it should instead be "removed, masked, sanitized, hashed, or encrypted". The Secrets Management Cheat Sheet is stricter: secrets should "Never be logged". When an AI agent reads your Debug Console, every logged key becomes a CWE-532 leak to a third party.
The fix with no code changes is to filter at the IDE layer:
For commands an agent launches in a terminal, put a line-buffered filter between the process and the agent. The child process still gets the real environment, so API calls succeed, but stdout and stderr are redacted line by line before anything reads them.
With the TraceCloak CLI ( @tracecloak/core on npm, Node 20+):
# Install once, or skip this and prefix commands with: npx @tracecloak/core npm install -g @tracecloak/core # Partial mask: sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890 -> sk_live_****7890 tracecloak run -- node scripts/fetch-stripe.js # Full shape-mask when an AI agent is reading the output tracecloak run --mode=full -- curl -v https://api.example.com/auth # Flutter, plus a custom key name your backend uses tracecloak run --mode=full --keys=xyz_key -- flutter run Enter fullscreen mode Exit fullscreen mode The CLI also loads.env* and local.properties values transiently, in memory, so it can match your exact secrets even when they don't look like a known provider format.
IDE filters catch console text. They can't help when a secret goes into an AI prompt your app builds, into a crash report, or through a Dio log. For those cases, use the tracecloak package on pub.dev. It's pure Dart (no Android or iOS native code) and under 60 KB compressed.
flutter pub add tracecloak Enter fullscreen mode Exit fullscreen mode Wrap runApp so every print() inside the zone is redacted, including prints from packages, async callbacks, and timers:
import 'package:flutter/material.dart'; import 'package:tracecloak/tracecloak.dart'; void main ( ) { TraceCloak. run ( ( ) => runApp ( const MyApp ( ) ) ); } // Anywhere in the app: print ( 'Calling Stripe API with: sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890' ); // Debug Console: Calling Stripe API with: sk_live_****7890 Enter fullscreen mode Exit fullscreen mode Add the Dio interceptor. It logs a sanitized copy of each request and leaves the real request alone, so the server still receives the genuine Authorization header:
import 'package:dio/dio.dart'; import 'package:tracecloak/tracecloak.dart'; final dio = Dio ( ).. interceptors. add ( TraceCloak. dioInterceptor ( ) ); // Console: // [INFO] [DIO-REQ] --> POST https://api.stripe.com/v1/charges | // metadata: {headers: {Authorization: Bearer sk_live_****7890},...} Enter fullscreen mode Exit fullscreen mode Wrap long-lived keys in SecureKey, so string interpolation and jsonEncode only ever produce the mask:
final stripeKey = SecureKey ( 'sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890' ); print ( 'Config: $stripeKey' ); // Config: sk_live_****7890 jsonEncode ( { 'key': stripeKey } ); // {"key":"sk_live_****7890"} // Unwrap only for the real network call: dio. options. headers [ 'Authorization' ] = 'Bearer ${stripeKey.exposeRaw()}'; Enter fullscreen mode Exit fullscreen mode If your app sends debug state to an LLM (a support bot, an in-app "explain this error" button), sanitize it first:
final safePrompt = rawContext. aiSafe; // strings final safeData = TraceCloak. aiSafe ( debugStateMap ); // maps, lists, objects Enter fullscreen mode Exit fullscreen mode Finally, generate the Layer 1 ignore files from the command line:
dart run tracecloak --shield-ai # writes.aiignore,.aiexclude,.cursorignore, etc. dart run tracecloak # scans the project for hardcoded keys (CWE-798), CI-friendly exit code Enter fullscreen mode Exit fullscreen mode Two limits to know about. TraceCloak.run() doesn't intercept stdout.write, dart:developer log(), or code in another isolate unless you wrap that isolate's entry point too. And TraceCloak.install() only stores settings; run() is what intercepts print().
By default ( enableInRelease: false ), a release build calls your body() directly with no zone, and structured logs produce no output. The check uses kDebugMode, so the Dart compiler can tree-shake the debug path out. The package's test suite verifies this by AOT-compiling a fixture in release mode. Explicit redact() and aiSafe() calls keep masking in production, which is what you want for prompts and crash reports.
Partial masking keeps a known provider prefix and the last few characters, so you can still tell two keys apart while debugging:
sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890 -> sk_live_****7890 Enter fullscreen mode Exit fullscreen mode Full shape-masking replaces every letter and digit with a class placeholder and keeps separators:
sk_live_51Hc29KJ8f3ks9fQ2ABCDEF1234567890 -> aa_aaaa_00aa00aa0a0aa0aa0baaaaa0000000001 Enter fullscreen mode Exit fullscreen mode The placeholder is chosen so it never equals the original character (an a in the input becomes b, a 0 becomes 1 ), and automated tests assert 0% character overlap between input and output for every rule. Use full mode for screen shares, demos, and any output an AI agent will read. The VS Code extension switches to full mode on its own when it detects Zoom, OBS, or Loom running.
The VS Code extension and JetBrains plugin bundle Layers 1 to 3 into one install, with no config file required:
code --install-extension tracecloak.tracecloak Enter fullscreen mode Exit fullscreen mode Get it from the VS Code Marketplace, or from Open VSX for Cursor, Windsurf, and VSCodium. For Android Studio and IntelliJ, install TraceCloak - Secret Redaction from the JetBrains Marketplace.
What you get in VS Code, by command palette name:
Detection combines provider patterns (Stripe, AWS, GitHub, Slack, Google, OpenAI, Anthropic, JWTs, PEM private keys, database URIs), adapted from the MIT-licensed Gitleaks ruleset, with an entropy fallback for unknown tokens and exact matching against values in your own.env.
If you already run a secrets manager, keep it. TraceCloak stores nothing, so it sits next to a vault without conflict: the vault controls where secrets live, and TraceCloak controls what gets printed and what the AI can open.
TraceCloak is a free, local-first tool that masks API keys, tokens and passwords before AI coding assistants can read them. It ships as a VS Code and Open VSX extension, a JetBrains plugin, a Flutter/Dart package on pub.dev, and an npm CLI. It stores no secrets and adds nothing to release builds.
According to GitGuardian's State of Secrets Sprawl 2026 report, Claude Code-assisted commits on public GitHub leaked secrets at a 3.2% rate in 2025, against a 1.5% baseline for all public commits. Leaked AI-service keys rose 81% the same year, and total new hardcoded secrets grew 34% to 28.65 million.
Create a.cursorignore file in the project root and list.env,.env.*, and *.env, plus any other secret files such as local.properties or google-services.json. Cursor then excludes those files from indexing and AI context. TraceCloak's "Sync AI Guardrails" command writes and maintains this file for you automatically.
Add permissions.deny rules to.claude/settings.json, such as Read(.env), Read(.env.*), and Read(**/local.properties). These block Claude Code's Read, Edit, and Write tools on matching files. They don't block shell commands like cat.env, so wrap agent-run commands with tracecloak run --mode=full as well.
Intercept the Debug Adapter Protocol output stream before the console renders it. A DebugAdapterTracker can rewrite OutputEvent text in place, masking keys without touching your source code. The TraceCloak extension does this for any language, using provider patterns, entropy detection, and exact matches against values in your local.env files.
CWE-798 is the MITRE weakness entry for hard-coded credentials: passwords, API keys, or tokens written directly into source code. With AI coding assistants it matters more, because the assistant reads that source as context and can send the key to a cloud model. Move such values into.env and scan for leftovers.
No..gitignore only controls what Git tracks. AI editors and agents read the files on disk, so an ignored.env is still visible to them. Each tool needs its own config:.cursorignore for Cursor,.aiignore for JetBrains AI Assistant,.aiexclude for Gemini in Android Studio, and permissions.deny for Claude Code.
Add the tracecloak package and wrap your app with TraceCloak.run(() => runApp(const MyApp())). Every print() inside the zone is redacted, including prints from packages and async callbacks. For network logs, add TraceCloak.dioInterceptor() to Dio, which masks the logged copy while sending the real Authorization header to the server.
With the default enableInRelease: false, release builds skip the zone entirely and TraceCloak.run() calls your code directly. Structured logs produce no output. The gate uses kDebugMode, which the Dart compiler can tree-shake. Explicit redact() and aiSafe() calls keep working, so prompts and crash reports stay masked in production.
No. TraceCloak holds secret values in memory only for a single redaction pass and writes only masked forms anywhere. It makes no network calls in its default build. The optional dashboard and MCP server bind to 127.0.0.1 and require a random 32-byte token generated for each session.
The name is TraceCloak, as in cloaking a trace or log line. People who hear it spoken often search for "TraceClock", which points to the same project. You can find the Flutter and Dart package at pub.dev/packages/tracecloak and the VS Code extension by searching "TraceCloak" in the Extensions view.
I'm Vinit Tailor, and I built TraceCloak after one too many screen shares with a.env file open. If you find a key format it misses, open an issue and I'll add a rule.