feat: soft-enforcement delegation + simplified team mode#41
Conversation
Reduces session startup overhead from ~1.1s (3x Python/uv startup) to ~0.4s (1x) by combining inject_workflow_orchestrator, inject-output-style, and inject_token_efficiency into a single inject_all.py that reads stdin once and merges all additionalContext into one JSON response.
Reduce per-session token overhead by trimming injected prompt files and removing a duplicate output-style injection. - output-styles/technical-adaptive.md: 19.1K -> 1.7K (91%). Drop all HTML/visual mode, mermaid integration, file tree CSS, and async generation patterns. Keep only terminal response rules. - system-prompts/orchestrator_stub.md: 3.3K -> 1.2K (65%). Collapse redundant routing tables and Stage 1 details into a single rule. Stage 1 / agent return format / prohibited tools live in the on-demand workflow_orchestrator.md instead. - system-prompts/token_efficient_cli.md: 7.1K -> 1.9K (73%). Drop per-tool REQUIRED/PROHIBITED tables that compact_run.py already rewrites at runtime. Keep the principle plus Read/Grep guidance the hooks cannot fix. - inject_all.py: stop injecting technical-adaptive.md. Claude Code loads it natively from plugin.json's outputStyles field (verified via /config showing workflow-orchestrator:technical-adaptive active), so the hook injection was a duplicate. - tests: drop obsolete test_inject_token_efficiency.py (the standalone script no longer exists; consolidated into inject_all.py in the parent branch). Update integration assertion to match the trimmed token_efficient_cli.md content. Net session-start savings: ~6,600 tokens. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hard-blocking delegation enforcement with per-turn escalating stderr nudges (silent -> hint -> warning -> strong reminder). Track only the 8 stable work primitives (Bash/Edit/Write/Read/Glob/Grep/ MultiEdit/NotebookEdit); new Claude Code tools never trigger nudges. Counter resets per turn and zeros when /workflow-orchestrator:delegate runs. Subagents immune. Removes the allowlist and commands/bypass.md. Simplify execution mode selection to one rule: TeamCreate available -> team mode, else subagent. Deletes team_mode_score scoring table. Fix team-mode spawns by forbidding run_in_background on teammate Agent calls (background tasks exit on completion and are not persistent swarm members). Downgrade validate_task_graph_compliance and validate_task_graph_depth to advisory-only. Update README, CLAUDE.md, docs/hook-debugging.md, docs/ARCHITECTURE_QUICK_REFERENCE.md to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Review Summary by QodoSoft enforcement delegation nudges, simplified team mode, and consolidated SessionStart hooks
WalkthroughsDescription• **Soft enforcement delegation**: Replaced hard-blocking tool usage restrictions with per-turn escalating stderr nudges (6 levels: silent → hint → warning → strong reminder). Tracks only 8 stable work primitives (Bash, Edit, Write, Read, Glob, Grep, MultiEdit, NotebookEdit); new Claude Code tools never trigger nudges. Removed 100+ lines of allowlist/pattern matching logic. • **Simplified team-mode selection**: Replaced complex team_mode_score scoring table with single rule: TeamCreate tool available → team mode, else subagent mode. Removed 4-step routing checklist. • **Team-mode spawn fix**: Added critical note that teammate Agent(team_name=...) calls must NOT use run_in_background: true (background tasks exit on completion, not persistent swarm members). • **Consolidated SessionStart hooks**: Merged 3 separate injection scripts into single inject_all.py (~0.3s faster startup). Injects stub orchestrator on startup (~1.1KB), full orchestrator on-demand (~7.5KB), saving ~6.6K tokens at session start. • **Downgraded validation hooks to advisory-only**: validate_task_graph_compliance and validate_task_graph_depth now emit one-liner hints instead of hard-blocking (exit 1). Only python_posttooluse_hook.py (Ruff/Pyright) remains hard-blocking. • **Statusline performance optimization**: Added stdin-first fast path for context window and version caching (920ms → 0ms per render, ~1s faster context rendering). • **Counter reset on delegation**: Per-turn nudge counter resets when /workflow-orchestrator:delegate runs, tracked via delegation_violations.json. • **Comprehensive test coverage**: New 223-line test suite for soft enforcement nudges, escalation ladder validation, and integration tests updated for consolidated hooks. • **Documentation updates**: README, CLAUDE.md, hook-debugging guide, architecture reference, and output style guide all updated to reflect soft enforcement mechanics, simplified team selection, and lean startup benefits. • **Deleted files**: Removed commands/bypass.md, separate SessionStart injection scripts, and obsolete token efficiency tests. Diagramflowchart LR
A["Hard-blocking enforcement<br/>+ allowlist logic"] -->|"Replace with soft nudges"| B["Per-turn escalating<br/>stderr messages"]
C["Complex team_mode_score<br/>scoring table"] -->|"Simplify to one rule"| D["TeamCreate available?<br/>→ team mode"]
E["3 separate SessionStart<br/>injection hooks"] -->|"Consolidate"| F["Single inject_all.py<br/>~6.6K tokens saved"]
G["Hard-blocking validation<br/>hooks"] -->|"Downgrade to advisory"| H["One-liner hints<br/>on stderr"]
I["Statusline subprocess<br/>calls"] -->|"Optimize with stdin"| J["Cached version lookup<br/>920ms → 0ms"]
B --> K["✓ Tests + Docs<br/>updated"]
D --> K
F --> K
H --> K
J --> K
File Changes1. hooks/PreToolUse/require_delegation.py
|
Code Review by Qodo
|
| ## EXECUTION MODE (ONE RULE) | ||
|
|
||
| ### Step 0: Team/Collaboration Detection (CHECK FIRST) | ||
| **If `TeamCreate` is in your available tools -> `execution_mode: "team"`. Otherwise -> `"subagent"`.** No scoring, no exceptions. Do not run Bash to check env vars -- tool availability is the signal. |
There was a problem hiding this comment.
5. Removed team_mode_score fallback logic 📘 Rule violation ≡ Correctness
Execution-mode selection was simplified to always choose team mode whenever TeamCreate is available, removing the required team_mode_score <= -3 fallback to subagent mode. This violates the required mode-selection behavior when experimental teams are enabled.
Agent Prompt
## Issue description
Mode-selection instructions now remove `team_mode_score` entirely and do not implement the required fallback to subagent mode when `team_mode_score <= -3`.
## Issue Context
Compliance requires:
- if `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` and `TeamCreate` is available: default to team
- only fall back to subagent when `team_mode_score <= -3`
## Fix Focus Areas
- commands/delegate.md[15-17]
- system-prompts/orchestrator_stub.md[13-17]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| tool_name = str(data.get("tool_name", "")) | ||
| if tool_name not in WORK_TOOLS: | ||
| return 0 |
There was a problem hiding this comment.
6. No team_mode_active auto-create 📘 Rule violation ≡ Correctness
The PreToolUse flow no longer auto-creates .claude/state/team_mode_active when experimental teams are enabled and a team tool is invoked. This breaks the required team-mode marker behavior and can prevent other hooks from recognizing team mode.
Agent Prompt
## Issue description
A PreToolUse hook must create `.claude/state/team_mode_active` when experimental teams are enabled and a team tool is invoked, but the current logic returns early for non-work tools and never creates the marker.
## Issue Context
This marker is used by other components/hooks to detect team mode.
## Fix Focus Areas
- hooks/PreToolUse/require_delegation.py[131-133]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Replace workflow-demo.gif with new 4x-speed recording of the team-mode calculator app workflow. Replace the 5 legacy subagent-flow screenshots with 4 new ones showing plan mode, dependency graph, tmux swarm view, and team completion. Rewrite the walkthrough text to describe the TeamCreate + persistent teammate + SendMessage coordination flow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- remind_skill_continuation.py: use tempfile.gettempdir() for debug log path (cross-platform) and sys.stdout.write instead of print (T201). - require_delegation.py: exit 1 on unexpected exception per hook exit-code policy (still non-blocking for the tool call itself). - validate_task_graph_compliance.py, validate_task_graph_depth.py: add PEP 723 script metadata block (required for uv run --script). - Delete orphaned system-prompts/workflow_orchestrator.md. No Python code loads this file; the full orchestrator logic lives in commands/delegate.md, which is injected by the slash command on demand. Update README.md and CLAUDE.md references accordingly. Qodo #5 (team_mode_score fallback) and #6 (team_mode_active auto-create) are intentional / false positives and will be replied to on the PR. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed qodo review in 35fc5f5. Fixed (5):
Rejected (2): #5 — #6 — |
…e.md The orphan system-prompts/workflow_orchestrator.md was deleted in the previous commit. Update the four secondary docs that still referenced it. CHANGELOG entry left untouched (historical record). - ARCHITECTURE_QUICK_REFERENCE.md: troubleshooting checklist + multi-step workflow example now point at inject_all.py and the slash command. - environment-variables.md: Related links collapsed to commands/delegate.md. - plan-explore-parallel-processing.md: 4 architectural references updated. - validation-schema.md: Related Documentation pointer updated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Soft-enforcement delegation, simplified team-mode selection, lean SessionStart injection, and team-spawn fix. See CHANGELOG.md for the full release notes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
require_delegation.pyemits per-turn escalating stderr nudges (silent →delegate?→nudge: ...→WARNING: ...→ strong reminder) 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 more allowlist to maintain.commands/bypass.mddeleted.team_mode_scorescoring table. One rule —TeamCreatein tools → team mode, else subagent.Agent(team_name=...)calls must NOT userun_in_background: true(background tasks exit on completion and are not persistent swarm members, leaving the tmux session empty).inject_all.py, stub + on-demand full orchestrator, ~6.6K tokens off session start.validate_task_graph_compliance/validate_task_graph_depthdowngraded to advisory-only.python_posttooluse_hook.py(Ruff/Pyright) is now the only hard-blocking hook.docs/hook-debugging.md,docs/ARCHITECTURE_QUICK_REFERENCE.md.Test plan
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1spawns real persistent teammates (verified in tmux swarm session), all phases PASS/workflow-orchestrator:delegate🤖 Generated with Claude Code