How to Stop AI Coding Agents From Leaking Your API Keys | Vibe Coding Ep. 2
Your AI coding agent can read, copy, and send any secret you paste into the chat. In episode 2 of Vibe Coding, I block a leaked OpenAI API key with ggshield AI hooks and a pre-commit hook, then try to leak it again to see what happens.
Last episode, I promised we'd catch my hardcoded key before it left my laptop. Bad news: it already had.
What you'll learn:
- Why secrets sprawl isn't just a code problem once an AI agent is in the loop
- How AI hooks scan prompts, tool calls, and tool outputs for secrets in Claude Code, Cursor, Copilot, and more
- How prompt injection can trick an agent into reading your.env file
- Why MCP config files leak secrets, and where those secrets belong instead
- How a pre-commit hook stops secrets before they reach git
- What to do if a key already leaked: revoke it first
Set it up in two commands:
ggshield auth login
ggshield machine setup
By the numbers (State of Secrets Sprawl 2026):
- 1.27M AI-service secrets leaked in 2025, up 81% year over year
- 24,008 unique secrets found in public MCP config files in 2025
- 64% of secrets confirmed valid in 2022 were still exploitable in 2026
Chapters:
0:00 My API key already leaked
0:18 Secrets sprawl isn't just a code problem
0:51 Door 1: AI hooks inside the agent
1:20 Set up ggshield in two commands
1:40 Pasting the key again: blocked
1:47 Prompt injection and your.env file
2:10 Secrets in MCP config files
2:40 Door 2: the pre-commit hook
3:06 Already leaked? Revoke the key
3:29 Recap
3:44 Next episode: insecure code
Resources:
Set up AI hooks: https://docs.gitguardian.com/ggshield-docs/integrations/ai-coding-tools/secret-scanning-for-ai-coding-tools
State of Secrets Sprawl 2026: https://blog.gitguardian.com/the-state-of-secrets-sprawl-2026/
Next up: insecure code. Subscribe so you don't miss it.
#vibecoding #aicoding #claudecode #cursor #copilot