Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/cli/internal/trace/claude/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ var commandTools = []string{"Bash"}
// kind fired.
var hookToolMatcher = strings.Join(append(append([]string{}, fileWritingTools...), commandTools...), "|")

// postHookToolMatcher also covers the Skill tool. The skill is loaded only
// after the call, so the post hook is the first one that can copy its folder.
var postHookToolMatcher = hookToolMatcher + "|" + skillTool

type hookEvent struct {
event string
command string
Expand All @@ -67,7 +71,7 @@ var hookEvents = []hookEvent{
{eventSessionStart, "chainloop trace hook claude session-start", ""},
{eventUserPromptSubmit, "chainloop trace hook claude user-prompt-submit", ""},
{eventPreToolUse, "chainloop trace hook claude pre-tool-use", hookToolMatcher},
{eventPostToolUse, "chainloop trace hook claude post-tool-use", hookToolMatcher},
{eventPostToolUse, "chainloop trace hook claude post-tool-use", postHookToolMatcher},
{eventPostToolUseFailure, "chainloop trace hook claude post-tool-use", hookToolMatcher},
{eventSessionEnd, "chainloop trace hook claude session-end", ""},
}
Expand Down
7 changes: 4 additions & 3 deletions app/cli/internal/trace/claude/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ func TestInstallHooks(t *testing.T) {
preEntry := preEntries[0].(map[string]any)
assert.Equal(t, "Edit|Write|MultiEdit|Bash", preEntry["matcher"])

// PostToolUse should have matcher
// PostToolUse also matches Skill, to copy the folder of a loaded skill
postEntries := hooks["PostToolUse"].([]any)
postEntry := postEntries[0].(map[string]any)
assert.Equal(t, "Edit|Write|MultiEdit|Bash", postEntry["matcher"])
assert.Equal(t, "Edit|Write|MultiEdit|Bash|Skill", postEntry["matcher"])

// PostToolUseFailure should have the same matcher
// PostToolUseFailure keeps the edit matcher: a failed Skill call loads
// no skill
failureEntries := hooks["PostToolUseFailure"].([]any)
failureEntry := failureEntries[0].(map[string]any)
assert.Equal(t, "Edit|Write|MultiEdit|Bash", failureEntry["matcher"])
Expand Down
Loading
Loading