* fix(shellcheck): declare and assign separately in router.sh (SC2155) * feat(plugin): enhance context management and skill invocation - Update .context-manifest.json to include profile and detailed source information. - Revise context-scout.md to clarify context root discovery and navigation. - Modify commands to replace deprecated skills with updated ones (brainstorming → approach, systematic-debugging → debugger). - Streamline install-context.md for clarity and remove interactive profile selection. - Improve oac-status.md to provide a more comprehensive status report. - Add OAC system paths to session-start.sh for better context management. - Remove obsolete skills and improve documentation for existing commands.
1.6 KiB
1.6 KiB
File Protection Hook
Purpose: Block edits to sensitive files
Configuration
{
"hooks": {
"PreToolUse": [{
"matcher": "Edit|Write",
"hooks": [{
"type": "command",
"command": "python3 -c \"import json, sys; data=json.load(sys.stdin); path=data.get('tool_input',{}).get('file_path',''); sys.exit(2 if any(p in path for p in ['.env', 'package-lock.json', '.git/']) else 0)\""
}]
}]
}
}
How It Works
- Triggers BEFORE Edit or Write tool executes
- Reads file path from JSON input
- Checks against protected patterns
- Exit code 2 blocks the operation
- Claude receives feedback about blocked file
Protected Patterns
Default patterns to block:
.env- Environment secretspackage-lock.json- Dependency locks.git/- Git internalscredentials.json- API keys*.pem,*.key- Private keys
Custom Protection Script
#!/usr/bin/env python3
import json, sys
PROTECTED = ['.env', 'package-lock.json', '.git/',
'credentials', '.pem', '.key', 'secrets']
data = json.load(sys.stdin)
path = data.get('tool_input', {}).get('file_path', '')
if any(p in path for p in PROTECTED):
print(f"Blocked: {path} is protected", file=sys.stderr)
sys.exit(2)
sys.exit(0)
Related
../../lookup/hook-events.md- Hook events reference./formatting-hook.md- Auto-format example
Reference: https://docs.anthropic.com/en/docs/claude-code/hooks