@@ -34,16 +34,19 @@ go build ./aihook
3434
3535## Usage
3636
37- ### Stop Hook
37+ ### Shell Hook
3838
39- The ` stop ` subcommand validates shell scripts and ensures all ` cd ` commands are executed within subshells:
39+ The ` shell ` subcommand validates shell scripts and ensures all ` cd ` commands are executed within subshells:
4040
4141``` bash
4242# Check a shell script from stdin
43- echo ' cd /tmp' | aihook stop
43+ echo ' cd /tmp' | aihook shell
4444
4545# With Claude Code hook format output
46- echo ' cd /tmp' | aihook stop --claude
46+ echo ' cd /tmp' | aihook shell --claude
47+
48+ # Block execution when cd violations are found
49+ echo ' cd /tmp' | aihook shell --claude --block-on-cd
4750```
4851
4952### Examples
@@ -58,10 +61,15 @@ cd /tmp && ls
5861(cd /tmp && ls)
5962```
6063
64+ ### Flags
65+
66+ - ` --claude ` : Output in JSON format compatible with Claude Code hooks
67+ - ` --block-on-cd ` : When set, returns exit code 2 for violations (blocks execution). Without this flag, violations are reported but execution is not blocked (exit code 0)
68+
6169### Exit Codes
6270
63- - ` 0 ` : No violations found
64- - ` 2 ` : Violations detected (cd commands outside subshells)
71+ - ` 0 ` : No violations found (or violations found but ` --block-on-cd ` not set)
72+ - ` 2 ` : Violations detected and ` --block-on-cd ` flag is set
6573- ` 1 ` : Parse error or other failure
6674
6775### Output Formats
@@ -97,7 +105,7 @@ To use `aihook` as a Claude Code PreToolUse hook that validates Bash commands, a
97105 "hooks" : [
98106 {
99107 "type" : " command" ,
100- "command" : " aihook stop --claude"
108+ "command" : " aihook shell --claude --block-on-cd "
101109 }
102110 ]
103111 }
@@ -110,7 +118,8 @@ The hook will:
110118- Match any Bash tool invocation (via the ` "Bash" ` matcher)
111119- Receive the bash command script on stdin
112120- Validate that all ` cd ` commands are in subshells
113- - Return exit code 0 to allow, or exit code 2 to block with error message
121+ - With ` --block-on-cd ` : Return exit code 2 to block execution when violations are found
122+ - Without ` --block-on-cd ` : Report violations but allow execution (exit code 0)
114123- Use ` --claude ` flag to output in the expected JSON format
115124
116125For more flexible matching, you can use regex patterns like ` "Bash.*cd" ` to only check Bash commands containing ` cd ` .
0 commit comments