@alexgreensh/token-optimizer 0.0.0-stage → 5.13.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +76 -0
- package/.claude-plugin/plugin.json +21 -0
- package/LICENSE +130 -0
- package/LICENSE-SMALL-BUSINESS.md +62 -0
- package/PRIVACY.md +200 -0
- package/README.md +13 -2
- package/hooks/codex-hooks.json +4 -0
- package/hooks/hooks.json +182 -0
- package/hooks/module_runner.py +149 -0
- package/hooks/posttooluse_runner.py +1110 -0
- package/hooks/python-launcher.sh +816 -0
- package/hooks/run.py +776 -0
- package/hooks/sessionstart_runner.py +629 -0
- package/hooks/stop_runner.py +408 -0
- package/hooks/userpromptsubmit_runner.py +722 -0
- package/hooks/windows-launcher.py +163 -0
- package/install-cloud.sh +23 -0
- package/package.json +29 -4
- package/skills/fleet-auditor/SKILL.md +150 -0
- package/skills/fleet-auditor/references/fleet-systems.md +167 -0
- package/skills/fleet-auditor/references/report-template.md +50 -0
- package/skills/fleet-auditor/references/waste-patterns.md +126 -0
- package/skills/fleet-auditor/scripts/fleet.py +3612 -0
- package/skills/fleet-auditor/scripts/shared.py +277 -0
- package/skills/resume-checkpoint/SKILL.md +52 -0
- package/skills/resume-checkpoint/scripts/pull_checkpoint.py +188 -0
- package/skills/token-coach/SKILL.md +129 -0
- package/skills/token-coach/assets/coach-dashboard-tab.html +45 -0
- package/skills/token-coach/examples/coaching-session-agentic.md +62 -0
- package/skills/token-coach/examples/coaching-session-heavy-setup.md +46 -0
- package/skills/token-coach/examples/coaching-session-new-project.md +38 -0
- package/skills/token-coach/references/agentic-systems.md +147 -0
- package/skills/token-coach/references/coach-patterns.md +120 -0
- package/skills/token-coach/references/coaching-scripts.md +146 -0
- package/skills/token-coach/references/deterministic-stages.md +102 -0
- package/skills/token-coach/references/keepwarm-consent.md +48 -0
- package/skills/token-coach/references/quick-reference.md +155 -0
- package/skills/token-dashboard/SKILL.md +72 -0
- package/skills/token-optimizer/SKILL.md +150 -0
- package/skills/token-optimizer/assets/dashboard.html +7251 -0
- package/skills/token-optimizer/examples/claude-md-optimized.md +40 -0
- package/skills/token-optimizer/examples/hooks-starter.json +179 -0
- package/skills/token-optimizer/examples/permissions-deny-template.json +24 -0
- package/skills/token-optimizer/pricing/prices.json +695 -0
- package/skills/token-optimizer/references/agent-prompts.md +687 -0
- package/skills/token-optimizer/references/cli-reference.md +92 -0
- package/skills/token-optimizer/references/codex-workflow.md +188 -0
- package/skills/token-optimizer/references/cursor-workflow.md +74 -0
- package/skills/token-optimizer/references/error-recovery.md +37 -0
- package/skills/token-optimizer/references/implementation-playbook.md +416 -0
- package/skills/token-optimizer/references/keepwarm-consent.md +48 -0
- package/skills/token-optimizer/references/opencode-workflow.md +72 -0
- package/skills/token-optimizer/references/optimization-checklist.md +714 -0
- package/skills/token-optimizer/references/phase0-setup.md +142 -0
- package/skills/token-optimizer/references/presentation-workflow.md +72 -0
- package/skills/token-optimizer/references/session-continuity.md +19 -0
- package/skills/token-optimizer/references/token-flow-architecture.md +629 -0
- package/skills/token-optimizer/scripts/activity_tracker.py +143 -0
- package/skills/token-optimizer/scripts/antigravity_doctor.py +548 -0
- package/skills/token-optimizer/scripts/antigravity_hook_bridge.py +511 -0
- package/skills/token-optimizer/scripts/antigravity_install.py +376 -0
- package/skills/token-optimizer/scripts/antigravity_proto.py +413 -0
- package/skills/token-optimizer/scripts/antigravity_session.py +346 -0
- package/skills/token-optimizer/scripts/antigravity_state.py +486 -0
- package/skills/token-optimizer/scripts/archive_result.py +1725 -0
- package/skills/token-optimizer/scripts/bash_compress.py +2490 -0
- package/skills/token-optimizer/scripts/bash_compress_hook.py +766 -0
- package/skills/token-optimizer/scripts/bash_hook.py +61 -0
- package/skills/token-optimizer/scripts/bash_whitelist.py +243 -0
- package/skills/token-optimizer/scripts/benchmark.py +1765 -0
- package/skills/token-optimizer/scripts/build_output_compress.py +776 -0
- package/skills/token-optimizer/scripts/cloud_kit.py +991 -0
- package/skills/token-optimizer/scripts/codex_command_compress.py +434 -0
- package/skills/token-optimizer/scripts/codex_compact_prompt.py +273 -0
- package/skills/token-optimizer/scripts/codex_doctor.py +454 -0
- package/skills/token-optimizer/scripts/codex_hook_bridge.py +311 -0
- package/skills/token-optimizer/scripts/codex_install.py +810 -0
- package/skills/token-optimizer/scripts/codex_io.py +119 -0
- package/skills/token-optimizer/scripts/codex_log_index.py +219 -0
- package/skills/token-optimizer/scripts/codex_models.py +34 -0
- package/skills/token-optimizer/scripts/codex_session.py +1186 -0
- package/skills/token-optimizer/scripts/codex_state.py +707 -0
- package/skills/token-optimizer/scripts/codex_statusline.py +303 -0
- package/skills/token-optimizer/scripts/command_filters.py +386 -0
- package/skills/token-optimizer/scripts/compression_backfill.py +600 -0
- package/skills/token-optimizer/scripts/compression_log.py +230 -0
- package/skills/token-optimizer/scripts/context_intel.py +331 -0
- package/skills/token-optimizer/scripts/context_pressure.py +115 -0
- package/skills/token-optimizer/scripts/copilot_doctor.py +406 -0
- package/skills/token-optimizer/scripts/copilot_hook_bridge.py +709 -0
- package/skills/token-optimizer/scripts/copilot_install.py +277 -0
- package/skills/token-optimizer/scripts/copilot_session.py +496 -0
- package/skills/token-optimizer/scripts/copilot_state.py +569 -0
- package/skills/token-optimizer/scripts/copilot_vscode.py +832 -0
- package/skills/token-optimizer/scripts/cowork_doctor.py +270 -0
- package/skills/token-optimizer/scripts/cowork_install.py +380 -0
- package/skills/token-optimizer/scripts/credential_patterns.py +1514 -0
- package/skills/token-optimizer/scripts/cursor_doctor.py +602 -0
- package/skills/token-optimizer/scripts/cursor_hook_bridge.py +843 -0
- package/skills/token-optimizer/scripts/cursor_install.py +423 -0
- package/skills/token-optimizer/scripts/cursor_session.py +303 -0
- package/skills/token-optimizer/scripts/cursor_state.py +348 -0
- package/skills/token-optimizer/scripts/delta_diff.py +110 -0
- package/skills/token-optimizer/scripts/detectors/__init__.py +2 -0
- package/skills/token-optimizer/scripts/detectors/bad_decomposition.py +78 -0
- package/skills/token-optimizer/scripts/detectors/cache_instability.py +504 -0
- package/skills/token-optimizer/scripts/detectors/looping.py +88 -0
- package/skills/token-optimizer/scripts/detectors/output_waste.py +143 -0
- package/skills/token-optimizer/scripts/detectors/overpowered.py +116 -0
- package/skills/token-optimizer/scripts/detectors/pdf_ingestion.py +52 -0
- package/skills/token-optimizer/scripts/detectors/registry.py +65 -0
- package/skills/token-optimizer/scripts/detectors/respond_to_bash.py +76 -0
- package/skills/token-optimizer/scripts/detectors/retry_churn.py +83 -0
- package/skills/token-optimizer/scripts/detectors/tool_cascade.py +62 -0
- package/skills/token-optimizer/scripts/detectors/wasteful_thinking.py +75 -0
- package/skills/token-optimizer/scripts/detectors/weak_model.py +55 -0
- package/skills/token-optimizer/scripts/detectors/websearch_routing.py +72 -0
- package/skills/token-optimizer/scripts/deterministic_candidates.py +1458 -0
- package/skills/token-optimizer/scripts/devin_compress.py +790 -0
- package/skills/token-optimizer/scripts/devin_doctor.py +403 -0
- package/skills/token-optimizer/scripts/devin_hooks.py +453 -0
- package/skills/token-optimizer/scripts/devin_install.py +1086 -0
- package/skills/token-optimizer/scripts/devin_source.py +119 -0
- package/skills/token-optimizer/scripts/devin_state.py +330 -0
- package/skills/token-optimizer/scripts/devin_verify.py +67 -0
- package/skills/token-optimizer/scripts/grok_doctor.py +560 -0
- package/skills/token-optimizer/scripts/grok_hook_bridge.py +699 -0
- package/skills/token-optimizer/scripts/grok_install.py +397 -0
- package/skills/token-optimizer/scripts/grok_session.py +317 -0
- package/skills/token-optimizer/scripts/grok_state.py +299 -0
- package/skills/token-optimizer/scripts/hermes_doctor.py +479 -0
- package/skills/token-optimizer/scripts/hermes_hook_bridge.py +285 -0
- package/skills/token-optimizer/scripts/hermes_install.py +668 -0
- package/skills/token-optimizer/scripts/hermes_session.py +691 -0
- package/skills/token-optimizer/scripts/hermes_state.py +448 -0
- package/skills/token-optimizer/scripts/hook_io.py +120 -0
- package/skills/token-optimizer/scripts/hook_runtime.py +713 -0
- package/skills/token-optimizer/scripts/injection.py +156 -0
- package/skills/token-optimizer/scripts/install_reconcile.py +952 -0
- package/skills/token-optimizer/scripts/measure.py +58739 -0
- package/skills/token-optimizer/scripts/outline.py +53 -0
- package/skills/token-optimizer/scripts/pipeline_analyzer.py +723 -0
- package/skills/token-optimizer/scripts/plugin_env.py +562 -0
- package/skills/token-optimizer/scripts/py_trust.py +80 -0
- package/skills/token-optimizer/scripts/quality_cache_gate.py +320 -0
- package/skills/token-optimizer/scripts/read_cache.py +2489 -0
- package/skills/token-optimizer/scripts/recovery_output.py +110 -0
- package/skills/token-optimizer/scripts/refetch_fingerprint.py +236 -0
- package/skills/token-optimizer/scripts/refetch_guard.py +244 -0
- package/skills/token-optimizer/scripts/routing_advisor.py +389 -0
- package/skills/token-optimizer/scripts/runtime_env.py +1893 -0
- package/skills/token-optimizer/scripts/session_store.py +979 -0
- package/skills/token-optimizer/scripts/spawn_utils.py +122 -0
- package/skills/token-optimizer/scripts/statusline.js +660 -0
- package/skills/token-optimizer/scripts/structure_map.py +2880 -0
- package/skills/token-optimizer/scripts/structure_map_ts.py +676 -0
- package/skills/token-optimizer/scripts/structure_replay.py +1556 -0
- package/skills/token-optimizer/scripts/thrash_guard.py +604 -0
- package/skills/token-optimizer/scripts/token_estimate.py +80 -0
- package/skills/token-optimizer/scripts/tool_search_diagnostic.py +61 -0
- package/skills/token-optimizer/scripts/utf8_io.py +219 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!-- Coach Dashboard Tab Fragment
|
|
2
|
+
Integrated into token-optimizer dashboard.html as the "Coach" tab.
|
|
3
|
+
Data comes from generate_coach_data() in measure.py, injected as data.coach.
|
|
4
|
+
|
|
5
|
+
This file is a reference copy. The actual rendering lives in dashboard.html's
|
|
6
|
+
renderCoach() function. Update both if modifying the coach tab layout.
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
<!-- Nav item (add to .nav-menu): -->
|
|
10
|
+
<!-- <a class="nav-item" data-view="coach">Coach</a> -->
|
|
11
|
+
|
|
12
|
+
<!-- View container (add to main-col): -->
|
|
13
|
+
<!-- <div class="view" id="view-coach"></div> -->
|
|
14
|
+
|
|
15
|
+
<!-- Rendering: renderCoach() in dashboard.html JavaScript section -->
|
|
16
|
+
<!-- Called from init() after renderHealth() -->
|
|
17
|
+
|
|
18
|
+
<!-- Data structure expected (from measure.py generate_coach_data()): -->
|
|
19
|
+
<!--
|
|
20
|
+
{
|
|
21
|
+
"health_score": 0-100,
|
|
22
|
+
"snapshot": {
|
|
23
|
+
"total_overhead": number,
|
|
24
|
+
"controllable": number,
|
|
25
|
+
"fixed": number,
|
|
26
|
+
"context_window": number,
|
|
27
|
+
"overhead_pct": number,
|
|
28
|
+
"usable_tokens": number,
|
|
29
|
+
"skill_count": number,
|
|
30
|
+
"skill_tokens": number,
|
|
31
|
+
"claude_md_tokens": number,
|
|
32
|
+
"memory_md_lines": number,
|
|
33
|
+
"mcp_server_count": number,
|
|
34
|
+
"mcp_tokens": number,
|
|
35
|
+
"rules_count": number,
|
|
36
|
+
"rules_always_loaded": number,
|
|
37
|
+
"imports_count": number,
|
|
38
|
+
"imports_tokens": number
|
|
39
|
+
},
|
|
40
|
+
"patterns_good": [{"name": string, "detail": string}],
|
|
41
|
+
"patterns_bad": [{"name": string, "severity": "high"|"medium"|"low", "detail": string, "fix": string, "savings": string}],
|
|
42
|
+
"questions": [string],
|
|
43
|
+
"focus_area": string|null
|
|
44
|
+
}
|
|
45
|
+
-->
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Example: Coaching Session for Multi-Agent Architecture
|
|
2
|
+
|
|
3
|
+
User chose option (c): Designing a multi-agent system, want architecture advice.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Coach Output
|
|
8
|
+
|
|
9
|
+
**Coach**: Multi-agent is where token optimization really matters. Every agent multiplies your config overhead. Your current setup costs ~18,500 tokens at startup. With multiple agents, that compounds fast.
|
|
10
|
+
|
|
11
|
+
Walk me through what you're building. How many agents? What does each one do?
|
|
12
|
+
|
|
13
|
+
**User**: I'm building a research automation. 4 agents: one scrapes web sources, one reads local documents, one analyzes findings, one writes the final report.
|
|
14
|
+
|
|
15
|
+
**Coach**: Four agents. Let's do the math on your current config:
|
|
16
|
+
|
|
17
|
+
- 4 agents x ~18,500 config overhead = 74,000 tokens just for agent setup
|
|
18
|
+
- Plus the orchestrator's own session = ~18,500 more
|
|
19
|
+
- Total infrastructure cost: ~92,500 tokens before any actual work
|
|
20
|
+
|
|
21
|
+
That's 46% of a single context window (though agents each get their own window, this matters for cost/rate limits).
|
|
22
|
+
|
|
23
|
+
Let's optimize each agent:
|
|
24
|
+
|
|
25
|
+
**Web scraper**: Data-gathering only. This should be a read-only agent on the cheapest model. Explore inherits your main model, so define a custom read-only subagent with `model: haiku`. It reads web content, returns summaries. It does NOT need your 54 skills or Opus-level reasoning. The cheapest tier cuts this agent's per-token cost the most.
|
|
26
|
+
|
|
27
|
+
**Document reader**: Also data-gathering. Another read-only agent on the cheapest model. It reads local files and extracts relevant content. Read-only is fine here.
|
|
28
|
+
|
|
29
|
+
**Analyzer**: This one needs judgment. Sonnet is the right model. It takes structured input from the first two agents and produces analysis. Still no need for full skill access unless it uses a specific analysis skill.
|
|
30
|
+
|
|
31
|
+
**Report writer**: Needs write access (to create the report file). General-purpose agent, Sonnet or Opus depending on report complexity. Only assign the specific writing-related skill if you have one.
|
|
32
|
+
|
|
33
|
+
**User**: The analyzer sometimes needs to look up additional files based on what it finds. Does that change things?
|
|
34
|
+
|
|
35
|
+
**Coach**: Good catch. If the analyzer needs to read files reactively, it can't be a read-only agent. Make it a general-purpose agent with Sonnet, but don't assign skills it doesn't need. The key distinction: Read-only agents are for pre-planned reads. General-purpose agents handle reactive, multi-step tasks.
|
|
36
|
+
|
|
37
|
+
For the coordination pattern: create a project-local folder (gitignore it). Each agent writes findings to it. The orchestrator tracks completion. The report writer reads from the findings folder directly, never from the orchestrator's context. This prevents your orchestrator from bloating with raw agent output.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
.token-coordination/
|
|
41
|
+
COORDINATION.md
|
|
42
|
+
findings/
|
|
43
|
+
web-sources.md # Web scraper writes here
|
|
44
|
+
local-docs.md # Document reader writes here
|
|
45
|
+
analysis.md # Analyzer writes here
|
|
46
|
+
output/
|
|
47
|
+
final-report.md # Report writer creates here
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**User**: Should I slim my CLAUDE.md before building this?
|
|
51
|
+
|
|
52
|
+
**Coach**: 100%. Your CLAUDE.md at 2,180 tokens loads in EVERY agent. 5 agents (including orchestrator) = 10,900 tokens just for CLAUDE.md copies. If you trim to 800 tokens, that's 5 x 800 = 4,000 tokens. You'd save 6,900 tokens across the system.
|
|
53
|
+
|
|
54
|
+
Same logic for skills: 54 skills x 5 agents = frontmatter loading 5 times. Archive unused skills, save ~3,500 x 5 = 17,500 tokens across all agents.
|
|
55
|
+
|
|
56
|
+
## Action Plan
|
|
57
|
+
|
|
58
|
+
1. **Assign correct agent types**: Web scraper and doc reader as read-only custom agents on the cheapest model. Analyzer as general-purpose/Sonnet. Report writer as general-purpose/Sonnet. (Largest per-token cut on the data-gathering agents)
|
|
59
|
+
2. **Implement coordination folder**: Agents write to files, orchestrator reads summaries only. Prevents context overflow.
|
|
60
|
+
3. **Slim CLAUDE.md to 800 tokens**: Saves ~6,900 tokens across 5 agents (5 x 1,380 tokens saved).
|
|
61
|
+
4. **Archive unused skills**: Saves ~17,500 tokens across 5 agents (5 x 3,500 tokens saved).
|
|
62
|
+
5. **No skill assignments to data-gathering agents**: Web scraper and doc reader need zero skills. Analyzer gets only the analysis skill. Report writer gets only the writing skill.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Example: Coaching Session for a Heavy Setup
|
|
2
|
+
|
|
3
|
+
User chose option (b): Existing project feels sluggish / context fills too fast.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Coach Output
|
|
8
|
+
|
|
9
|
+
**Coach**: Found the weight. Your setup uses ~32,400 tokens at startup. That's 16.2% of your 200K window before you type anything (on a 1M window it would be about 3%). With auto-compact headroom reserved on top, most of that window is already spoken for.
|
|
10
|
+
|
|
11
|
+
The top 3 overhead sources:
|
|
12
|
+
1. **54 skills**: ~5,400 tokens in the startup menu. You've got the 50-Skill Trap going on.
|
|
13
|
+
2. **CLAUDE.md**: 2,180 tokens. That's over the 800-token target. The CLAUDE.md Novel pattern.
|
|
14
|
+
3. **8 MCP servers**: ~1,200 tokens between tool names and server instructions.
|
|
15
|
+
|
|
16
|
+
When does it feel slow? Early in sessions, after a few messages, or during multi-agent work?
|
|
17
|
+
|
|
18
|
+
**User**: After about 10-15 messages. Compaction keeps hitting and I lose context.
|
|
19
|
+
|
|
20
|
+
**Coach**: That tracks. You're starting at 16.2% used. Each message adds conversation history plus file reads. By message 10-15, you're likely deep into the window, where retrieval quality has slipped and compaction triggers.
|
|
21
|
+
|
|
22
|
+
Two things would help most:
|
|
23
|
+
|
|
24
|
+
First, your skills: 54 installed, but in the last 30 days you've only invoked 19 of them. Those 35 unused skills cost ~3,500 tokens per session for zero benefit. Move them to ~/.claude/_backups/skills-archived/. You can always move them back.
|
|
25
|
+
|
|
26
|
+
Second, your CLAUDE.md has a 400-line section about coding standards that should be a skill. As a skill, it'd cost ~100 tokens in the menu instead of ~2,000 tokens every message. That's a 95% reduction on that content alone.
|
|
27
|
+
|
|
28
|
+
Together: ~5,500 tokens recovered per session. That buys you roughly 3-4 more messages before compaction.
|
|
29
|
+
|
|
30
|
+
**User**: Which skills should I archive?
|
|
31
|
+
|
|
32
|
+
**Coach**: Looking at your trends data, these 35 skills haven't been invoked in 30 days: [list]. Before archiving, scan for any that are seasonal (deploy skills you use monthly, tax-season skills, etc.). Keep those. Archive the rest.
|
|
33
|
+
|
|
34
|
+
The quick process:
|
|
35
|
+
```bash
|
|
36
|
+
mkdir -p ~/.claude/_backups/skills-archived
|
|
37
|
+
mv ~/.claude/skills/[skill-name] ~/.claude/_backups/skills-archived/
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Action Plan
|
|
41
|
+
|
|
42
|
+
1. **Archive 35 unused skills** (Quick Win): Move to ~/.claude/_backups/skills-archived/. Recovers ~3,500 tokens/session.
|
|
43
|
+
2. **Extract coding standards from CLAUDE.md to a skill** (Medium): Create a coding-standards skill. Recovers ~1,900 tokens/message.
|
|
44
|
+
3. **Review 8 MCP servers** (Medium): Disable servers you don't use in CLI. Ask yourself which you actually use in conversation before disabling.
|
|
45
|
+
4. **Use /compact at phase boundaries** (Habit): Don't wait for auto-compact. Run /compact proactively around message 8-10 given your current setup, and set `/autocompact` below the tuned default if you want compaction to fire earlier.
|
|
46
|
+
5. **Run /token-optimizer for full audit**: Get the before/after measurement and automated fixes.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Example: Coaching Session for Building a New Project
|
|
2
|
+
|
|
3
|
+
User chose option (a): Building something new, want it token-efficient from the start.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Coach Output
|
|
8
|
+
|
|
9
|
+
**Coach**: Your current setup starts every session with ~18,200 tokens of overhead. That's 9.1% of your context window, pretty reasonable. The big items: CLAUDE.md at 1,450 tokens, 23 skills at ~2,300 tokens, and 4 MCP servers at ~480 tokens.
|
|
10
|
+
|
|
11
|
+
What are you building?
|
|
12
|
+
|
|
13
|
+
**User**: A multi-step skill for doing code reviews. It should read files, run tests, and generate a review summary.
|
|
14
|
+
|
|
15
|
+
**Coach**: Good scope. For a code review skill, the architecture is:
|
|
16
|
+
|
|
17
|
+
1. **SKILL.md** (~80 lines, ~1,200 tokens on invoke): Orchestrator only. Phase 0 resolves paths, Phase 1 collects code context, Phase 2 analyzes, Phase 3 generates summary. Keep the body focused on control flow.
|
|
18
|
+
|
|
19
|
+
2. **references/review-criteria.md**: Your review standards, patterns to check for, severity levels. Zero tokens until the skill reads it. This is where the heavy domain knowledge goes.
|
|
20
|
+
|
|
21
|
+
3. **references/output-templates.md**: Example review outputs. Also zero cost until read.
|
|
22
|
+
|
|
23
|
+
Your frontmatter budget: description under 80 chars. Something like "Code review with test verification and structured summary." That's 56 chars, perfect.
|
|
24
|
+
|
|
25
|
+
The skill adds ~100 tokens to your startup overhead (frontmatter in the menu). Full cost of ~1,200 tokens only when someone invokes /code-review. The reference files cost zero unless the skill explicitly reads them during execution.
|
|
26
|
+
|
|
27
|
+
**User**: Should I use subagents for the test running?
|
|
28
|
+
|
|
29
|
+
**Coach**: Yes, for one reason: context isolation. When the skill reads code files for review, those stay in context. Running tests can produce verbose output. A subagent for test execution keeps that output in its own window and reports back just pass/fail + relevant failures.
|
|
30
|
+
|
|
31
|
+
Use an Explore agent (read-only) if you just need to read test results. Use a general-purpose agent if you need to actually run the tests via Bash. Either way, don't assign skills to the test agent unless it specifically needs them.
|
|
32
|
+
|
|
33
|
+
## Action Plan
|
|
34
|
+
|
|
35
|
+
1. **Create skill skeleton**: SKILL.md + references/ directory. Budget: ~100 tokens startup, ~1,200 on invoke. (~0 additional startup cost vs no skill)
|
|
36
|
+
2. **Keep description under 80 chars**: "Code review with test verification and structured summary" (56 chars)
|
|
37
|
+
3. **Use subagent for test execution**: Isolates verbose test output from review context. Use general-purpose agent with Bash access, no skill assignments.
|
|
38
|
+
4. **Put review criteria in references/**: Zero cost until the skill reads them. Don't inline domain knowledge in SKILL.md body.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Agentic Systems: Multi-Agent Design Patterns for Token Efficiency
|
|
2
|
+
|
|
3
|
+
Reference file for Token Coach. Loaded ONLY for option c (multi-agent architecture).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Contents
|
|
8
|
+
|
|
9
|
+
- [The Cost Model](#the-cost-model)
|
|
10
|
+
- [Design Patterns](#design-patterns)
|
|
11
|
+
- [Anti-Patterns in Multi-Agent Design](#anti-patterns-in-multi-agent-design)
|
|
12
|
+
- [Quick Decision Framework](#quick-decision-framework)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## The Cost Model
|
|
17
|
+
|
|
18
|
+
Every subagent gets its own fresh context window sized to its model (1M tokens on current Claude models). This is both the power and the cost of multi-agent architectures.
|
|
19
|
+
|
|
20
|
+
### What Each Agent Inherits
|
|
21
|
+
- System prompt + built-in tools: ~15K tokens (FIXED, same as your main session)
|
|
22
|
+
- MCP tool definitions: same as your main session (deferred or eager)
|
|
23
|
+
- Skills frontmatter: same menu as your main session (~100 tokens/skill)
|
|
24
|
+
- Global CLAUDE.md: full content, every agent
|
|
25
|
+
- MEMORY.md: full content, every agent
|
|
26
|
+
|
|
27
|
+
### What Each Agent Does NOT Inherit
|
|
28
|
+
- Your conversation history (good, this is why subagents are useful)
|
|
29
|
+
- Files you've already read (they start fresh)
|
|
30
|
+
- Results from other subagents
|
|
31
|
+
|
|
32
|
+
### The Math
|
|
33
|
+
- 5 agents x 15K config overhead = 75K tokens just for setup
|
|
34
|
+
- Slimming CLAUDE.md by 1,000 tokens saves 5,000 tokens across 5 agents
|
|
35
|
+
- Measured native agent overhead: ~13K tokens per agent
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Design Patterns
|
|
40
|
+
|
|
41
|
+
### Pattern 1: Subagent as Context Isolation
|
|
42
|
+
Anthropic's official recommendation: use subagents to preserve main session context.
|
|
43
|
+
- Every file Claude reads stays in your context until compaction
|
|
44
|
+
- Subagents run in their own window and return only summaries
|
|
45
|
+
- Prompt: "use a subagent to investigate X" keeps your main window clean
|
|
46
|
+
- Think of subagents as disposable research assistants, not just parallel workers
|
|
47
|
+
|
|
48
|
+
### Pattern 2: The Coordination Folder
|
|
49
|
+
Prevents orchestrator context overflow from agent outputs. Use a project-local folder (add it to `.gitignore` so agent output never lands in a commit or a shared temp directory):
|
|
50
|
+
```
|
|
51
|
+
.coordination/
|
|
52
|
+
COORDINATION.md # Status tracker
|
|
53
|
+
findings/ # Agents write here
|
|
54
|
+
agent-1-findings.md
|
|
55
|
+
agent-2-findings.md
|
|
56
|
+
status/ # Agent completion signals
|
|
57
|
+
```
|
|
58
|
+
- Agents write FULL findings to files
|
|
59
|
+
- Orchestrator gets "Agent X completed, output at {path}" not the full output
|
|
60
|
+
- Synthesis agent reads files directly
|
|
61
|
+
- Do not pull raw agent output into the orchestrator's context; the whole point of the folder is that the orchestrator reads one line per agent, not every finding
|
|
62
|
+
|
|
63
|
+
### Pattern 3: Parallel Dispatch for Independent Tasks
|
|
64
|
+
- Independent tasks in one message with multiple Agent tool calls
|
|
65
|
+
- Don't dispatch sequentially when tasks have no dependencies
|
|
66
|
+
- Each parallel agent gets its own fresh context
|
|
67
|
+
- Total token usage is the same, but wall-clock time is much less
|
|
68
|
+
|
|
69
|
+
### Pattern 4: Model Routing for Agents
|
|
70
|
+
Default routing table:
|
|
71
|
+
| Task Type | Model tier | Why |
|
|
72
|
+
|-----------|-------|-----|
|
|
73
|
+
| File reading, counting, directory scans | haiku | The cheapest tier is accurate enough for data gathering |
|
|
74
|
+
| Code analysis, judgment calls, writing | sonnet | Good balance of quality and cost |
|
|
75
|
+
| Complex multi-step reasoning, architecture | opus | Only when you need deep reasoning |
|
|
76
|
+
|
|
77
|
+
Add to CLAUDE.md: "Default subagents to model='haiku' for data gathering, model='sonnet' for analysis. Reserve model='opus' for complex reasoning."
|
|
78
|
+
|
|
79
|
+
### Pattern 5: Surgical Skill Assignments
|
|
80
|
+
- Skills in a subagent's `skills:` field load FULLY at agent startup (not progressively)
|
|
81
|
+
- 5 skills x 3K tokens each = 15K tokens before the agent does anything
|
|
82
|
+
- Only assign skills the agent actually needs
|
|
83
|
+
- Built-in agents (Explore, Plan) don't get skills at all
|
|
84
|
+
- Reference files within assigned skills still load progressively
|
|
85
|
+
|
|
86
|
+
### Pattern 6: Built-in Agent Type Selection
|
|
87
|
+
| Type | Access | Use For |
|
|
88
|
+
|------|--------|---------|
|
|
89
|
+
| Explore | Read-only (Glob, Grep, Read) | Codebase navigation, file search |
|
|
90
|
+
| Plan | Read-only | Planning, architecture analysis |
|
|
91
|
+
| General-purpose | Full tools | Tasks requiring write access |
|
|
92
|
+
| Custom | You configure | Specialized workflows |
|
|
93
|
+
|
|
94
|
+
Use Explore when you just need to find things. Use Plan when you need reasoning without edits. Use General-purpose only when the agent needs to write files.
|
|
95
|
+
|
|
96
|
+
Built-in Explore and Plan run on the main conversation's model, and General-purpose does too unless `CLAUDE_CODE_SUBAGENT_MODEL` or the `model` field sets another. To get a lighter tier for reads, define a read-only custom subagent with `model: haiku` (or set `CLAUDE_CODE_SUBAGENT_MODEL` together with `CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1`, which also forces Explore and Plan).
|
|
97
|
+
|
|
98
|
+
### Pattern 7: Agent Team Cost-Benefit Analysis
|
|
99
|
+
Anthropic's docs report that agent teams use roughly 7x the tokens of a single session in plan mode.
|
|
100
|
+
- Agent teams buy wall-clock speed with token cost
|
|
101
|
+
- Break-even: only use teams when the time savings justify several times the token cost
|
|
102
|
+
- For budget-conscious users: single agent with selective /dispatch for parallelizable subtasks
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Anti-Patterns in Multi-Agent Design
|
|
107
|
+
|
|
108
|
+
### The Context Flood
|
|
109
|
+
**Problem**: Orchestrator reads back all agent output files into its own context.
|
|
110
|
+
**Symptoms**: Orchestrator hits compaction after 2-3 agents report back.
|
|
111
|
+
**Fix**: Orchestrator receives only "Agent X completed at {path}". Synthesis agent reads files.
|
|
112
|
+
|
|
113
|
+
### The Clone Army
|
|
114
|
+
**Problem**: Every agent is general-purpose with full tools and default model.
|
|
115
|
+
**Symptoms**: High cost. Agents doing simple reads with Opus.
|
|
116
|
+
**Fix**: Use read-only agents for reads and give them a lighter `model`; Explore and Plan inherit the main model unless you force one. Route model by task complexity.
|
|
117
|
+
|
|
118
|
+
### The Skill Dump
|
|
119
|
+
**Problem**: Custom agents assigned all available skills "just in case."
|
|
120
|
+
**Symptoms**: Each agent loads 10+ skills fully at startup. 30K+ tokens before work begins.
|
|
121
|
+
**Fix**: Assign only the 1-2 skills each agent actually needs.
|
|
122
|
+
|
|
123
|
+
### The Sequential Chain
|
|
124
|
+
**Problem**: Independent tasks dispatched one at a time instead of in parallel.
|
|
125
|
+
**Symptoms**: 5 minute task takes 25 minutes. Same total tokens, much longer wall-clock.
|
|
126
|
+
**Fix**: Launch independent agents in a single message with multiple Agent tool calls.
|
|
127
|
+
|
|
128
|
+
### The Missing Handoff
|
|
129
|
+
**Problem**: No coordination folder. Agents can't see each other's work.
|
|
130
|
+
**Symptoms**: Duplicate work. Agents solving the same problem independently. No synthesis.
|
|
131
|
+
**Fix**: Create a coordination folder. Agents write findings to it. Orchestrator tracks status.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Quick Decision Framework
|
|
136
|
+
|
|
137
|
+
**Should I use subagents for this task?**
|
|
138
|
+
1. Does the task require reading many files? -> YES, use subagents for context isolation
|
|
139
|
+
2. Are there 3+ independent subtasks? -> YES, parallel dispatch
|
|
140
|
+
3. Is it a simple, focused task? -> NO, single session is simpler and cheaper
|
|
141
|
+
4. Am I hitting compaction frequently? -> YES, subagents help by isolating file reads
|
|
142
|
+
|
|
143
|
+
**How many agents?**
|
|
144
|
+
- 1 agent: Simple tasks, focused edits, single-module changes
|
|
145
|
+
- 2-3 agents: Multi-module tasks with clear boundaries
|
|
146
|
+
- 4-6 agents: Large refactors, cross-cutting changes, parallel research
|
|
147
|
+
- 7+ agents: Rarely justified. Coordination overhead exceeds benefits.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Coach Patterns: Architecture Patterns and Anti-Patterns
|
|
2
|
+
|
|
3
|
+
Reference file for Token Coach. Loaded for options a/b/d (config optimization).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Contents
|
|
8
|
+
|
|
9
|
+
- [Architecture Patterns (The "What To Do" Layer)](#architecture-patterns-the-what-to-do-layer)
|
|
10
|
+
- [Anti-Patterns (Common Mistakes with Fixes)](#anti-patterns-common-mistakes-with-fixes)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Architecture Patterns (The "What To Do" Layer)
|
|
15
|
+
|
|
16
|
+
### Pattern 1: Skill Design for Minimal Overhead
|
|
17
|
+
- SKILL.md body under 500 lines (Anthropic's recommendation)
|
|
18
|
+
- Description field under 200 characters, but trigger-rich (helps Claude suggest the skill)
|
|
19
|
+
- Heavy content in references/ (zero cost until explicitly read)
|
|
20
|
+
- Frontmatter is ~60-100 tokens per skill, loaded every session
|
|
21
|
+
- Full SKILL.md body loads on invocation (2K-5K tokens)
|
|
22
|
+
- References load only when the skill reads them (zero until then)
|
|
23
|
+
|
|
24
|
+
### Pattern 2: CLAUDE.md Layering
|
|
25
|
+
- Global CLAUDE.md (~/.claude/CLAUDE.md): Identity, critical rules, key paths, model routing. Target <800 tokens.
|
|
26
|
+
- Project CLAUDE.md (<project>/.claude/CLAUDE.md): Project-specific conventions, tech stack, file layout. Keep separate.
|
|
27
|
+
- CLAUDE.local.md: Personal overrides, not committed to repo.
|
|
28
|
+
- Rule: if content only applies to specific tasks, it belongs in a skill, not CLAUDE.md.
|
|
29
|
+
- Every line in CLAUDE.md costs tokens on EVERY message, EVERY session, in EVERY subagent.
|
|
30
|
+
|
|
31
|
+
### Pattern 3: MCP Server Consolidation
|
|
32
|
+
- Fewer servers with more tools > many servers with few tools
|
|
33
|
+
- Each server adds ~50-100 tokens of instruction text per message (even with deferred tools)
|
|
34
|
+
- Disable servers you don't use in CLI (re-enable anytime in settings.json)
|
|
35
|
+
- Cloud-synced servers (ENABLE_CLAUDEAI_MCP_SERVERS) may add tools you don't need in CLI
|
|
36
|
+
- Check for duplicate tools across servers and plugins
|
|
37
|
+
|
|
38
|
+
### Pattern 4: Rules Scoping
|
|
39
|
+
- Always use `paths:` frontmatter to scope rules to specific directories
|
|
40
|
+
- Rules without paths: load EVERY message, same cost as CLAUDE.md
|
|
41
|
+
- Audit unscoped rules: are they truly global, or just lazily unscoped?
|
|
42
|
+
- Consolidate overlapping rules into fewer files
|
|
43
|
+
|
|
44
|
+
### Pattern 5: Memory Hygiene
|
|
45
|
+
- MEMORY.md auto-loads first 200 lines every session
|
|
46
|
+
- Lines beyond 200 are truncated but still counted toward your window
|
|
47
|
+
- Move detailed notes to topic-specific files in memory/ directory
|
|
48
|
+
- Keep MEMORY.md as an index of high-signal, frequently-referenced items
|
|
49
|
+
- Dedup against CLAUDE.md (common source of waste)
|
|
50
|
+
|
|
51
|
+
### Pattern 6: Import Auditing
|
|
52
|
+
- @imports in CLAUDE.md pull entire files into every message
|
|
53
|
+
- Each @path/to/file.md adds that file's FULL token count to every message
|
|
54
|
+
- Grep CLAUDE.md for @ patterns, resolve paths, add up tokens
|
|
55
|
+
- Move large imports to skills or reference files that load on demand
|
|
56
|
+
|
|
57
|
+
### Pattern 7: Frontmatter Discipline
|
|
58
|
+
- Skill descriptions under 200 chars (80 chars is the sweet spot)
|
|
59
|
+
- Skill names under 30 chars
|
|
60
|
+
- Description should be a trigger phrase, not a paragraph
|
|
61
|
+
- Detailed usage instructions belong in SKILL.md body, not frontmatter
|
|
62
|
+
|
|
63
|
+
### Pattern 8: Progressive Loading via Skills
|
|
64
|
+
- Content in CLAUDE.md: costs tokens every message
|
|
65
|
+
- Same content as a skill: ~100 tokens in menu, full cost only on invocation
|
|
66
|
+
- That's 97% savings on messages that don't invoke the skill
|
|
67
|
+
- Rule of thumb: if content is only relevant to specific tasks, make it a skill
|
|
68
|
+
- Split heavy skill content into references/ (Tier 3, zero until read)
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Anti-Patterns (Common Mistakes with Fixes)
|
|
73
|
+
|
|
74
|
+
### The 50-Skill Trap
|
|
75
|
+
**Problem**: 50+ skills installed. Menu overhead: 5,000+ tokens every session.
|
|
76
|
+
**Symptoms**: Slow startup feel. Context fills faster than expected.
|
|
77
|
+
**Fix**: Archive unused skills to ~/.claude/_backups/skills-archived/. A subfolder inside skills/ still loads as a namespace, so move OUTSIDE skills/ entirely. Review with `measure.py trends` to see which skills you actually invoke.
|
|
78
|
+
**Savings**: ~100 tokens per archived skill per session.
|
|
79
|
+
|
|
80
|
+
### The Opus Addiction
|
|
81
|
+
**Problem**: 70%+ of token usage on Opus when Sonnet/Haiku would suffice.
|
|
82
|
+
**Symptoms**: High costs, hitting rate limits, budget burns fast.
|
|
83
|
+
**Fix**: Add model routing to CLAUDE.md: "Default subagents to haiku for data gathering, sonnet for analysis. Opus only for complex reasoning."
|
|
84
|
+
**Savings**: Large cost cuts on multi-agent workflows. Same context tokens, much less spend.
|
|
85
|
+
|
|
86
|
+
### The CLAUDE.md Novel
|
|
87
|
+
**Problem**: 200+ lines in global CLAUDE.md. 2,000+ tokens loading every message.
|
|
88
|
+
**Symptoms**: Config overhead dominates. Less room for actual work.
|
|
89
|
+
**Fix**: Progressive disclosure. Move workflows to skills. Move standards to reference files. Move gotchas to MEMORY.md. Target <800 tokens.
|
|
90
|
+
**Savings**: 400-1,200+ tokens per message.
|
|
91
|
+
|
|
92
|
+
### The Import Avalanche
|
|
93
|
+
**Problem**: Multiple @imports in CLAUDE.md pulling large files every message.
|
|
94
|
+
**Symptoms**: Unexpectedly high baseline token count. CLAUDE.md "feels small" but loads heavy.
|
|
95
|
+
**Fix**: Audit @import paths. Move large imports to skills. Keep only tiny, critical imports.
|
|
96
|
+
**Savings**: Varies wildly. Some users have 5,000+ tokens in forgotten imports.
|
|
97
|
+
|
|
98
|
+
### The MCP Sprawl
|
|
99
|
+
**Problem**: 15+ MCP servers configured, most rarely used.
|
|
100
|
+
**Symptoms**: High tool count in /context. Slow tool search. Context pressure.
|
|
101
|
+
**Fix**: Audit settings.json. Disable unused servers (can re-enable anytime). Check for cloud-synced servers from claude.ai.
|
|
102
|
+
**Savings**: ~50-100 tokens per disabled server (instruction overhead) plus reduced tool search noise.
|
|
103
|
+
|
|
104
|
+
### The Stale Memory
|
|
105
|
+
**Problem**: MEMORY.md duplicates CLAUDE.md content, or contains outdated entries.
|
|
106
|
+
**Symptoms**: Wasted tokens on redundant info. Potentially conflicting instructions.
|
|
107
|
+
**Fix**: Dedup MEMORY.md against CLAUDE.md. Remove resolved issues, completed migrations, one-time setup notes. Move verbose entries to topic files.
|
|
108
|
+
**Savings**: Depends on duplication level. Commonly 200-600 tokens.
|
|
109
|
+
|
|
110
|
+
### The Singleton Session
|
|
111
|
+
**Problem**: One long session for everything. Never uses /clear or /compact.
|
|
112
|
+
**Symptoms**: Quality degrades over time. Compaction happens unexpectedly. Hallucinations increase.
|
|
113
|
+
**Fix**: Session hygiene. /compact at phase boundaries, not mid-task. /clear between unrelated topics. Fresh session for fresh work. On a 1M model, set `/autocompact` below the ~967K default if you want compaction to land inside the quality zone.
|
|
114
|
+
**Savings**: Not token savings per se, but dramatically better output quality.
|
|
115
|
+
|
|
116
|
+
### The Unscoped Rules
|
|
117
|
+
**Problem**: All rules in .claude/rules/ lack paths: frontmatter.
|
|
118
|
+
**Symptoms**: Backend rules load when working on frontend. Testing rules load during docs work.
|
|
119
|
+
**Fix**: Add paths: frontmatter to scope rules to relevant directories.
|
|
120
|
+
**Savings**: Proportional to rule size. Can be hundreds of tokens per message.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Coaching Scripts: Conversation Flows for Each Intake Option
|
|
2
|
+
|
|
3
|
+
Reference file for Token Coach. Provides conversation structure for each coaching scenario.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Contents
|
|
8
|
+
|
|
9
|
+
- [General Coaching Principles](#general-coaching-principles)
|
|
10
|
+
- [Option A: Building Something New](#option-a-building-something-new)
|
|
11
|
+
- [Option B: Existing Project Feels Sluggish](#option-b-existing-project-feels-sluggish)
|
|
12
|
+
- [Option C: Designing a Multi-Agent System](#option-c-designing-a-multi-agent-system)
|
|
13
|
+
- [Option D: Quick Health Check](#option-d-quick-health-check)
|
|
14
|
+
- [Handling Follow-Up Questions](#handling-follow-up-questions)
|
|
15
|
+
- [Quality-Driven Coaching](#quality-driven-coaching)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## General Coaching Principles
|
|
20
|
+
|
|
21
|
+
1. **Lead with their data, not your knowledge.** "You have 47 skills" lands harder than "Skills cost tokens."
|
|
22
|
+
2. **One insight at a time.** Present 1-2 findings, then ask a question. Don't dump everything.
|
|
23
|
+
3. **Name the anti-pattern.** "You've got the 50-Skill Trap" is memorable. "You have many skills" is forgettable.
|
|
24
|
+
4. **Quantify everything.** "~4,700 tokens" beats "a lot of tokens."
|
|
25
|
+
5. **Respect their workflow.** Some skills matter even if rarely invoked. Ask before recommending removal.
|
|
26
|
+
6. **End with action, not information.** Every coaching exchange should close with "Here's what to do next."
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Option A: Building Something New
|
|
31
|
+
|
|
32
|
+
### Opening
|
|
33
|
+
"Nice, building from scratch is the best time to get this right. Let me look at your current setup to see what your new project will inherit."
|
|
34
|
+
|
|
35
|
+
### Flow
|
|
36
|
+
1. **Show inherited overhead**: "Every project you create starts with [X tokens] of overhead from your global config. That's [Y%] of your context window spoken for before you write a single line of project code."
|
|
37
|
+
2. **Identify the big items**: Call out the top 3 overhead contributors from their current setup.
|
|
38
|
+
3. **Ask about the project**: "What are you building? (Skill, MCP server, multi-agent system, app with Claude integration?)"
|
|
39
|
+
4. **Give architecture advice based on answer**:
|
|
40
|
+
- Skill: Point to Pattern 1 (Skill Design) and Pattern 7 (Frontmatter Discipline)
|
|
41
|
+
- MCP server: Point to Pattern 3 (MCP Consolidation) and deferred loading
|
|
42
|
+
- Multi-agent: Switch to agentic-systems.md patterns
|
|
43
|
+
- App: Focus on CLAUDE.md layering and session management
|
|
44
|
+
5. **Recommend a token budget**: "For a skill, budget ~100 tokens frontmatter + 3K body + references as needed. For a CLAUDE.md section, budget under 800 tokens total."
|
|
45
|
+
|
|
46
|
+
### Closing
|
|
47
|
+
"Want me to run the full audit with /token-optimizer? Or are there specific architecture questions I can help with?"
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Option B: Existing Project Feels Sluggish
|
|
52
|
+
|
|
53
|
+
### Opening
|
|
54
|
+
"Let's figure out where the weight is. I've got your current measurements."
|
|
55
|
+
|
|
56
|
+
### Flow
|
|
57
|
+
1. **Show the headline number**: "Your setup uses [X tokens] at startup. That's [Y%] of your context window before you type anything."
|
|
58
|
+
2. **Identify the top 3 waste sources**: Use the coaching data patterns. Name the anti-patterns.
|
|
59
|
+
3. **Ask what they notice**: "When does it feel slow? Early in sessions? After a few messages? During multi-agent work?"
|
|
60
|
+
4. **Based on their answer**:
|
|
61
|
+
- Early: Focus on startup overhead (skills, CLAUDE.md, MCP)
|
|
62
|
+
- After a few messages: Focus on compaction and context management (/compact, /clear habits)
|
|
63
|
+
- During multi-agent: Switch to agentic-systems.md patterns
|
|
64
|
+
5. **Prioritize fixes**: "The biggest win here is [X]. That alone would recover [Y tokens]. Want to tackle that first?"
|
|
65
|
+
|
|
66
|
+
### Closing
|
|
67
|
+
"I'd recommend running /token-optimizer for the full audit and automated fixes. It'll back up everything first and measure the before/after difference."
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Option C: Designing a Multi-Agent System
|
|
72
|
+
|
|
73
|
+
### Opening
|
|
74
|
+
"Multi-agent is where token optimization really matters. Every agent multiplies your config overhead. Let's design this right."
|
|
75
|
+
|
|
76
|
+
### Flow
|
|
77
|
+
1. **Ask about the architecture**: "Walk me through what you're building. How many agents? What does each one do?"
|
|
78
|
+
2. **Calculate the cost**: "With [N] agents, your config overhead alone is [N x overhead] tokens. That's before any of them read a single file."
|
|
79
|
+
3. **Review agent types**: "Which of these need write access? Which are just gathering data? The data-gathering ones should be read-only Explore agents."
|
|
80
|
+
4. **Check for the common anti-patterns**:
|
|
81
|
+
- Clone Army: All general-purpose agents
|
|
82
|
+
- Skill Dump: Too many skills assigned to agents
|
|
83
|
+
- Sequential Chain: Independent tasks not parallelized
|
|
84
|
+
- Missing Handoff: No coordination folder
|
|
85
|
+
5. **Recommend architecture changes**: Specific agent types, model routing, coordination pattern.
|
|
86
|
+
|
|
87
|
+
### Closing
|
|
88
|
+
"Shall I also look at your overall setup? Slimming CLAUDE.md saves [X x N] tokens across all [N] agents."
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Option D: Quick Health Check
|
|
93
|
+
|
|
94
|
+
### Opening
|
|
95
|
+
"Quick scan coming up."
|
|
96
|
+
|
|
97
|
+
### Flow
|
|
98
|
+
1. **Token Health Score**: Show the composite score (0-100) and what drives it.
|
|
99
|
+
2. **Top 3 actions**: The three highest-impact things they can do right now, with estimated savings.
|
|
100
|
+
3. **One habit tip**: The single behavioral change that would help most.
|
|
101
|
+
|
|
102
|
+
### Closing
|
|
103
|
+
Keep it under 2 minutes of reading. "That's the quick view. For the deep dive, run /token-optimizer."
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Handling Follow-Up Questions
|
|
108
|
+
|
|
109
|
+
### "How do I know which skills to archive?"
|
|
110
|
+
"Run `python3 measure.py trends` to see which skills you've actually invoked in the last 30 days. Anything you haven't used is a candidate. Move to ~/.claude/skills/_archived/ and you can always move it back."
|
|
111
|
+
|
|
112
|
+
### "What should my CLAUDE.md look like?"
|
|
113
|
+
"Identity (1-2 lines), critical behavioral rules, key file paths, and model routing instructions. Everything else should be in skills, reference files, or MEMORY.md. Target: under 50 lines, under 800 tokens."
|
|
114
|
+
|
|
115
|
+
### "Is this costing me money or just context?"
|
|
116
|
+
"Both, but differently. Context overhead affects output quality (degrades as the window fills). Token costs affect your bill. Skills cost tokens but only on invocation. CLAUDE.md costs tokens every single message. Multi-agent workflows multiply everything."
|
|
117
|
+
|
|
118
|
+
### "Should I use /compact or /clear?"
|
|
119
|
+
"Different tools for different situations. /compact preserves conversation context but may lose nuance. /clear gives you a completely fresh window. Rule of thumb: /compact within a topic, /clear between topics."
|
|
120
|
+
|
|
121
|
+
### "My setup is already minimal. What else can I do?"
|
|
122
|
+
"Focus on behavioral habits: batch related requests into one message, use /compact at phase boundaries (don't wait for auto-compact; on a 1M model set /autocompact lower than the ~967K default if you want it earlier), use subagents for file-heavy research, and match your model to the task complexity."
|
|
123
|
+
|
|
124
|
+
### "My session feels degraded but context isn't full."
|
|
125
|
+
"That's a quality problem, not a quantity problem. Run `python3 measure.py quality current` to see what's rotting. Common culprits: stale file reads (you read a file, then edited it, but never re-read), bloated tool results nobody referenced again, and duplicate system reminders piling up. Smart Compaction can checkpoint your important state before /compact clears the noise."
|
|
126
|
+
|
|
127
|
+
### "What's Smart Compaction?"
|
|
128
|
+
"Auto-compaction fires when context gets tight, but it's lossy. It summarizes your session with a generic checklist and drops nuance: the 'why' behind decisions, error sequences, agent state. Smart Compaction adds two things: (1) a PreCompact hook that snapshots structured state to disk before compaction, and (2) a SessionStart hook that injects what was lost back into the fresh context. Set it up with `python3 measure.py setup-smart-compact`."
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Quality-Driven Coaching
|
|
133
|
+
|
|
134
|
+
When quality data is available from `measure.py quality`, use these coaching patterns:
|
|
135
|
+
|
|
136
|
+
### Quality Score 85-100 (Excellent)
|
|
137
|
+
"Your session is clean. [Score]/100 quality. Not much to optimize here. Focus on behavioral habits and model routing."
|
|
138
|
+
|
|
139
|
+
### Quality Score 70-84 (Good)
|
|
140
|
+
"Session quality is [Score]/100. You've got some bloat building up: [top issue]. A manual `/compact` now would clear [X tokens] of low-value content. If you haven't set up Smart Compaction yet, now's a good time."
|
|
141
|
+
|
|
142
|
+
### Quality Score 50-69 (Degraded)
|
|
143
|
+
"Your session quality dropped to [Score]/100. That's the danger zone. [Top 2 issues] are eating [X tokens] combined. I'd recommend `/compact` now. If Smart Compaction is installed, your decisions and error context will survive. If not, consider `/clear` and reloading what you need."
|
|
144
|
+
|
|
145
|
+
### Quality Score <50 (Critical)
|
|
146
|
+
"Session quality is [Score]/100. Heavy rot. You've got [N stale reads], [N bloated results], and [N compactions] worth of information loss stacked up. The context window is working against you at this point. Recommended: `/clear` and start fresh. If you need continuity, install Smart Compaction first (`python3 measure.py setup-smart-compact`), then `/clear`. Your state will be checkpointed."
|