Skip to content

feat: Add is_subagent() helper method to all hook context classes#3

Closed
kitaekatt wants to merge 1 commit intoGowayLee:mainfrom
kitaekatt:add-is-subagent-helper
Closed

feat: Add is_subagent() helper method to all hook context classes#3
kitaekatt wants to merge 1 commit intoGowayLee:mainfrom
kitaekatt:add-is-subagent-helper

Conversation

@kitaekatt
Copy link

This adds the is_subagent() helper method to all hook context classes (PreToolUseContext, PostToolUseContext, SessionStartContext, SessionEndContext, UserPromptSubmitContext, NotificationContext, StopContext, SubagentStopContext, PreCompactContext).

The method enables developers to detect whether a hook is running in a sub-agent context vs main Claude context by examining the transcript_path filename pattern. Main Claude sessions use 'session-{id}.jsonl', while sub-agents use 'agent-{id}.jsonl'.

This enables tool access gating patterns where main Claude and delegated task contexts can have different authorization and capability requirements.

Changes:

  • Add is_subagent() method to all 9 context classes
  • Comprehensive unit tests covering main Claude, sub-agent, and edge cases
  • All 320 existing tests pass without regression

The implementation is non-breaking (adds new method only) and has zero performance overhead (just pattern matching on filename).

This adds the is_subagent() helper method to all hook context classes
(PreToolUseContext, PostToolUseContext, SessionStartContext, SessionEndContext,
UserPromptSubmitContext, NotificationContext, StopContext, SubagentStopContext,
PreCompactContext).

The method enables developers to detect whether a hook is running in a sub-agent
context vs main Claude context by examining the transcript_path filename pattern.
Main Claude sessions use 'session-{id}.jsonl', while sub-agents use 'agent-{id}.jsonl'.

This enables tool access gating patterns where main Claude and delegated task
contexts can have different authorization and capability requirements.

Changes:
- Add is_subagent() method to all 9 context classes
- Comprehensive unit tests covering main Claude, sub-agent, and edge cases
- All 320 existing tests pass without regression

The implementation is non-breaking (adds new method only) and has zero performance
overhead (just pattern matching on filename).
@kitaekatt
Copy link
Author

Flaw in my approach

@kitaekatt kitaekatt closed this Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant