You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: soft-enforcement delegation, simplified team mode, lean injection
Soft enforcement replaces hard-blocking delegation:
- require_delegation.py emits per-turn escalating stderr nudges instead of exit-2 blocks
- Tracks only the 8 stable work primitives (Bash/Edit/Write/Read/Glob/Grep/MultiEdit/NotebookEdit)
- New Claude Code tools never trigger nudges — no allowlist maintenance
- Counter resets per turn, zeros on /workflow-orchestrator:delegate, subagents immune
Simplified team-mode selection:
- Deleted team_mode_score scoring table
- One rule: TeamCreate available → team mode, else subagent
Team-mode persistent teammate fix:
- Teammate Agent(team_name=...) calls must NOT use run_in_background: true
- Background tasks exit on completion and are not persistent swarm members
Lean SessionStart injection (~6.6K token savings):
- 3 hooks consolidated into inject_all.py
- Stub orchestrator on startup, full logic loaded on-demand by /delegate
- Output style loaded natively from plugin.json
Validation hooks downgraded to advisory-only. Removed orphaned
system-prompts/workflow_orchestrator.md and commands/bypass.md.
README walkthrough refreshed with team-mode demo.
Closes#41
Copy file name to clipboardExpand all lines: CHANGELOG.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,33 @@
2
2
3
3
All notable changes to this project will be documented in this file.
4
4
5
+
## [1.18.0] - 2026-04-08
6
+
7
+
### Changed
8
+
-**Soft enforcement replaces hard blocking**: `hooks/PreToolUse/require_delegation.py` no longer blocks tool calls. It emits per-turn escalating stderr nudges (silent → `delegate?` → `nudge: ...` → `WARNING: ...` → strong reminder) based on `.claude/state/delegation_violations.json`. The counter resets each turn and zeros when `/workflow-orchestrator:delegate` runs. Subagents are immune.
9
+
-**Stable work-tool surface**: Only the 8 stable primitives (`Bash`, `Edit`, `Write`, `Read`, `Glob`, `Grep`, `MultiEdit`, `NotebookEdit`) are tracked. New Claude Code tools never trigger nudges — no more allowlist maintenance as Anthropic ships new tools.
10
+
-**One-rule team mode selection**: Deleted the `team_mode_score` scoring table from `commands/delegate.md`. New rule — if `TeamCreate` is in the available tools, `execution_mode: "team"`; otherwise `"subagent"`. No scoring, no exceptions.
11
+
-**Advisory-only validation hooks**: `validate_task_graph_compliance.py` and `validate_task_graph_depth.py` are now advisory (stderr hints, never block). `python_posttooluse_hook.py` (Ruff/Pyright) is the only remaining hard-blocking hook.
12
+
13
+
### Fixed
14
+
-**Team-mode persistent teammates**: Teammate `Agent(team_name=...)` calls must NOT use `run_in_background: true`. Background Agent tasks exit on completion and are not persistent swarm members, leaving the tmux session empty. Subagent-mode spawns still use `run_in_background: true`.
15
+
16
+
### Removed
17
+
-**`commands/bypass.md`**: No longer needed under soft enforcement.
18
+
-**`system-prompts/workflow_orchestrator.md`**: Orphaned file (no Python loaded it). The full orchestrator logic lives inline in `commands/delegate.md` and is loaded on-demand by the slash command.
Copy file name to clipboardExpand all lines: CLAUDE.md
+37-56Lines changed: 37 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,17 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
5
5
---
6
6
7
-
## Critical: Delegation Policy
7
+
## Delegation Policy (Soft Enforcement)
8
8
9
-
**MANDATORY IMMEDIATE DELEGATION ON TOOL BLOCK**
9
+
The framework nudges via stderr when the main agent uses work-doing tools (`Bash`, `Edit`, `Write`, `Read`, `Glob`, `Grep`, `MultiEdit`, `NotebookEdit`) directly. **Nudges never block.** They escalate by per-turn violation count: silent → short hint → warning → strong reminder. The counter resets each turn and zeros when `/workflow-orchestrator:delegate` runs.
10
10
11
-
When ANY tool is blocked by the delegation policy hook:
12
-
13
-
1.**DO NOT try alternative approaches** - just delegate immediately
14
-
2.**IMMEDIATELY use `/workflow-orchestrator:delegate <task>`** on first tool block
15
-
3.**The entire user request must be delegated**, not just the blocked tool
16
-
17
-
### Recognition Pattern
11
+
The expected path for any multi-step or work-shaped request is:
18
12
19
13
```
20
-
Error: PreToolUse:* hook error: [...] Tool blocked by delegation policy
21
-
Tool: <ToolName>
22
-
23
-
STOP: Do NOT try alternative tools.
24
-
REQUIRED: Use /workflow-orchestrator:delegate command immediately:
First tool block = immediate delegation. Don't try alternatives, don't explain — just delegate.
17
+
Subagents are immune (they're executing a delegation). New tools added by Claude Code never trigger nudges — only the 8 stable work primitives are tracked.
29
18
30
19
---
31
20
@@ -62,7 +51,6 @@ CI workflow exists (`.github/workflows/ci.yml`) but tests are currently disabled
62
51
```bash
63
52
/workflow-orchestrator:delegate <task># Plan and execute task via native plan mode
|**PostToolUse**|`python_posttooluse_hook.py` (Edit/Write/MultiEdit), `remind_skill_continuation.py` (ExitPlanMode\|Skill\|SlashCommand), `validate_task_graph_depth.py` + `remind_todo_after_task.py` (Agent/Task) | Python validation (Ruff, Pyright, security), workflow continuation state (triggers on ExitPlanMode for plan mode flows), depth-3 enforcement, task reminders |
116
-
|**UserPromptSubmit**|`clear-delegation-sessions.py`|Clear delegation state, record turn start timestamp, clear team state (`team_mode_active`, `team_config.json`), rotate logs |
117
-
|**SessionStart** (`startup\|resume\|clear\|compact`) |`inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py`| Inject conditional orchestrator (stub on startup, full on /workflow-orchestrator:delegate), output style, token efficiency guidance|
Hook config source of truth: `hooks/plugin-hooks.json` (not settings.json). All hooks are Python for cross-platform compatibility (Windows/macOS/Linux).
122
110
123
-
### Tool Allowlist
111
+
### Soft Enforcement (Adaptive Nudges)
124
112
125
-
Main agent can only use: `AskUserQuestion`, `TaskCreate`, `TaskUpdate`, `TaskList`, `TaskGet`, `Skill`, `SlashCommand`, `Agent`, `Task`, `SubagentTask`, `AgentTask`, `EnterPlanMode`, `ExitPlanMode`, `ToolSearch`, `CronCreate`, `CronDelete`, `CronList`
113
+
There is no allowlist. `require_delegation.py` tracks per-turn direct work-tool calls and writes a stderr message that escalates by count:
126
114
127
-
Special cases:
128
-
-`Write` tool allowed for temp/scratchpad paths only (`/tmp/`, `/private/tmp/`, `/var/folders/`)
129
-
-`TaskOutput` is **prohibited** (context exhaustion: ~20K tokens per agent)
130
-
-`TaskList` polling loops are **prohibited** (use completion notifications instead)
115
+
| Violations | Message | Tokens |
116
+
|---|---|---|
117
+
| 0 | (silent) | 0 |
118
+
| 1 |`delegate?`|~2 |
119
+
| 2 |`nudge: use /workflow-orchestrator:delegate for multi-step work`|~12 |
120
+
| 3–4 |`WARNING: N direct tool calls bypassing delegation. Use /workflow-orchestrator:delegate <task>.`|~25 |
121
+
| 5+ | Strong reminder explaining what's being lost |~55 |
131
122
132
-
**Agent Teams tools** (conditional, requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`):
133
-
- Explicit: `TeamCreate`, `SendMessage`
134
-
- Teammates are spawned via `Agent` tool with `team_name` parameter (Agent is already in the main allowlist)
135
-
- Pattern match: Any tool name containing `"team"` or `"teammate"` (case-insensitive) as safety net
123
+
Tracked tools (the only ones that count as violations): `Bash`, `Edit`, `Write`, `Read`, `Glob`, `Grep`, `MultiEdit`, `NotebookEdit`. These 8 stable primitives are the only ones monitored. New Claude Code tools never trigger nudges.
136
124
137
-
### Bypass Mechanisms
125
+
The counter:
126
+
- Resets each turn (`UserPromptSubmit`)
127
+
- Zeros when `/workflow-orchestrator:delegate` runs (slate clean — model chose the right path)
128
+
- Is bypassed entirely for subagents (they're executing a delegation; `CLAUDE_PARENT_SESSION_ID` / `CLAUDE_AGENT_ID` set)
129
+
- Is bypassed when `.claude/state/delegation_active` exists (delegation already in progress)
138
130
139
-
| Mechanism | How | Scope |
140
-
|-----------|-----|-------|
141
-
| Env var |`DELEGATION_HOOK_DISABLE=1`| Session-wide |
142
-
|`/workflow-orchestrator:bypass` command | Creates `.claude/state/delegation_disabled`| Persists until toggled |
143
-
| Subagent auto-bypass |`CLAUDE_PARENT_SESSION_ID` set | Automatic for subagents |
144
-
| Delegation active flag |`.claude/state/delegation_active` created on Skill/Agent/Task use | Per-delegation |
131
+
The only hook that still hard-blocks is `python_posttooluse_hook.py` (Ruff/Pyright on edited Python files — stable surface, fix-forward UX).
145
132
146
133
**Note:** The `task-planner` and `breadth-reader` skills have been removed. Planning and orchestration are provided by native plan mode (EnterPlanMode/ExitPlanMode). Read-only breadth tasks are handled by spawning parallel Explore agents or the codebase-context-analyzer directly.
147
134
@@ -174,21 +161,17 @@ Two team workflow patterns:
174
161
-**Team mode (simple):** Single AGENT TEAM phase with `phase_type: "team"` and `teammates` array -- used for multi-perspective exploration (e.g., "explore from different angles")
175
162
-**Team mode (complex):** Multiple individual phases across waves, all executed as teammates via `Agent(team_name=...)` -- used for collaborative implementation (e.g., "implement project, tasks should be collaborative"). The plan has `execution_mode: "team"` at the top level; no individual phase needs `phase_type: "team"`
176
163
177
-
**Mode selection** is based on TeamCreate tool availability (detected during plan mode):
178
-
-**If TeamCreate tool is available** (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 is set): Calculate `team_mode_score` to determine whether to use team mode or subagent mode
- Default to team mode (score not calculated, absent, or > -3); use subagent mode only when score <= -3
183
-
-**If TeamCreate tool is not available** (env var not set): Always use subagent mode (≥2 subtasks mandatory)
164
+
**Mode selection** is based on ONE RULE (detected during plan mode):
165
+
-**If TeamCreate tool is available** (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 is set): `execution_mode: "team"`
166
+
-**If TeamCreate tool is not available** (env var not set): `execution_mode: "subagent"` (≥2 subtasks mandatory)
184
167
185
168
**When team mode is active:**
186
169
-`validate_task_graph_compliance.py` hook is bypassed (team handles dependencies)
187
170
- Agent Teams tools are added to the allowlist (TeamCreate, SendMessage; teammates via Agent with team_name param)
188
171
- Agents use conditional COMMUNICATION MODE (teammate messaging vs `DONE|{path}`)
189
172
- State files: `.claude/state/team_mode_active`, `.claude/state/team_config.json`
190
173
191
-
Agent selection uses keyword matching (≥2 matches threshold, highest count wins). Falls back to general-purpose if 0-1 matches. See `system-prompts/workflow_orchestrator.md` for keyword lists.
174
+
Agent selection uses keyword matching (≥2 matches threshold, highest count wins). Falls back to general-purpose if 0-1 matches. See `commands/delegate.md` (Available Specialized Agents section) for keyword lists.
|`.claude/state/delegated_sessions.txt`| Session registry | Cleared per user prompt |
203
-
|`.claude/state/delegation_active`| Subagent session flag | Per-delegation |
204
-
|`.claude/state/delegation_disabled`| Bypass flag | Until `/bypass` toggle |
185
+
|`.claude/state/delegation_violations.json`| Per-turn nudge counter (`{violations, delegations, turn_id}`) | Reset per user prompt; zeroed on `/workflow-orchestrator:delegate`|
186
+
|`.claude/state/delegation_active`| Active-delegation flag (suppresses nudges) | Per-delegation |
cat .claude/state/delegation_violations.json # current per-turn nudge counter
269
+
ls .claude/state/delegation_active 2>/dev/null # delegation in progress?
289
270
```
290
271
291
272
**Multi-step not detected:**
292
-
Ensure SessionStart hooks are installed (inject_workflow_orchestrator.py) so that workflow_orchestrator.md is injected and native plan mode (EnterPlanMode/ExitPlanMode) is available. Use connectors in prompts: "and then", "with", "including".
273
+
Ensure the SessionStart hook is installed (`hooks/SessionStart/inject_all.py`) so `orchestrator_stub.md` is injected and the main agent knows to route multi-step work through `/workflow-orchestrator:delegate`. Use connectors in prompts: "and then", "with", "including".
The PreToolUse hook blocks all team tools (`TeamCreate`, `SendMessage`, pattern `*team*`/`*teammate*`) unless this env var is set. The hook auto-creates `.claude/state/team_mode_active` when the env var is "1" and a team tool is invoked.
300
281
301
282
**Team mode not activating despite keywords:**
302
-
Team mode is activated by tool availability detection during plan mode. Ensure `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` is set before running a workflow that should use team mode. The planning phase evaluates `team_mode_score` based on task complexity and characteristics. Without the env var, plan mode always selects `"subagent"` mode (with ≥2 subtasks mandatory).
283
+
Team mode is activated by tool availability detection during plan mode. Ensure `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` is set before running a workflow that should use team mode. The planning phase checks if `TeamCreate` tool is available. If the env var is not set, `TeamCreate` is blocked by PreToolUse hook, so plan mode always selects `"subagent"` mode (with ≥2 subtasks mandatory).
0 commit comments