[FEATURE] Add invocation context/provenance to PreToolUse hook payload for Task tool

Status Closed — duplicate
Maintainer reply None cached
Activity 3 comments · opened Feb 8, 2026 · closed Feb 12, 2026

Problem

When using PreToolUse hooks with the Task matcher, there is no way to determine what triggered the Task tool call. Specifically, hooks cannot distinguish between:

  • A Task spawned directly by the main agent in response to user input
  • A Task spawned as part of a Skill execution

This matters because hooks that enrich Task prompts (e.g., injecting session context, standards, or additional instructions) may be unnecessary or even counterproductive when the Task is spawned by a skill that already has its own well-defined prompt.

Current behavior

The PreToolUse hook payload for Task contains:

{
  "session_id": "...",
  "transcript_path": "...",
  "tool_name": "Task",
  "tool_input": {
    "prompt": "...",
    "description": "...",
    "subagent_type": "..."
  }
}

There is no field indicating why or by whom the Task was invoked.

Proposed solution

Add an invocation_context (or similar) field to the hook payload:

{
  "tool_name": "Task",
  "invocation_context": {
    "triggered_by": "skill",
    "skill_name": "sync-branches"
  },
  "tool_input": { ... }
}

This would allow hook scripts to make context-aware decisions, e.g.:

triggered_by="$(jq -r '.invocation_context.triggered_by // "agent"' <<<"$payload")"
if [[ "$triggered_by" == "skill" ]]; then
    # Skip enrichment for skill-originated tasks
    exit 0
fi

Workarounds considered

| Approach | Limitation |
|---|---|
| Parse transcript for recent Skill tool calls | Fragile, timing-dependent, expensive |
| Pattern-match Task description/prompt | Requires maintenance per skill, not reliable |
| Sentinel file via skill frontmatter hooks | Race condition (skill hooks and global hooks fire in parallel) |
| Skill frontmatter hook override | Not possible — skill hooks are additive, not replacements |

None of these are robust.

Use case

A common pattern is having a PreToolUse hook that injects session context and agent standards into every Task prompt. This is valuable for user-initiated tasks but adds unnecessary token overhead and noise for skills that already provide complete, self-contained prompts to their Task agents.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗