mirror of
https://github.com/luongnv89/claude-howto.git
synced 2026-04-26 09:56:01 +02:00
34259caf7c
The squash merge of PR #49 discarded two review fix commits. Re-applying: - security-scan.sh: wrap output in hookSpecificOutput (PostToolUse protocol); restore secret/token detection; fix JSON newline escaping; escape file path - validate-prompt.sh: try "user_prompt" field first, fall back to "prompt" - log-bash.sh: document sed truncation limitation for quoted commands - format-code.sh: fix misleading comment about updatedInput output
32 lines
918 B
Bash
32 lines
918 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
|
|
# Note: sed [^"]* stops at escaped quotes in JSON; for commands with double-quoted
|
|
# strings, only the portion up to the first \" will be captured — this is a known
|
|
# limitation of sed-based JSON parsing and is acceptable for logging purposes.
|
|
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
|