cd /news/ai-agents/rules-and-a-pre-commit-hook-to-catch… · home › topics › ai-agents › article
[ARTICLE · art-153325] src=gist.github.com ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Rules and a pre-commit hook to catch placeholders and secrets in AI-written code

A developer published a set of agent instruction rules and a pre-commit hook for catching placeholders and leaked secrets in AI-written code. The rules direct coding agents to avoid TODO/FIXME markers and hardcoded returns in authentication, authorization, payment, and access-control code, and to read secrets only from environment variables. The accompanying bash hook blocks staged .env files, flags placeholders in sensitive paths, and scans added lines for common secret patterns, with the caveat that git hooks are local and should be mirrored in CI.

by read2 min views1 publishedOct 19, 2026

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.

  • 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

  • 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

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

SENSITIVE_PATHS='auth|payment|billing|permission|access'

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)

if echo "$staged" | grep -E '(^|/)\.env(\..+)?$' | grep -vq '\.example$'; then
  echo "Blocked: a .env file is staged. Add it to .gitignore."
  fail=1
fi

sensitive=$(echo "$staged" | grep -Ei "$SENSITIVE_PATHS" || true)
if [ -n "$sensitive" ]; then
  if git diff --cached -U0 -- $sensitive | grep -E '^\+[^+]' \
     | grep -Ei 'TODO|FIXME|return[[:space:]]+true[[:space:]]*;?[[:space:]]*$'; then
    echo "Blocked: placeholder or hardcoded return in security-sensitive code."
    fail=1
  fi
fi

if git diff --cached -U0 | grep -E '^\+[^+]' | grep -Ei -e "$SECRET_PATTERN"; then
  echo "Blocked: possible secret in staged changes."
  fail=1
fi

if [ "$fail" -ne 0 ]; then
  echo "Commit blocked. Fix the issues above. If it's a false positive, adjust the patterns in this hook."
  exit 1
fi

Git hooks are local and aren't shared when someone clones the repo. Run the same checks in CI so they apply to everyone.

.env
.env.*
!.env.example
  1. Rotate it immediately. Deleting it from the code doesn't remove it from git history.
  2. Check the provider's logs for any use of the leaked key.
  3. Remove it from git history if the repo is shared or public.
  4. Add the pattern to your hook so it can't happen again.
── more in #ai-agents 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/rules-and-a-pre-comm…] indexed:0 read:2min 2026-10-19 · —