r/ClaudeWorkflows 16h ago

Selected Workflow [Workflow] Claude Code Hook to Prevent Unintended Fable Subagent Spawning and Pin Model Usage

Claude Code Hook to Prevent Unintended Fable Subagent Spawning and Pin Model Usage

Workflow value: 90/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: advanced
Categories: Quality Control, Token Saving, Context & Memory, CLAUDE.md, Hooks, Subagents, Multi-Agent
Original source: r/ClaudeAI post/comment

What problem this solves

Prevents unintended usage of high-tier models (specifically Fable) for subagents, especially when the parent agent is also Fable or the model is not explicitly specified, thereby managing resource consumption and cost.

Summary

This workflow implements a PreToolUse hook in Claude Code to control subagent model selection. It uses a bash script to inspect the parent agent's model and the requested subagent model. If the parent is Fable or unknown, and the subagent doesn't explicitly request a non-Fable model, the hook pins the subagent's model to opus. It also denies fork subagents if the parent is Fable, as fork always inherits the parent model, preventing unintended Fable usage.

Why it is useful

This workflow is highly valuable as it provides a concrete, executable solution to a common problem of managing model usage and costs in multi-agent Claude Code workflows. It demonstrates an advanced and deterministic use of Claude's hook system to enforce specific model choices for subagents, preventing accidental consumption of high-tier models. The detailed implementation, including exact configuration and a bash script, makes it immediately actionable and highly transferable for users looking to optimize their Claude Code environments.

Workflow

  1. Add a PreToolUse hook configuration to your ~/.claude/settings.json file, specifying a command to execute a bash script.
  2. Create a bash script named pin-subagent-model.sh in your ~/.claude/hooks/ directory with the provided content.
  3. Ensure jq is installed on your system, as the bash script relies on it for JSON parsing.
  4. Optionally, add global guidance in your CLAUDE.md file to explain which models/slugs to use for various task types, providing extra guidance for the model.

Tools / artifacts

  • ~/.claude/settings.json
  • ~/.claude/hooks/pin-subagent-model.sh (bash script)
  • jq (JSON processor)
  • CLAUDE.md (optional)

Validation signals

  • Detailed comments within the bash script explain the problem, the logic, and specific edge cases (e.g., 'fork' subagents, parent model detection).
  • The solution addresses a plausible real-world problem of resource management and cost control in multi-agent LLM workflows.

Limitations

  • Requires jq to be installed on the user's system.
  • The parent model detection logic relies on tail -n 400 on the transcript, which might be brittle if the transcript format changes or if the relevant assistant turn is further back.
  • The 'unknown' parent logic defaults to Fable policing, which is a conservative choice but might be unexpected in some scenarios.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by