From 666e0fcb5ad3f5f0f56e1219e8cf03d44e62a49a Mon Sep 17 00:00:00 2001 From: Donchitos <150119193+Donchitos@users.noreply.github.com> Date: Fri, 10 Apr 2026 20:28:38 +1000 Subject: [PATCH] =?UTF-8?q?Fix=20log-agent=20hooks=20reading=20wrong=20fie?= =?UTF-8?q?ld=20=E2=80=94=20audit=20trail=20always=20logged=20"unknown"=20?= =?UTF-8?q?(#21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both SubagentStart/SubagentStop hooks were extracting `.agent_name` from the hook payload, but Claude Code emits the agent name in `agent_type`. This caused every audit log entry to fall through to the "unknown" fallback, making the entire agent audit trail useless. Fix: swap `.agent_name` -> `.agent_type` in both the jq path and the grep/sed fallback for systems without jq. Log output format is unchanged so existing audit logs remain valid. Bug reported and fix authored by @bobloy in issue #20: https://github.com/Donchitos/Claude-Code-Game-Studios/issues/20 Co-authored-by: Claude Sonnet 4.6 --- .claude/hooks/log-agent-stop.sh | 13 +++++++++---- .claude/hooks/log-agent.sh | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.claude/hooks/log-agent-stop.sh b/.claude/hooks/log-agent-stop.sh index 5c7bf07..afbd281 100644 --- a/.claude/hooks/log-agent-stop.sh +++ b/.claude/hooks/log-agent-stop.sh @@ -2,16 +2,21 @@ # Claude Code SubagentStop hook: Log agent completion for audit trail # Tracks when agents finish and their outcome # -# Input schema (SubagentStop): -# { "agent_id": "agent-abc123", "agent_name": "game-designer", ... } +# Input schema (SubagentStop) — per Claude Code hooks reference: +# { "session_id": "...", "agent_id": "agent-abc123", "agent_type": "Explore", +# "agent_transcript_path": "...", "last_assistant_message": "...", ... } +# +# The agent name is in `agent_type`, NOT `agent_name`. Reading `.agent_name` +# returns null on every invocation, so the fallback "unknown" is always used +# and the audit trail captures nothing useful. INPUT=$(cat) # Parse agent name -- use jq if available, fall back to grep if command -v jq >/dev/null 2>&1; then - AGENT_NAME=$(echo "$INPUT" | jq -r '.agent_name // "unknown"' 2>/dev/null) + AGENT_NAME=$(echo "$INPUT" | jq -r '.agent_type // "unknown"' 2>/dev/null) else - AGENT_NAME=$(echo "$INPUT" | grep -oE '"agent_name"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/"agent_name"[[:space:]]*:[[:space:]]*"//;s/"$//') + AGENT_NAME=$(echo "$INPUT" | grep -oE '"agent_type"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/"agent_type"[[:space:]]*:[[:space:]]*"//;s/"$//') [ -z "$AGENT_NAME" ] && AGENT_NAME="unknown" fi diff --git a/.claude/hooks/log-agent.sh b/.claude/hooks/log-agent.sh index a88830e..e39a5e7 100644 --- a/.claude/hooks/log-agent.sh +++ b/.claude/hooks/log-agent.sh @@ -2,16 +2,20 @@ # Claude Code SubagentStart hook: Log agent invocations for audit trail # Tracks which agents are being used and when # -# Input schema (SubagentStart): -# { "agent_id": "agent-abc123", "agent_name": "game-designer", ... } +# Input schema (SubagentStart) — per Claude Code hooks reference: +# { "session_id": "...", "agent_id": "agent-abc123", "agent_type": "Explore", ... } +# +# The agent name is in `agent_type`, NOT `agent_name`. Reading `.agent_name` +# returns null on every invocation, so the fallback "unknown" is always used +# and the audit trail captures nothing useful. INPUT=$(cat) # Parse agent name -- use jq if available, fall back to grep if command -v jq >/dev/null 2>&1; then - AGENT_NAME=$(echo "$INPUT" | jq -r '.agent_name // "unknown"' 2>/dev/null) + AGENT_NAME=$(echo "$INPUT" | jq -r '.agent_type // "unknown"' 2>/dev/null) else - AGENT_NAME=$(echo "$INPUT" | grep -oE '"agent_name"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/"agent_name"[[:space:]]*:[[:space:]]*"//;s/"$//') + AGENT_NAME=$(echo "$INPUT" | grep -oE '"agent_type"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/"agent_type"[[:space:]]*:[[:space:]]*"//;s/"$//') [ -z "$AGENT_NAME" ] && AGENT_NAME="unknown" fi