Skip to content

Commit bcf72d6

Browse files
barkainclaude
andauthored
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>
1 parent 1768e0f commit bcf72d6

28 files changed

Lines changed: 1176 additions & 1915 deletions

.github/workflows/claude-code-review.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ jobs:
2626
permissions:
2727
contents: read
2828
pull-requests: write
29+
issues: write
2930
id-token: write
31+
actions: read
3032

3133
steps:
3234
- name: Checkout repository
@@ -39,9 +41,11 @@ jobs:
3941
uses: anthropics/claude-code-action@v1
4042
with:
4143
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
42-
plugin_marketplaces: 'https://github.com/anthropics/claude-code.git'
43-
plugins: 'code-review@claude-code-plugins'
44-
prompt: '/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}'
44+
prompt: |
45+
Review this PR for code quality, potential bugs, and improvements.
46+
Focus on meaningful issues rather than style nits.
47+
additional_permissions: |
48+
actions: read
4549
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
4650
# or https://code.claude.com/docs/en/cli-reference for available options
4751
env:

CLAUDE.md

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ uvx ruff format . # Format code (auto-fix)
4646
uvx ruff check --no-fix . # Lint code (check only)
4747
uvx pyright . # Type checking
4848
uvx deadcode hooks/ scripts/ # Dead code detection
49-
uvx pytest tests/ -v # Run test suite
5049
```
5150

5251
The PostToolUse hook enforces a specific ruff rule subset on edited Python files:
5352
```bash
5453
uvx ruff check --select F,E711,E712,UP006,UP007,UP035,UP037,T201,S <file>
5554
```
5655

57-
Test suite exists in `tests/` with comprehensive coverage for hooks and token efficiency features.
56+
CI workflow exists (`.github/workflows/ci.yml`) but tests are currently disabled/placeholder.
5857

5958
---
6059

@@ -80,13 +79,16 @@ In plugin mode, agent/skill names use prefix `workflow-orchestrator:` (e.g., `wo
8079

8180
### Execution Flow
8281

82+
**Token overhead:** Conditional injection (stub ~200 tokens on startup, full ~11K tokens on first delegation) + per-agent delegation (~350 tokens)
83+
8384
```
8485
User prompt
8586
→ UserPromptSubmit hook (clear state, record turn timestamp, clear team state)
86-
→ SessionStart hooks (inject workflow_orchestrator.md + output style)
87-
→ workflow_orchestrator detects multi-step → enters native plan mode (EnterPlanMode)
88-
→ plan mode: main agent explores codebase, decomposes, assigns agents, creates tasks via TaskCreate
89-
→ plan mode: evaluates execution_mode (subagent vs team via team_mode_score)
87+
→ SessionStart hooks (inject stub orchestrator + output style + token efficiency)
88+
[Stub version provides just enough system direction, avoiding unnecessary tokens]
89+
→ Task detection: if multi-step connectors found, enters native plan mode (EnterPlanMode)
90+
→ plan mode: injects full workflow_orchestrator, explores codebase, decomposes, assigns agents, creates tasks via TaskCreate
91+
→ plan mode: evaluates execution_mode (subagent vs team via TeamCreate tool availability)
9092
→ plan mode: exits via ExitPlanMode (requires lead approval)
9193
→ PostToolUse hook (remind_skill_continuation.py): creates workflow_continuation_needed.json on ExitPlanMode
9294
→ After ExitPlanMode approval, main agent continues to Stage 1
@@ -96,7 +98,7 @@ User prompt
9698
→ Agents write to $CLAUDE_SCRATCHPAD_DIR, return DONE|{path}
9799
→ SubagentStop hooks: remind task update, suggest verification
98100
→ Main agent: TaskUpdate to mark completed, proceed to next wave
99-
→ TEAM MODE (experimental, CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1):
101+
→ TEAM MODE (when TeamCreate tool is available):
100102
→ Create .claude/state/team_mode_active + team_config.json
101103
→ TeamCreate(team_name=...), then Agent(team_name=...) for each teammate with agent configs
102104
→ Create shared tasks with dependencies, bridge to framework Tasks API
@@ -106,22 +108,22 @@ User prompt
106108
→ Stop hook: calculate turn duration, quality analysis
107109
```
108110

109-
### Hook System (6 lifecycle events, 15 scripts)
111+
### Hook System (6 lifecycle events, 14 hooks)
110112

111113
| Event | Scripts | Purpose |
112114
|-------|---------|---------|
113-
| **PreToolUse** (`*`, `Bash`) | `require_delegation.py`, `validate_task_graph_compliance.py`, `token_rewrite_hook.py` | Block non-allowed tools; validate Agent/Task invocations against active task graph; rewrite Bash commands for token efficiency |
115+
| **PreToolUse** (`*`, `Bash`) | `validate_task_graph_compliance.py`, `require_delegation.py`, `token_rewrite_hook.py` (Bash only) | Validate Agent/Task invocations against active task graph; block non-allowed tools (compressed error messages); rewrite Bash commands for token efficiency (cd && pattern, eslint, next, tsc) |
114116
| **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 |
115117
| **UserPromptSubmit** | `clear-delegation-sessions.py` | Clear delegation state, record turn start timestamp, clear team state (`team_mode_active`, `team_config.json`), rotate logs |
116-
| **SessionStart** (`startup\|resume\|clear\|compact`) | `inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py` | Inject system prompt + output style + token efficiency guidance |
118+
| **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 /delegate), output style, token efficiency guidance |
117119
| **SubagentStop** (`*`) | `remind_todo_update.py` (async), `trigger_verification.py` | Remind to update tasks, suggest verification |
118120
| **Stop** | `python_stop_hook.py` | Turn duration, workflow continuation (block stop + inject "continue"), quality analysis |
119121

120122
Hook config source of truth: `hooks/plugin-hooks.json` (not settings.json). All hooks are Python for cross-platform compatibility (Windows/macOS/Linux).
121123

122124
### Tool Allowlist
123125

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`
125127

126128
Special cases:
127129
- `Write` tool allowed for temp/scratchpad paths only (`/tmp/`, `/private/tmp/`, `/var/folders/`)
@@ -144,9 +146,10 @@ Special cases:
144146

145147
### Skills (forked context)
146148

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.
148149
- **breadth-reader** (`skills/breadth-reader/SKILL.md`): Lightweight read-only breadth tasks. Spawns `Explore` subagents (Haiku). Returns summary only.
149150

151+
**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+
150153
### Specialized Agents (8)
151154

152155
| Agent | Domain |
@@ -176,12 +179,13 @@ Two team workflow patterns:
176179
- **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")
177180
- **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"`
178181

179-
**Mode selection** uses `team_mode_score` (calculated during plan mode):
180-
- Phase count >8: +2, Tier 3 complexity: +2, cross-phase data flow: +3
181-
- Review-fix cycles: +3, iterative refinement: +2, user keyword "collaborate"/"team": +5
182-
- Breadth task: -5, phase count <=3: -3
183-
- With `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`: default to team mode; only fall back to subagent when `team_mode_score <= -3` (breadth-only tasks)
184-
- Without env var: always parallel subagent mode (≥2 subtasks mandatory)
182+
**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
184+
- Phase count >8: +2, Tier 3 complexity: +2, cross-phase data flow: +3
185+
- Review-fix cycles: +3, iterative refinement: +2, user keyword "collaborate"/"team": +5
186+
- Breadth task: -5, phase count <=3: -3
187+
- 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)
185189

186190
**When team mode is active:**
187191
- `validate_task_graph_compliance.py` hook is bypassed (team handles dependencies)
@@ -191,7 +195,10 @@ Two team workflow patterns:
191195

192196
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.
193197

194-
Agent config format: YAML frontmatter (`name`, `description`, optional `tools`/`model`/`color`) + markdown system prompt body. All agents enforce `DONE|{output_file}` return format.
198+
Agent config format: YAML frontmatter (`name`, `description`, optional `tools`/`model`/`color`) + markdown system prompt body. All agents enforce `DONE|{output_file}` return format. Custom agent instructions include:
199+
- Return format must be exactly `DONE|{output_file_path}` (no summaries or explanations)
200+
- Write directly to output file using Write tool (do not delegate writing)
201+
- If Write is blocked, report error and stop (do not retry)
195202

196203
### State Files (Runtime)
197204

@@ -241,7 +248,7 @@ Agent config format: YAML frontmatter (`name`, `description`, optional `tools`/`
241248
| `CLAUDE_PLUGIN_ROOT` | Not set | Set by plugin system for path resolution |
242249
| `CLAUDE_SCRATCHPAD_DIR` | Per-session | Session-isolated temp dir for agent output |
243250
| `CLAUDE_PROJECT_DIR` | `$PWD` | State directory base path |
244-
| `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` | `0` | Enable Agent Teams dual-mode (`1` to enable team mode scoring and tools) |
251+
| `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` | `0` | Enable Agent Teams (TeamCreate tool availability and team mode scoring; `1` to enable) |
245252
| `CLAUDE_CODE_ENABLE_TASKS` | `true` | Set `false` to revert to TodoWrite |
246253
| `CLAUDE_CODE_TASK_LIST_ID` | Per-session | Share task list across sessions |
247254
| `CLAUDE_TOKEN_EFFICIENCY` | `1` | Enable token-efficient CLI output compression (`0` to disable) |
@@ -252,11 +259,15 @@ Agent config format: YAML frontmatter (`name`, `description`, optional `tools`/`
252259

253260
Minimize command output to reduce context consumption. Enabled by default (`CLAUDE_TOKEN_EFFICIENCY=1`).
254261

255-
**Two-layer approach:**
262+
**Multi-layer approach:**
256263
1. **Behavioral guidance** (`system-prompts/token_efficient_cli.md`): Injected via SessionStart, teaches compact flag usage (e.g., `git status -sb`, `pytest -q --tb=short`)
257264
2. **Output compression** (`hooks/compact_run.py`): PreToolUse hook rewrites matching Bash commands through `compact_run.py`, which compresses git/test/log output post-execution
265+
3. **cd && pattern handling**: Hooks support chained commands with `cd && command` pattern for working directory preservation in compressed output
266+
4. **Extended language support**: Rewrite hook supports eslint, next, tsc build tools in addition to git/test families
267+
5. **Partial file reads**: Use Read tool with `offset` and `limit` parameters for files >200 lines to avoid loading entire file contents into context
268+
6. **Compressed error messages**: Delegation error messages are optimized for minimal token consumption (use logging, never print statements)
258269

259-
**Supported command families:** git (push/pull/commit/etc), pytest, cargo test, npm/pnpm/yarn/bun test, npx (vitest/jest/mocha/playwright), go test, make test/check, docker/kubectl logs
270+
**Supported command families:** git (push/pull/commit/etc), pytest, cargo test, npm/pnpm/yarn/bun test, npx (vitest/jest/mocha/playwright), go test, make test/check, docker/kubectl logs, eslint, next, tsc
260271

261272
Disable: `export CLAUDE_TOKEN_EFFICIENCY=0`
262273

@@ -287,13 +298,13 @@ Ensure SessionStart hooks are installed (inject_workflow_orchestrator.py) so tha
287298

288299
**TeamCreate blocked:**
289300
```bash
290-
echo $CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS # Must be "1"
301+
echo $CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS # Check if set to "1"
291302
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
292303
```
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.
294305

295306
**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).
297308

298309
**Team state files stale after crash:**
299310
```bash

README.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ The `plugin-hooks.json` configures the delegation enforcement hooks using cross-
252252

253253
**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.
254254

255-
**Hook Events (6 lifecycle points, 15 scripts):**
255+
**Hook Events (6 lifecycle points, 14 hooks):**
256256

257257
| Event | Scripts | Purpose |
258258
|-------|---------|---------|
259-
| **PreToolUse** | `validate_task_graph_compliance.py`, `require_delegation.py`, `token_rewrite_hook.py` (Bash only) | Validate task graph compliance; block non-delegated tools; rewrite Bash commands for token efficiency |
259+
| **PreToolUse** | `validate_task_graph_compliance.py`, `require_delegation.py`, `token_rewrite_hook.py` (Bash only) | Validate task graph compliance; block non-delegated tools; rewrite Bash commands for token efficiency (cd && pattern, eslint, next, tsc support) |
260260
| **PostToolUse** | `python_posttooluse_hook.py` (Edit/Write), `remind_skill_continuation.py` (ExitPlanMode/Skill/SlashCommand), `validate_task_graph_depth.py` (Agent/Task), `remind_todo_after_task.py` (Agent/Task, async) | Python validation (Ruff/Pyright); workflow continuation state; depth-3 enforcement; task reminders |
261261
| **UserPromptSubmit** | `clear-delegation-sessions.py` | Clear delegation/team state, record turn timestamp |
262-
| **SessionStart** | `inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py` | Inject system prompts (workflow orchestration, output style, token efficiency) |
262+
| **SessionStart** | `inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py` | Inject conditional orchestrator (stub on startup, full on /delegate), output style, token efficiency guidance |
263263
| **SubagentStop** | `remind_todo_update.py` (async), `trigger_verification.py` | Remind to update tasks, suggest verification |
264264
| **Stop** | `python_stop_hook.py` | Turn duration tracking, workflow continuation |
265265

@@ -268,22 +268,10 @@ The `plugin-hooks.json` configures the delegation enforcement hooks using cross-
268268
Multi-step workflow orchestration requires the workflow_orchestrator system prompt to be appended:
269269

270270
**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.
287275

288276
**What this enables:**
289277
- Multi-step task detection via pattern matching
@@ -415,7 +403,7 @@ No other configuration is required. Plan mode automatically evaluates whether a
415403

416404
### How Mode Selection Works
417405

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:
419407

420408
| Factor | Points | Condition |
421409
|---------------------------------------|--------|--------------------------------------------------------|
@@ -428,7 +416,7 @@ During planning, plan mode calculates a `team_mode_score` based on task characte
428416
| Breadth task | -5 | Simple exploration is better as subagents |
429417
| Phase count <= 3 | -3 | Small workflows don't need team overhead |
430418

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.
432420

433421
### Subagent Mode vs Team Mode
434422

@@ -503,7 +491,7 @@ Team mode creates two additional state files (automatically cleaned up on comple
503491

504492
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`).
505493

506-
### Two-Layer Approach
494+
### Multi-Layer Approach
507495

508496
1. **Behavioral Guidance** — The `token_efficient_cli.md` system prompt (injected via SessionStart) teaches compact flag usage:
509497
- `git status -sb` (short branch format)
@@ -515,6 +503,13 @@ The framework minimizes command output to reduce context consumption and preserv
515503
- Git: `push`, `pull`, `commit`, `merge`, `rebase`, `status`, etc.
516504
- Test runners: `pytest`, `cargo test`, `npm/pnpm/yarn/bun test`, `vitest`, `jest`, `mocha`, etc.
517505
- Logs: `docker logs`, `kubectl logs`, `make` output
506+
- Build tools: `eslint`, `next`, `tsc`
507+
- Command chaining: `cd && command` pattern support
508+
509+
3. **Conditional System Prompt Injection** — The orchestrator is injected conditionally:
510+
- On session startup: Stub version (~200 tokens) provides minimal direction
511+
- On first plan mode entry (via /delegate or detected multi-step): Full version (~11K tokens) for complete planning capability
512+
- Saves tokens for single-step and read-only tasks
518513

519514
### Disable Token Efficiency
520515

0 commit comments

Comments
 (0)