PreCommitSanitize
Skill10 starsChanged 5 months agoMITView on GitHub
Scan staged files for hardcoded home paths, personal identifiers, symlinks, and runtime state before committing to the ~/.claude repo. USE WHEN staging or committing in ~/.claude, or before pushing a dotfiles/config repo to a public GitHub remote.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- hooks/CLAUDE.mdCLAUDE.md
- WorkflowGuideSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Before every git add or git commit in ~/.claude, scan staged files for sensitive personal information that should not be pushed to a public …
- Very specific: line 72
If any of these appear in git status as tracked, run git rm --cached <file> and add to .gitignore.
- Distinctive: line 76
Before staging, run this scan on all files being committed:
- Distinctive: line 83
If matches are found:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pre-Commit Sanitization
When This Applies
Before every git add or git commit in ~/.claude, scan staged files for sensitive personal information that should not be pushed to a public GitHub repository.
What to Catch
Hardcoded Home Paths
Any absolute path containing a username or home directory:
| Pattern | Example | Fix |
/Users/<username>/ | /Users/jane/.claude/hooks/... | ~/.claude/hooks/... |
/home/<username>/ | /home/deploy/.claude/... | ~/.claude/... |
C:\Users\<username>\ | C:\Users\jane\... | ~\.claude\... |
Exception: .gitignore rules may use relative paths that are fine.
Personal Identifiers
| Pattern | Example | Action |
| Email addresses | jane@gmail.com | Remove or replace with user@example.com |
| Social media handles | linkedin.com/in/<handle> | Remove unless intentionally public (README author section) |
| Machine hostnames | <Name>-MacBook-Pro.local | Remove |
| Usernames in paths | username embedded in file content | Replace with ~ or $HOME |
Exception: README.md author/contact section may intentionally include social links — confirm before removing.
Symlinks
Rule: No symlink inside ~/.claude/ may be committed to git.
Symlinks are always machine-specific — they point to absolute paths on the local filesystem that don't exist on other machines. Committing them breaks clones and leaks personal paths.
| Action | When |
Add to .gitignore under # Symlinks section | When creating any new symlink inside ~/.claude/ |
Run git rm --cached <path> | If a symlink was accidentally tracked |
The hooks/git/pre-commit hook auto-detects and blocks staged symlinks (git mode 120000) and adds them to .gitignore automatically. This is a safety net — always add manually first.
Pattern for .gitignore:
# Symlinks (local-only, machine-specific — never commit symlinks to shared tools)
# Rule: ANY symlink inside ~/.claude/ must be listed here.
skills/MySkilLinkRuntime State Files
Files that are managed by Claude Code at runtime and should not be version-controlled:
| File/Pattern | Why |
plugins/installed_plugins.json | Contains absolute install paths with username |
plugins/known_marketplaces.json | Contains absolute install paths with username |
plugins/install-counts-cache.json | Runtime cache |
security_warnings_state_*.json | Session-specific state |
stats-cache.json | Runtime cache |
settings.json.bak | Backup file |
*.db, *.db-shm, *.db-wal | Database files |
history.jsonl | Session history |
If any of these appear in git status as tracked, run git rm --cached <file> and add to .gitignore.
How to Check
Before staging, run this scan on all files being committed:
# Check for hardcoded home paths in staged files
git diff --cached --name-only | xargs grep -n '/Users/\|/home/\|C:\\Users\\' 2>/dev/nullIf matches are found:
- For
settings.jsonhook commands — these require absolute paths (Claude Code limitation). Addsettings.jsonto.gitignoreif it contains paths, or accept this as a known trade-off and document it. - For all other files — replace with
~/.claude/or$HOME/.claude/. - For comments/docs — use
~/.claude/notation.
Automated Enforcement
The hooks/git/pre-commit hook runs bunx varlock scan --staged for secret detection. For path sanitization, manually verify before committing or add a grep check to the pre-commit hook:
# Add to hooks/git/pre-commit after varlock scan
if git diff --cached --name-only | xargs grep -l '/Users/' 2>/dev/null | grep -v 'settings.json' | grep -qv '.gitignore'; then
echo "[pre-commit] WARNING: Hardcoded /Users/ paths found in staged files" >&2
git diff --cached --name-only | xargs grep -n '/Users/' 2>/dev/null | grep -v 'settings.json' | grep -v '.gitignore' >&2
echo "[pre-commit] Replace with ~/.claude/ before committing" >&2
exit 1
fiKnown Trade-offs
settings.json hook commands require absolute paths — Claude Code does not expand ~ or $HOME in hook command strings. Options:
- Gitignore settings.json — loses version control on hook config
- Accept the path leak — username visible but not a security risk
- Use env var in a wrapper — hook commands call a shell script that resolves
$HOME
Current decision: keep settings.json tracked, accept that the username is visible. The file contains no secrets — only hook wiring with absolute paths.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

