PLUGIN brewtools / Skills

Agent Deadline Setup

sonnet opt-in project | global

Claude Code has no wall-clock timeout for subagents. An agent that hits maxTurns returns a partial result and loses any analysis it hasn’t written down. These hooks add a soft elapsed-time budget that nudges the agent to finalize. They kill nothing.

Quick reference

FieldValue
Command/brewtools:agent-deadline-setup
Args[prompt] [status|install|upgrade|enable|disable|uninstall|purge] [project|global] [minutes] [--unattended]
Modelsonnet
Defaultsno args = status; budget 20 min; ABSENT config = DISABLED (enabled must be exactly true)
Output2 hook files, 2 settings.json entries, agent-deadline.json

Modes

ModeDoes
statusReport installed scopes, wiring, governing config (default)
installCopy hooks, merge settings, write config
upgradeRe-emit hooks from the current plugin, budget kept
enableSet enabled: true
disableSet enabled: false, files stay
uninstallUnwire and delete hooks, keep config
purgeUninstall and delete config

Under --unattended, upgrade covers one scope and skips with nothing written unless the prompt names exactly one of project or global; it also skips when that scope has an orphan config, is not installed, uses a custom launcher or has an invalid settings.json. A config kept by uninstall is not an install: the note is not installed (uninstalled, config kept) and the hooks are not wired again. See how the flag works.

Example

/brewtools:agent-deadline-setup install project 20

The skill prints its plan (2 hook files into .claude/hooks/, config with defaultMinutes: 20, 2 settings entries), asks only for confirmation and re-prints status: guard=yes cleanup=yes guard_refs=1 cleanup_refs=1 enabled=true.

How it works

ElapsedAction
80% of budgetNon-blocking notice: finish the step, prepare the final report
100%Every tool outside the finalization set is denied
hardStopRatio x budget (default 2x)Only Write, Edit, SubagentHandback pass

The finalization set is Read, Write, Edit, NotebookEdit, TodoWrite, TaskUpdate, SubagentHandback.

  1. Status first

    Both scopes are checked before anything changes.

  2. Plan, then questions

    The plan is printed; scope and budget are asked only if missing.

  3. Delegated file work

    One brewcode:hook-creator spawn per scope copies hooks and merges settings. See Delegation.

  4. Live status

    Wiring and config changes apply to the running session; no restart, /hooks confirms.

Technical details

The two hooks #
HookEventBehavior
agent-deadline-guard.mjsPreToolUse on .*Tracks elapsed time per agent_id; warns at 80%; past 100% denies tools outside the finalization set; past hardStopRatio x budget allows only Write, Edit, SubagentHandback (deny reason starts Time budget far exceeded)
agent-deadline-cleanup.mjsSubagentStopStamps the stop on the agent’s state file, never deletes it, prunes old state. A call under 5 minutes after the stop continues the original clock; later gets a fresh window

SubagentHandback stays allowed at every stage: in auto mode it is how a subagent reports. AskUserQuestion is denied past the deadline: a subagent parked on a human answer is the unbounded wait this guard stops. Read-only agent types (readOnlyAgentTypes) are told to return what they have instead of saving a file.

Installation targets and config discovery #
ScopeHooks dirsettings.jsonConfig
Project<repo>/.claude/hooks/<repo>/.claude/settings.json<repo>/.claude/agent-deadline.json
Global<config dir>/hooks/<config dir>/settings.json<config dir>/agent-deadline.json

<config dir> is $CLAUDE_CONFIG_DIR when set, else ~/.claude. State lives in the OS temp dir under brewtools-agent-deadline/<session_id>/, never under the config dir.

The guard reads the nearest valid project config first (a JSON object in .claude/agent-deadline.json, walking up from the subagent’s working directory, at most 16 levels), then the global one; a malformed project config is skipped. Global writes go through Bash only, because the config dir is a protected path for Write/Edit.

Config shape #

Example: {"enabled": true, "defaultMinutes": 20, "byAgentType": {}, "hardStopRatio": 2} plus the provenance keys below.

KeyMeaning
enabledExactly true; anything else turns enforcement off
defaultMinutesBudget for every agent type; default 20
byAgentTypePer-type overrides, e.g. {"Explore": 10}; empty = one limit
hardStopRatioOptional, default 2, must be > 1
readOnlyAgentTypesOptional, default ["Explore", "Plan"]; a list replaces the default, add it by hand
version / content_version / generated_by / last_updatedProvenance; freshness is judged by content_version (header of agent-deadline-guard.mjs)

Budget is byAgentType[agent_type] ?? defaultMinutes. upgrade keeps defaultMinutes, byAgentType, hardStopRatio and enabled; a disabled setup stays disabled. One scope per run.

enabled is opt-in: absent or not true means OFF, unlike agent-router-setup and brewdoc:docsync-setup.

Governing config after uninstall project #

uninstall project keeps .claude/agent-deadline.json. While the global scope still registers the guard, that file keeps governing it: the project enabled and budget override global. The uninstall prints WARNING: kept <cfg> still GOVERNS ... and offers purge project.

status prints governing_config=<path> governing_scope=project|global|none orphan_config=yes|no; orphan_config=yes means a project config governs while the project has no registrations and global has some. upgrade is never offered for it, because it would re-wire the project and undo the uninstall.

GoalRun
Hand control back to global/brewtools:agent-deadline-setup purge project
Keep the project configNothing; the warning is informational

uninstall and purge remove only the state recorded for this scope’s config, plus files untouched for 24 h.

Limits: read before trusting it #
  • Not a timeout. Time is sampled only at tool-call boundaries; cap long commands separately with BASH_MAX_TIMEOUT_MS.
  • The clock starts at the first tool call, not at spawn. A stop does not reset it (see the cleanup hook above), so an over-budget agent blocked once by another guard can only finalize.
  • agent_type for plugin agents is unverified (brewcode:skill-creator vs skill-creator). A non-matching byAgentType key silently falls back to defaultMinutes.
  • Fail-open: any hook error lets the call through.
  • Cost on every tool call, main session included. The matcher is .* because the guard must see SubagentHandback. Measured on one Apple M-series machine (Node v24.1.0, 30 runs): median 58.3 ms, p90 62.5 ms. A global install charges this in every session; re-measure before relying on it.

Provenance keys and version checks: see Artifact metadata.

Brewtools overview

All brewtools skills and agents.

Agent Return Setup

Size budget for subagent final returns; installs side by side with this skill.

Setup Status

Dashboard across every -setup skill; upgrade brings the stale ones current.

GitHub source

SKILL.md, the install runbook and both hook scripts.

Update: /brewtools:plugin-update, /reload-plugins, then /brewcode:setup-status upgrade - FAQ