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
Token optimization: reduce plugin overhead by 55% and enforce Agent Teams (#36)
* Token optimization: reduce plugin overhead by 55% (20K→9K tokens)
## Conditional Orchestrator Injection
- SessionStart injects 40-line routing stub (~200 tokens) instead of
full 545-line orchestrator (~5.5K tokens)
- Full orchestrator loads on-demand via /delegate command only
- Sessions that don't use multi-step delegation save ~5K tokens
## Prompt Compression
- Orchestrator slimmed 49% (1065→545 lines)
- /delegate template compressed 89% (4955→555 chars)
- Agent definitions deduplicated 47% (640→339 lines)
- Delegation error messages compressed 57%, no emoji
## Token Efficiency Enhancements
- DONE|{path} return format enforced in all 8 agent definitions
- Partial file read guidance (offset/limit for >200 lines)
- cd && command pattern handling in rewrite hook
- Added eslint, next lint, tsc to output compression
- Conversation filler reduction rules in output style
## Agent Teams as Default
- Team mode detection via TeamCreate tool availability (not Bash env check)
- Mandatory TeamCreate + Agent(team_name=...) when teams available
- Isolated subagents only as fallback when TeamCreate fails
- Team check is FIRST ACTION before any planning
## Cleanup
- Deleted deprecated task-planner skill (-622 lines)
- Planning exclusively via native EnterPlanMode
- Updated all documentation (CLAUDE.md, README.md, docs/)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix uncaught exception exit code in require_delegation hook
Change exit code from 0 (fail-open) to 1 (internal error) in the
uncaught exception handler, per hook exit code convention:
0=allow, 1=error, 2=block. Addresses Qodo review feedback on PR #36.
* Fix Qodo review issues: PEP 723 blocks, execution_mode threshold, npx next output, delegate allowlist
- Add PEP 723 inline metadata to inject_workflow_orchestrator.py and require_delegation.py
- Fix execution_mode selection to fall back to subagent when team_mode_score <= -3 (not just breadth tasks)
- Fix npx next output suppression: only compress 'next lint', pass through other next commands
- Update delegate.md allowed-tools to include all required tools (EnterPlanMode, ExitPlanMode, TaskCreate, etc.)
* Fix execution_mode threshold to match CLAUDE.md policy (>= 5 for team, < 5 for subagent)
Aligns workflow_orchestrator.md team_mode_score decision logic with the
documented policy in CLAUDE.md. The previous threshold (> -3) effectively
restricted subagent fallback to breadth-only tasks. The correct threshold
(>= 5) ensures subagent mode is selected whenever the score indicates
insufficient complexity for team coordination.
* Fix team_mode_score threshold: default to team mode unless score <= -3
Align execution mode selection policy so that team mode is the default
when Agent Teams is enabled, falling back to subagent only when
team_mode_score <= -3 (previously required score >= 5 to use teams).
Updated both workflow_orchestrator.md and CLAUDE.md for consistency.
* fix: correct next lint test to use proper subcommand args
* fix: enable Claude Code Review to post PR comments
- Remove plugin-based review approach (code-review@claude-code-plugins)
that was not posting comments correctly
- Use standard auto-detected review mode for pull_request events
- Add missing permissions: issues: write, actions: read
- Add additional_permissions for CI result reading
- Use prompt input for review instructions instead of plugin skill invocation
* docs: update architecture and environment variable documentation
* fix: normalize DONE format and prevent wrapping long-running npx commands
* Fix ruff formatting in token_rewrite_hook.py
Resolves CI linting failure caused by unformatted code.
* Fix delegate command allowed-tools: add ToolSearch, TeamCreate, SendMessage
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Hook config source of truth: `hooks/plugin-hooks.json` (not settings.json). All hooks are Python for cross-platform compatibility (Windows/macOS/Linux).
121
123
122
124
### Tool Allowlist
123
125
124
-
Main agent can only use: `AskUserQuestion`, `TaskCreate`, `TaskUpdate`, `TaskList`, `TaskGet`, `Skill`, `SlashCommand`, `Agent`, `Task`, `SubagentTask`, `AgentTask`, `EnterPlanMode`, `ExitPlanMode`, `ToolSearch`
126
+
Main agent can only use: `AskUserQuestion`, `TaskCreate`, `TaskUpdate`, `TaskList`, `TaskGet`, `Skill`, `SlashCommand`, `Agent`, `Task`, `SubagentTask`, `AgentTask`, `EnterPlanMode`, `ExitPlanMode`, `ToolSearch`, `CronCreate`, `CronDelete`, `CronList`
125
127
126
128
Special cases:
127
129
-`Write` tool allowed for temp/scratchpad paths only (`/tmp/`, `/private/tmp/`, `/var/folders/`)
@@ -144,9 +146,10 @@ Special cases:
144
146
145
147
### Skills (forked context)
146
148
147
-
-**task-planner** (`skills/task-planner/SKILL.md`): Legacy planning skill, retained for reference/backward compatibility. The core planning logic (complexity scoring, tier classification, agent assignment, wave scheduling, task creation) has been absorbed into `system-prompts/workflow_orchestrator.md` and now executes as native plan mode (EnterPlanMode/ExitPlanMode) directly in the main agent context rather than a forked skill context.
**Note:** The `task-planner` skill has been removed. Its orchestration and planning functionality is now provided by native plan mode (EnterPlanMode/ExitPlanMode), which handles both planning and execution orchestration directly within the main agent context.
152
+
150
153
### Specialized Agents (8)
151
154
152
155
| Agent | Domain |
@@ -176,12 +179,13 @@ Two team workflow patterns:
176
179
-**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")
177
180
-**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"`
178
181
179
-
**Mode selection** uses `team_mode_score` (calculated during plan mode):
**Mode selection** is based on TeamCreate tool availability (detected during plan mode):
183
+
-**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
188
+
-**If TeamCreate tool is not available** (env var not set): Always use subagent mode (≥2 subtasks mandatory)
185
189
186
190
**When team mode is active:**
187
191
-`validate_task_graph_compliance.py` hook is bypassed (team handles dependencies)
@@ -191,7 +195,10 @@ Two team workflow patterns:
191
195
192
196
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.
193
197
194
-
Agent config format: YAML frontmatter (`name`, `description`, optional `tools`/`model`/`color`) + markdown system prompt body. All agents enforce `DONE|{output_file}` return format.
@@ -287,13 +298,13 @@ Ensure SessionStart hooks are installed (inject_workflow_orchestrator.py) so tha
287
298
288
299
**TeamCreate blocked:**
289
300
```bash
290
-
echo$CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS#Must be "1"
301
+
echo$CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS#Check if set to "1"
291
302
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
292
303
```
293
-
The PreToolUse hook blocks all team tools (`TeamCreate`, `SendMessage`, pattern `*team*`/`*teammate*`) unless this env var is set. The hook prints a specific error message indicating the env var is missing.
304
+
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.
294
305
295
306
**Team mode not activating despite keywords:**
296
-
When `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` is set, team mode is the default. It only falls back to subagent mode when`team_mode_score <= -3` (breadth-only tasks with no complexity factors). Without the env var, plan mode always selects `"subagent"` mode (with ≥2 subtasks mandatory).
307
+
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).
Copy file name to clipboardExpand all lines: README.md
+17-22Lines changed: 17 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -252,14 +252,14 @@ The `plugin-hooks.json` configures the delegation enforcement hooks using cross-
252
252
253
253
**Note:** All hooks use `uv run --no-project --script` for cross-platform compatibility (Windows, macOS, Linux). The `--no-project` flag allows execution without requiring a pyproject.toml, and `--script` directly runs Python scripts using uv's managed interpreter.
@@ -268,22 +268,10 @@ The `plugin-hooks.json` configures the delegation enforcement hooks using cross-
268
268
Multi-step workflow orchestration requires the workflow_orchestrator system prompt to be appended:
269
269
270
270
**Automatic (via SessionStart hook):**
271
-
```json
272
-
{
273
-
"hooks": {
274
-
"SessionStart": [
275
-
{
276
-
"hooks": [
277
-
{
278
-
"type": "append_system_prompt",
279
-
"path": "system-prompts/workflow_orchestrator.md"
280
-
}
281
-
]
282
-
}
283
-
]
284
-
}
285
-
}
286
-
```
271
+
272
+
The `inject_workflow_orchestrator.py` hook uses conditional injection:
273
+
-**On startup/resume:** Injects a lightweight stub that registers `/delegate` and `/bypass` commands without loading the full orchestrator prompt, keeping baseline token overhead minimal.
274
+
-**On `/delegate` invocation:** The full `workflow_orchestrator.md` system prompt is loaded on-demand, providing the complete planning and execution logic only when needed.
287
275
288
276
**What this enables:**
289
277
- Multi-step task detection via pattern matching
@@ -415,7 +403,7 @@ No other configuration is required. Plan mode automatically evaluates whether a
415
403
416
404
### How Mode Selection Works
417
405
418
-
During planning, plan mode calculates a `team_mode_score` based on task characteristics:
406
+
During planning, plan mode checks if the TeamCreate tool is available (indicator that Agent Teams are enabled). If available, it calculates a `team_mode_score` based on task characteristics:
@@ -428,7 +416,7 @@ During planning, plan mode calculates a `team_mode_score` based on task characte
428
416
| Breadth task | -5 | Simple exploration is better as subagents |
429
417
| Phase count <= 3 | -3 | Small workflows don't need team overhead |
430
418
431
-
A score of **5 or higher** (with `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`) triggers team mode. Otherwise, subagent mode is used.
419
+
Default to team mode when Agent Teams available (TeamCreate in tools). Falls back to subagent only when `team_mode_score <= -3` (breadth-only tasks). If TeamCreate tool is not available (env var not set), subagent mode is always selected.
432
420
433
421
### Subagent Mode vs Team Mode
434
422
@@ -503,7 +491,7 @@ Team mode creates two additional state files (automatically cleaned up on comple
503
491
504
492
The framework minimizes command output to reduce context consumption and preserve tokens for meaningful work. Token efficiency is enabled by default (`CLAUDE_TOKEN_EFFICIENCY=1`).
505
493
506
-
### Two-Layer Approach
494
+
### Multi-Layer Approach
507
495
508
496
1.**Behavioral Guidance** — The `token_efficient_cli.md` system prompt (injected via SessionStart) teaches compact flag usage:
509
497
-`git status -sb` (short branch format)
@@ -515,6 +503,13 @@ The framework minimizes command output to reduce context consumption and preserv
515
503
- Git: `push`, `pull`, `commit`, `merge`, `rebase`, `status`, etc.
516
504
- Test runners: `pytest`, `cargo test`, `npm/pnpm/yarn/bun test`, `vitest`, `jest`, `mocha`, etc.
0 commit comments