Skip to content

skill not getting invoked #107

@RichardHightower

Description

@RichardHightower

Regarding your question about the hook loading the mastering-aws-cdk skill — let me check.

⏺ Searched for 3 patterns, read 1 file (ctrl+o to expand)

⏺ Good catch! Yes — lines 108-122 of hooks.yaml:

- name: cdk-typescript-context                                                              
  matchers:                                                                                 
    tools: [Write, Edit, Read]                                                              
    directories: [cdk/]                                                                     
    extensions: [.ts]                                                    
  actions:                           
    inject_inline: |
      ## AWS CDK Skill Available
      You are editing AWS CDK TypeScript infrastructure code.
      Use `/mastering-aws-cdk` for CDK v2 construct patterns, stack design, and deployment

workflows.

The hook triggers when editing/reading .ts files under cdk/ — it injects a reminder to use the
skill. But there are two issues:

  1. The planner agent read CDK files (via the Agent tool), but hooks only fire on
    Write/Edit/Read tools in the main conversation — subagent tool calls don't trigger hooks in
    the parent.
  2. The hook only reminds (inject_inline) — it doesn't auto-load the skill. It says "Use
    /mastering-aws-cdk" but the agent has to actually invoke it.

For the executor in Phase 2, the hook will fire when it reads/edits database.ts and
database.test.ts, since those are .ts files under cdk/. But that's just a reminder — the
executor would need to explicitly load the skill.

★ Insight ─────────────────────────────────────

  • Hooks fire on tool calls in the current conversation, not in subagents
  • The inject_inline pattern is advisory — it nudges but doesn't force skill loading
  • For the Phase 2 executor, we could pass the skill content directly in the prompt, or
    instruct the executor to load it
    ─────────────────────────────────────────────────

Want me to load mastering-aws-cdk before executing Phase 2 so the executor has that context?

✻ Cogitated for 1m 39s

❯ how do we make it required .. how do we trigger hooks in subagents.

⏺ Good questions. Let me research both — I'll check the hooks skill and Claude Code docs.

⏺ Skill(mastering-hooks)
⎿  Successfully loaded skill

⏺ Read 2 files (ctrl+o to expand)

⏺ Great finds. Here are the answers:

  1. How to trigger hooks in subagents: BeforeAgent event

The BeforeAgent event (lines 439-449 of rule-patterns.md) fires when any subagent is launched.
This is how you inject context into subagents:

Inject CDK skill content before any agent that touches CDK files

  • name: agent-cdk-policy
    event: BeforeAgent
    match: {}
    action:
    type: inject
    source: file
    path: .claude/context/cdk-conventions.md

★ Insight ─────────────────────────────────────

  • PreToolUse/PostToolUse fire for tool calls in the current conversation — they don't
    propagate into subagent conversations
  • BeforeAgent fires when a subagent is spawned — it injects into the subagent's initial
    context
  • This is the mechanism for governing what subagents know and do
    ─────────────────────────────────────────────────
  1. How to make skill loading required (not just advisory)

Your current hooks use inject_inline with text like "Use /mastering-aws-cdk for..." — that's a
suggestion the agent can ignore. Two approaches to make it mandatory:

Option A: Inject the skill content directly (recommended)

Instead of telling the agent to load a skill, inject the actual guidance:

  • name: cdk-required-context
    event: PreToolUse
    match:
    tools: [Write, Edit]
    directories: [cdk/]
    extensions: [.ts]
    action:
    type: inject
    source: file
    path: .claude/context/cdk-conventions.md # extracted key patterns from the skill

Option B: Use run action to block without skill

  • name: require-cdk-skill
    event: PreToolUse
    match:
    tools: [Write, Edit]
    directories: [cdk/]
    extensions: [.ts]
    action:
    type: run
    command: |
    echo '{"continue": true, "context": "## MANDATORY: CDK Conventions\n- Use
    RemovalPolicy.DESTROY for ephemeral\n- Use IS_EPHEMERAL from @evinova/esdp-constants\n- Match
    existing patterns in redis.ts/kms-key.ts\n- Run npm run build + tests before committing"}'

Option C: For subagents specifically — BeforeAgent + file inject

  • name: agent-cdk-conventions
    event: BeforeAgent
    match: {}
    action:
    type: inject
    source: file
    path: .claude/context/agent-conventions.md

Recommendation

The best approach for your use case is a two-layer strategy:

  1. BeforeAgent — inject project-wide conventions (including CDK patterns) into every subagent
  2. PreToolUse on cdk/ + .ts — inject CDK-specific guidance when editing CDK files in the main
    conversation

Want me to create the context files and update hooks.yaml with these rules?

✻ Sautéed for 36s

❯ no lets continue be sure you load the aws cdk skill giong forward

⏺ Got it. Let me load the CDK skill now, then we'll execute Phase 2.

⏺ Skill(mastering-aws-cdk)
⎿  Successfully loaded skill

⏺ CDK skill loaded. Ready to execute Phase 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions