- Replace `grep -P` (Perl regex) with `sed` for JSON field extraction, as Windows Git Bash does not support `grep -P` - Replace positional arg (`$1`) with stdin JSON parsing to match the actual Claude Code hook protocol (hooks receive data via stdin, not args) - Fix JSON double-quote escaping in grep patterns that silently fails on Windows Git Bash - Remove python3 dependency for JSON parsing, making scripts portable - Add Windows Git Bash to compatibility notes in script headers Affected scripts: security-scan.sh, validate-prompt.sh, log-bash.sh, format-code.sh Co-authored-by: Bruce <binyuli1993@foxmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
672 B
Bash
29 lines
672 B
Bash
#!/bin/bash
|
|
# Log all bash commands
|
|
# Hook: PostToolUse:Bash
|
|
#
|
|
# Reads the executed command from stdin JSON and logs it to a file.
|
|
#
|
|
# Compatible with: macOS, Linux, Windows (Git Bash)
|
|
|
|
# Read JSON input from stdin (Claude Code hook protocol)
|
|
INPUT=$(cat)
|
|
|
|
# Extract the bash command from tool_input
|
|
COMMAND=$(echo "$INPUT" | sed -n 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)
|
|
|
|
if [ -z "$COMMAND" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
|
|
LOGFILE="$HOME/.claude/bash-commands.log"
|
|
|
|
# Create log directory if it doesn't exist
|
|
mkdir -p "$(dirname "$LOGFILE")"
|
|
|
|
# Log the command
|
|
echo "[$TIMESTAMP] $COMMAND" >> "$LOGFILE"
|
|
|
|
exit 0
|