From 3d891313ba39418fc72351cbbf8d045f561af990 Mon Sep 17 00:00:00 2001 From: Yuichi TSUNEMATSU Date: Thu, 20 Aug 2026 15:02:24 +0900 Subject: [PATCH] =?UTF-8?q?feat(claude):=20herdr=20=E3=81=AE=20SessionStar?= =?UTF-8?q?t=20=E3=83=95=E3=83=83=E3=82=AF=E3=82=92=20chezmoi=20=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=B8=8B=E3=81=AB=E7=BD=AE=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit settings.json が SessionStart で参照している ~/.claude/hooks/herdr-agent-state.sh が管理外だったため、新しいマシンで chezmoi apply してもこのファイルだけ配置されず、フックが参照先を失う。 herdr が生成するファイルなので二重管理になる点は承知の上で追加する。 現状は HERDR_INTEGRATION_VERSION=7 を固定することになるため、herdr 側の 統合を更新したあとは chezmoi re-add で取り込み直す必要がある。 Co-Authored-By: Claude Opus 5 (1M context) --- .../hooks/executable_herdr-agent-state.sh | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 dot_claude/hooks/executable_herdr-agent-state.sh diff --git a/dot_claude/hooks/executable_herdr-agent-state.sh b/dot_claude/hooks/executable_herdr-agent-state.sh new file mode 100644 index 0000000..cb5e840 --- /dev/null +++ b/dot_claude/hooks/executable_herdr-agent-state.sh @@ -0,0 +1,101 @@ +#!/bin/sh +# installed by herdr +# managed by herdr; reinstalling or updating the integration overwrites this file. +# add custom hooks beside this file instead of editing it. +# HERDR_INTEGRATION_ID=claude +# HERDR_INTEGRATION_VERSION=7 + +set -eu + +action="${1:-}" +hook_input_file="$(mktemp "${TMPDIR:-/tmp}/herdr-claude-hook.XXXXXX")" || exit 0 +trap 'rm -f "$hook_input_file"' EXIT HUP INT TERM +cat >"$hook_input_file" 2>/dev/null || true + +case "$action" in + session) ;; + *) exit 0 ;; +esac + +[ "${HERDR_ENV:-}" = "1" ] || exit 0 +[ -n "${HERDR_SOCKET_PATH:-}" ] || exit 0 +[ -n "${HERDR_PANE_ID:-}" ] || exit 0 +command -v python3 >/dev/null 2>&1 || exit 0 + +HERDR_ACTION="$action" HERDR_HOOK_INPUT_FILE="$hook_input_file" python3 - <<'PY' +import json +import os +import random +import socket +import time + +source = "herdr:claude" +action = os.environ.get("HERDR_ACTION", "") +pane_id = os.environ.get("HERDR_PANE_ID") +socket_path = os.environ.get("HERDR_SOCKET_PATH") +hook_input_file = os.environ.get("HERDR_HOOK_INPUT_FILE") + +if not pane_id or not socket_path: + raise SystemExit(0) + +hook_input = {} +if hook_input_file: + try: + with open(hook_input_file, encoding="utf-8") as handle: + content = handle.read() + if content.strip(): + hook_input = json.loads(content) + except Exception: + hook_input = {} + +hook_event_name = str(hook_input.get("hook_event_name") or "") +is_subagent = bool(hook_input.get("agent_id")) +if is_subagent: + raise SystemExit(0) +if hook_event_name == "SubagentStop": + # SubagentStop is a completion event. Older Herdr integrations mapped it + # to durable working, but Claude recap/away-summary can emit it after the + # main turn has already stopped. Never let it revive an idle pane. + raise SystemExit(0) +request_id = f"{source}:{int(time.time() * 1000)}:{random.randrange(1_000_000):06d}" +report_seq = time.time_ns() +session_id = hook_input.get("session_id") +agent_session_id = session_id if isinstance(session_id, str) and session_id else None +transcript_path = hook_input.get("transcript_path") +agent_session_path = transcript_path if isinstance(transcript_path, str) and transcript_path else None +session_start_source = hook_input.get("source") if hook_event_name == "SessionStart" else None +if not isinstance(session_start_source, str) or not session_start_source: + session_start_source = None +if agent_session_id: + params = { + "pane_id": pane_id, + "source": source, + "agent": "claude", + "seq": report_seq, + "agent_session_id": agent_session_id, + } + if agent_session_path: + params["agent_session_path"] = agent_session_path + if session_start_source: + params["session_start_source"] = session_start_source + request = { + "id": request_id, + "method": "pane.report_agent_session", + "params": params, + } +else: + raise SystemExit(0) + +try: + client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + client.settimeout(0.5) + client.connect(socket_path) + client.sendall((json.dumps(request) + "\n").encode()) + try: + client.recv(4096) + except Exception: + pass + client.close() +except Exception: + pass +PY