A security starter pack for Claude Code beginners — CLAUDE.md rules + pre-built hooks that prevent credential leaks before they happen.
Claude Code sends file contents to Anthropic servers whenever it reads a file. By default there are no guardrails — nothing stops it from reading your .env, .clasprc.json, or any file with "secret" in the name if you (or Claude) accidentally ask it to.
This pack closes those gaps with:
CLAUDE.mdrules — instructions that tell Claude what not to touch, including Bash-based workarounds (becausecat .envleaks just as much asRead .env)block_sensitive_readhook — a hard OS-level block on the Read tool before Claude can even trypre_push_safetyhook — scans everygit pushfor 25+ API key patterns before anything leaves your machine
This repo ships with a CLAUDE.md that tells Claude Code how to install everything. The easiest way:
git clone https://github.com/<YOUR_USERNAME>/claude-code-security-starter
cd claude-code-security-starter
claude # open Claude Code in this directoryThen just say: "幫我安裝" or "install this" — Claude will copy the hooks, configure your forbidden directories, and merge the settings for you.
# 1. Copy hooks
mkdir -p ~/.claude/hooks
cp hooks/block_sensitive_read.sh ~/.claude/hooks/
cp hooks/pre_push_safety.sh ~/.claude/hooks/
chmod +x ~/.claude/hooks/*.sh
# 2. Edit your forbidden directories
nano ~/.claude/hooks/block_sensitive_read.sh # fill in FORBIDDEN_DIRS
# 3. Merge settings.example.json into ~/.claude/settings.json
# 4. Copy and adapt the CLAUDE.md template to your project
cp CLAUDE.md.template /path/to/your/project/CLAUDE.md
# Replace all <PLACEHOLDER> values| File | Purpose |
|---|---|
CLAUDE.md.template |
Security rules to paste into your project's CLAUDE.md |
hooks/block_sensitive_read.sh |
Blocks the Read tool on .env, credentials, and your custom forbidden paths |
hooks/pre_push_safety.sh |
Scans git push for 25+ API key / token regex patterns |
settings.example.json |
Claude Code hook wiring (merge into settings.json) |
- Any path you add to
FORBIDDEN_DIRS(e.g. your~/secrets/folder) - Any filename you add to
FORBIDDEN_FILES .envand.env.*.clasprc*(Google clasp OAuth tokens)credentials.json,service-account.json- Any filename containing
secret,credential,token, orkey
Regex patterns for: AWS, Google API, Anthropic, OpenAI, GitHub, GitLab, Stripe, SendGrid, Twilio, Slack, HuggingFace, Perplexity, Replicate, npm, Telegram Bot, HashiCorp Vault, PEM private keys, database connection strings (MongoDB, PostgreSQL, MySQL), and generic api_key = "..." patterns.
Claude Code hooks are shell scripts that run at defined lifecycle events. A hook that exits with code 2 blocks the tool call and feeds the output back to Claude as context.
PreToolUse → hook runs → exit 2 → tool call cancelled
→ exit 0 → tool call proceeds normally
More on hooks: https://code.claude.com/docs/hooks
MIT