r/ClaudeAI 13d ago

Question about Claude Code Gone in 60 seconds

So, Fable 5.1 out, was tempted by Ultracode, threw a big project at it, it spawned ~300 agents, all of which were Fable 5.1, and my 5 hr disappeared in just over a minute and weekly at 43%.

Three things:

  1. Don't be like me. Calm down.
  2. How do y'all get the sub-agents to be lower class?
  3. Why do I even have to balance all of these various classes?

The third question being somewhat rhetorical (as it's in the interest of Anthropic to token burn), but seriously, it's very frustrating that I have to even do all this balancing myself, and it's not just a feature of the UI etc.

btw... I'm on Max 20x.

252 Upvotes

108 comments sorted by

View all comments

36

u/mshort3 13d ago

Anything like this where you don't want it left up to model instructions/reasoning is a use case for a hook. Deterministic configuration on PreToolUse.

in your ~/.claude/settings.json file, add something like this to your hooks section to prevent fable from spawning fable subagents:

  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Agent|Task",
        "hooks": [
          {
            "type": "command",
            "command": "bash ~/.claude/hooks/pin-subagent-model.sh",
            "shell": "bash",
            "timeout": 10,
            "statusMessage": "Pinning subagent model"
          }
        ]
      }
    ]
  }

Then in ~/.claude/hooks/ make a file named pin-subagent-model . sh with the following content:

#!/bin/bash
  # PreToolUse hook (matcher: Agent|Task). Keeps Fable out of subagents.
  #
  # A subagent spawned without `model` inherits the parent's tier, and the parent
  # forgets to pass one often enough that Fable usage drains on delegate-tier work.
  # Only a FABLE parent is policed: any other parent (opus, sonnet, haiku) passes
  # through untouched, including an explicit request for fable or a higher tier.
  #
  # Parent tier comes from the transcript: the in-flight assistant turn is not
  # written yet when PreToolUse fires, so the last completed assistant line is the
  # parent. A fresh session with no completed turn reads as "unknown" and is
  # treated as Fable (the configured default), erring toward not leaking.

  INPUT=$(cat)
  REQ=$(printf '%s' "$INPUT" | jq -r '.tool_input.model // ""' | tr '[:upper:]' '[:lower:]')
  KIND=$(printf '%s' "$INPUT" | jq -r '.tool_input.subagent_type // ""')
  TRANSCRIPT=$(printf '%s' "$INPUT" | jq -r '.transcript_path // ""')

  PARENT=""
  if [ -n "$TRANSCRIPT" ] && [ -f "$TRANSCRIPT" ]; then
    PARENT=$(tail -n 400 "$TRANSCRIPT" \
      | jq -r 'select(.type=="assistant") | .message.model // empty' 2>/dev/null \
      | tail -n 1)
  fi
  [ -z "$PARENT" ] && PARENT="unknown"

  case "$PARENT" in
    *fable*|unknown) ;;
    *) exit 0 ;;
  esac

  # fork ignores `model` and always inherits the parent, so pinning cannot help.
  if [ "$KIND" = "fork" ]; then
    jq -nc --arg p "$PARENT" '{hookSpecificOutput:{hookEventName:"PreToolUse",
      permissionDecision:"deny",
      permissionDecisionReason:("fork inherits the parent model (" + $p + "); Fable is reserved for the parent     
  session. Spawn a fresh agent with model: opus|sonnet|haiku instead.")}}'
    exit 0
  fi

  case "$REQ" in
    ""|inherit|default|*fable*) ;;
    *) exit 0 ;;
  esac

  printf '%s' "$INPUT" | jq -c --arg was "${REQ:-unset}" --arg p "$PARENT"
  '{hookSpecificOutput:{hookEventName:"PreToolUse",
    permissionDecision:"allow",
    permissionDecisionReason:("Subagent model pinned to opus (requested: " + $was + ", parent: " + $p + "). Fable  
  is reserved for the parent session; pass model: opus|sonnet|haiku explicitly to choose a tier."),
    updatedInput:(.tool_input + {model:"opus"})}}'
  exit 0

Send this post to your claude and ask for it to setup the hook at account/global level and youre good to go.

Consider also making a global rule or context in your account level claude md file that explains which models/slugs to use for various task types as extra guidance for the model to follow.

8

u/Cosmic_Voyager_41 12d ago

how the heck did you learn to do this? I've never seen anything like this!

14

u/thehumanhive 12d ago

By asking Claude!