Files
claude-mnemonic/cmd/hooks/subagent-stop/main.go
T
2026-03-06 15:39:52 +00:00

42 lines
1.1 KiB
Go

// Package main provides the subagent-stop hook entry point.
// This hook fires when a Task/subagent completes, capturing observations from subagent work.
package main
import (
"fmt"
"os"
"github.com/lukaszraczylo/claude-mnemonic/pkg/hooks"
)
// Input is the hook input from Claude Code.
type Input struct {
hooks.BaseInput
StopHookActive bool `json:"stop_hook_active"`
}
func main() {
if !hooks.IsWorkerAvailable() {
hooks.WriteResponse("SubagentStop", true)
return
}
hooks.RunHook("SubagentStop", handleSubagentStop)
}
func handleSubagentStop(ctx *hooks.HookContext, input *Input) (string, error) {
fmt.Fprintf(os.Stderr, "[subagent-stop] Subagent completed in project %s\n", ctx.Project)
// Notify worker that a subagent completed
// This can trigger processing of any queued observations from the subagent
_, err := hooks.POST(ctx.Port, "/api/sessions/subagent-complete", map[string]interface{}{
"claudeSessionId": ctx.SessionID,
"project": ctx.Project,
})
if err != nil {
// Non-fatal - just log warning
fmt.Fprintf(os.Stderr, "[subagent-stop] Warning: failed to notify worker: %v\n", err)
}
return "", nil
}