Rules and a pre-commit hook to catch placeholders and secrets in AI-written code
Vibe coding securely: placeholders and secrets
Rules to add to your agent's instruction file (AGENTS.md, CLAUDE.md, or your rules file), plus a pre-commit hook that enforces them. The rules guide the agent. The hook catches what slips through.
1. Add these rules to your agent's instruction file
Placeholders
- Never ship incomplete code or skip a security check
- If you can't complete a security check, deny access by default and tell me
- Never leave TODO or FIXME comments in authentication, authorization, payment, or access control code
- Never write a function that returns true or skips validation as a temporary stand-in
Secrets
- Read secrets only from environment variables
- Never write a key, token, or password into code, config files, or tests
- Never put secrets or privileged API keys in frontend code
- When a new secret is needed, add a placeholder to .env.example and tell me
2. Add a pre-commit hook
Save as .git/hooks/pre-commit and make it executable with chmod +x .git/hooks/pre-commit. Adjust SENSITIVE_PATHS to match your repo.
#!/usr/bin/env bash
set -euo pipefail
# Paths that hold security-sensitive code. Adjust for your repo.
SENSITIVE_PATHS='auth|payment|billing|permission|access'
# Common secret patterns. A backstop, not a replacement for a dedicated secret scanner.
SECRET_PATTERN="AKIA[0-9A-Z]{16}|-----BEGIN [A-Z ]*PRIVATE KEY-----|(api[_-]?key|secret|token|passw(or)?d)[[:space:]]*[:=][[:space:]]*[\"'][^\"']{8,}"
fail=0
staged=$(git diff --cached --name-only --diff-filter=ACM)
# 1. Block .env files (allows .env.example)
if echo "$staged" | grep -E '(^|/)\.env(\..+)?