[FEATURE] Security: approved bash command that run scripts should check the script hash
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
In order to improve agent independence while at the same time trying to avoid giving blanket permissions to claude, I usually allow claude to run pre-approved scripts. This is usually the difference between having the agent work independently for 5-10 minutes vs. having the agent run independently for half an hour or longer without the need for aggressive sandboxing and dangerous permission skips.
There is the remnant risk that the agent will edit the pre-approved scripts independently and then run whatever bash command comes to mind. This doesnt happen in short runs with clean context, however this might happen on very long sesions with context overrun, especially when claude rabbit holes into debugging a hallucinated issue.
Proposed Solution
Bash permissions that involve running scripts with direct invocation like this "./my-script.sh" should, when giving claude permanent permission to run the command, remember the sha-hash of the script at the time the permission was given. Subsequent auto-allows should only trigger, if the hash of the invoked script matches the approved hash, otherwise it is treated as an unknown command and claude must ask for permission.
Alternative Solutions
Using scripts that cant be edited by claude via ACL. This doesnt work well because the script could be moved, if claude has permission to the directory, and a new script with the same name can be created in the same place.
Priority
Low - Nice to have
Feature Category
Other
Use Case Example
_No response_
Additional Context
_No response_
5 Comments
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Good idea. The core risk here — agent edits a pre-approved script and then runs it — is a form of TOCTOU (time-of-check, time-of-use) vulnerability. The permission was granted for script-at-hash-X, but the agent executes script-at-hash-Y.
Until hash-pinning is built into Claude Code's permission system, you can approximate this with a PreToolUse hook today:
Add to
.claude/settings.json:Exit code 2 = hard block that the model can't override.
For a more comprehensive approach, sentinel-ai's
sentinel hookscans every Bash command for dangerous patterns (rm -rf, credential access, data exfiltration) at ~0.05ms latency — complements hash-pinning by catching cases where the agent bypasses scripts entirely and uses inline commands.Smart concern — the model could edit a pre-approved script to inject arbitrary commands, then run the "approved" script. You can enforce script integrity with hooks today:
1. PreToolUse hook that verifies script hashes before execution:
2. Auto-generate the hash file at session start:
Then the PreToolUse hook checks against
/tmp/.claude-script-hashes:3. Protect scripts from modification (belt and suspenders):
This gives you: hash verification before execution + modification prevention + session-start baseline. The model can run pre-approved scripts but cannot modify them and cannot run modified versions.
I actually found a much cleaner solution: Write skills that invoke scripts within the skills directory. Accept all edits does not grant access to the .claude directory, so there is no risk to overwrite scripts after approval.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.