Why this rule
Agent hook configurations run shell commands automatically on events like file save or tool use. A destructive or injection-vulnerable hook fires without explicit user action — in an agent session, the agent may trigger it indirectly through file writes. Because hooks execute outside the agent’s visible reasoning loop, a compromised hook can cause irrecoverable damage — deleted files, elevated permissions, or remote code execution — before any human has a chance to intervene.What triggers it
Charter scans agent hook configuration files —.claude/settings.json and .claude/settings.local.json for Claude Code, and .cursor/hooks.json for Cursor — and inspects every command declared across all hook events.
It flags commands that fall into three danger classes:
| Danger class | Examples | Why dangerous |
|---|---|---|
| Shell injection | $(), backticks, && with open input | Agent-controlled input can execute arbitrary commands |
| Destructive commands | rm -rf, git reset --hard, git clean -fd | Irrecoverable file loss triggered automatically |
| Privilege escalation | sudo, chmod 777, chown -R | Elevates permissions beyond intended scope |
Examples
- Failing
- Passing
A hook command using A hook elevating permissions is also flagged:
rm -rf with a shell-expanded path — destructive and flagged Blocker:.claude/settings.json
.claude/settings.json
How to fix
Locate the flagged hook
Run
charter explain AE-CC-001 to see the finding evidence. Charter identifies the config file and the offending command pattern.Replace the dangerous pattern
Substitute destructive or injection-vulnerable commands with explicit, scoped, non-destructive alternatives. Prefer array-form execution (
args) over shell strings to avoid expansion.Review against the injection model
For each hook, ask: “If an agent were prompt-injected, could this hook be weaponized?” If yes, redesign the command to be safe regardless of what the agent does.
Score impact
Blocker — engages the hard blocker score cap. The final score is capped at ≤ 59 whenever any Blocker finding is present, regardless of other findings.
Edge cases
Hook managers out of scope for v1
Hook managers out of scope for v1
Only the three JSON hook files are scanned in v1.
hk.pkl, .pre-commit-config.yaml, lefthook.yml, and .husky/ shell-dir hooks are out of scope and not evaluated.Controlled && chains
Controlled && chains
A controlled
&& chain where both sides are safe (e.g. cd app && npm test) is not flagged — operator chaining is only flagged when the left-hand side accepts open or agent-controlled input.Malformed JSON hook files
Malformed JSON hook files
A hook file that cannot be parsed fails the scan fast with a wrapped error. Charter surfaces the parse failure rather than silently passing the file.
Related rules
AE-CC-002
Requires explicit edit-scope boundaries in the agent context file.
AE-SEC-001
Detects hardcoded secrets in tracked files.