Protect secrets from leaking on stream when using Claude Code on Twitch/YouTube.
Uses Claude Code hooks to intercept tool calls and block secret exposure before it reaches the screen.
# Install globally
npm install -g stream-leak-guard
# Set up hooks in Claude Code
stream-leak-guard init
# Start streaming safely
claudeThree Claude Code hooks work together:
- SessionStart — Injects safety instructions into Claude's context so it avoids outputting secrets in its text responses
- PreToolUse (Bash, Read, Write, Edit) — Blocks dangerous commands and scans for secret values before any tool executes
- PostToolUse (Bash, Read, Write, Edit) — Scans tool output after execution and redacts any secret values or patterns before they reach the conversation context
Dangerous commands:
env,printenv(without arguments) — dump all environment variablesexport -p,set,declare -p— list all shell/exported variablescat .env,head .env.local, etc. — read env files directlysource .env,. .env— source env filesecho $SECRET_KEY,echo $API_KEY— print known secret variable namesgrep/rg/ag/egrep/fgreptargeting.envfilesawk/sed/cut/sort/tr/wc/tee/xargs/stringstargeting.envfiles- Inline code execution accessing
.envfiles (node -e,python -c,ruby -e) - Any command with
.envfile arguments (cp .env /tmp/,diff .env .env.bak, etc.)
Secret values detected by:
- Exact matching — Loads actual values from
.envfiles and matches against command/content text - Pattern matching — Regex patterns for known secret formats (AWS keys, GitHub tokens, API keys, etc.)
Sensitive file reads:
.env,.env.*filescredentials.json,*.pem,*.key,id_rsa,id_ed25519.npmrc,.pypirc
If a secret value or known pattern slips through in tool output (e.g. a command prints a database URL, or a file read includes an API key), the PostToolUse hook replaces it with [REDACTED:VAR_NAME] before the output is shown. This covers:
- Exact value matching — Any value loaded from
.envfiles - Pattern matching — Known secret formats (AWS keys, GitHub tokens, private keys, database URLs, etc.)
- Custom patterns — Any additional patterns defined in your
.streamguardrc.json
Large outputs (>1MB) skip regex pattern scanning for performance but still perform exact value redaction.
Everything else. Normal commands (npm test, ls, git status, node app.js) flow through unimpeded. The guard only blocks truly dangerous operations and commands containing literal secret values.
Create a .streamguardrc.json in your project root to customize behavior:
{
"enabled": true,
"envFiles": [".env", ".env.local", ".env.development", ".env.production"],
"sensitiveFiles": [".env", ".env.*", "credentials.json", "*.pem", "*.key"],
"customPatterns": [],
"allowedCommands": [],
"minSecretLength": 8,
"safeEnvPrefixes": ["PUBLIC_", "NEXT_PUBLIC_", "VITE_", "REACT_APP_", "EXPO_PUBLIC_"],
"verbose": false
}Run stream-leak-guard init to create an example config file.
| Option | Default | Description |
|---|---|---|
enabled |
true |
Enable/disable the guard |
envFiles |
[".env", ".env.local", ...] |
Files to load secret values from |
sensitiveFiles |
[".env", ".env.*", ...] |
File patterns to block reading |
customPatterns |
[] |
Additional regex patterns [{ regex, name }] |
allowedCommands |
[] |
Commands to always allow (bypass blocking) |
minSecretLength |
8 |
Minimum value length to treat as a secret |
safeEnvPrefixes |
["PUBLIC_", ...] |
Env var prefixes that are safe (skipped during scanning) |
verbose |
false |
Enable verbose logging to stderr |
- AWS Access Keys (
AKIA...) - GitHub Tokens (
ghp_,github_pat_,gho_,ghu_,ghs_,ghr_) - Anthropic API Keys (
sk-ant-) - OpenAI API Keys (
sk-proj-,sk-...) - Slack Tokens (
xoxb-,xoxp-) and Webhook URLs - Stripe Keys (
sk_live_,rk_live_) - Google API Keys (
AIza...) - npm Tokens (
npm_...) - Private Keys (
-----BEGIN ... PRIVATE KEY-----) - Database URLs with passwords (
postgres://user:pass@host) - Discord Bot Tokens
- Twilio API Keys (
SK...) - SendGrid API Keys (
SG....) - Vercel Tokens
- Supabase Service Role Keys
- JWTs (in assignment context)
stream-leak-guard init # Set up hooks in ~/.claude/settings.json
stream-leak-guard status # Check if hooks are configured
stream-leak-guard disable # Remove hooks from settings- Zero dependencies — No supply chain risk. Uses only Node.js built-ins.
- Fail-open — If the guard errors, development continues (exit 1 is non-blocking).
- Value-to-name mapping — Error messages say "Found DATABASE_URL" not the actual value.
- Safe env prefixes — Framework-designated public values (
NEXT_PUBLIC_,VITE_, etc.) are skipped. - Bun-first, Node-compatible —
#!/usr/bin/env nodeshebang works everywhere. Bun users get faster hook startup.
# Run tests
bun testMIT