token-optimization
Optimize token consumption in Claude Code through cache management, context forking, model selection, and input filtering.
Skill by valorisa
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/valorisa-token-optimization
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: agent-building
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
- Runs as
- Python package
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/token-optimization
What's inside
- Skill name
token-optimization- Description
- Optimize token consumption in Claude Code through cache management, context forking, model selection, and input filtering. Use when user mentions high token costs, context window bloat, slow sessions, cache invalidation, verbose agent output, heavy MCP load, or any context management issues. Covers four critical axes - cache misses, context bloating, wrong model/effort level, and verbose input formats. Triggers on "tokens", "cost", "expensive", "context", "cache", "slow session", "optimize", or symptoms of token waste even without explicit mention.
- License
- MIT
- Metadata
- author: valorisa · version: 1.0.0 · category: workflow-automation
- Instructions
- 392 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Files (8)
- README.md
- SKILL.md
- cache-deep-dive.md · references/
- claude-md-templates.md · references/
- tools.md · references/
- validate_skill.py · scripts/
- functional-tests.md · tests/
- trigger-tests.md · tests/
SKILL.md (first lines)
# Token Optimization — Claude Code
## Overview
Token overconsumption in Claude Code stems from **four main sources**:
1. **Cache miss** — uncached or invalidated requests
2. **Context bloating** — unnecessarily growing context window
3. **Wrong model / wrong effort** — reasoning overuse
4. **Verbose input format** — overly verbose data injected into context
---
## Phase 1: Initial Session Audit
Before any work, run these two commands:
```bash
/context # Shows loaded MCPs and tokens already consumed
/plugin # Lists active plugins
```
**Systematic actions:**
- Disable all MCPs not needed for current project
- Disable all unused plugins
- One project ≠ one global config → customize per project
> Real example: empty session with Canva + Gmail + Google Calendar MCPs loaded = **23,000 tokens consumed before first keystroke**.
**Red flags to check:**
- More than 3 MCPs loaded
- Plugins unrelated to current work
- Base token count >10,000 on empty session
---
## Phase 2: Cache Management
### Principle
Claude Code caches: system instructions (CLAUDE.md), tool/MCP list, and message history. Any **modification during session** invalidates this cache, causing complete re-billing of affected tokens.
### Imperative rules
- **Never add a tool, MCP, or model mid-session.**
Configure everything *before* starting, or in a dedicated setup session.
- If a critical addition is required mid-session (heavy skill, MCP, critical command):
1. Compact the session (`/compact`)
2. Start new session with compacted summary as starting point
- Treat cache like **HTTP cache**: changing a header invalidates everything downstream.
### Cache invalidation hierarchy
```
┌─────────────────────────────────────────────┐
│ BASE SYSTEM INSTRUCTIONS (CLAUDE.md + tools)│ ← Invalidated if tool added
├─────────────────────────────────────────────┤
│ SESSION STATE (project files, memory) │ ← Invalidated if file changes
├─────────────────────────────────────────────┤
│ MESSAGE HISTORY │ ← Invalidated if message edited
│ msg 1 → msg 2 → msg 3 → ... │ (invalidates everything after)
└─────────────────────────────────────────────┘
```
**What invalidates cache:**
| Action | Layer invalidated | Impact |
|---|---|---|
| Add MCP mid-session | Base instructions | Very high |
| Add tool (tool calling) | Base instructions | Very high |
| Modify CLAUDE.md | Base instructions | Very high |
| Edit message in middle of history | Message history (from that point) | Moderate |
| Load new file into context | Session state | Moderate |
**Optimal session strategy:**
```
1. Full configuration (MCP, tools, CLAUDE.md) → BEFORE starting
2. Work session → NEVER modify configuration
3. If modification needed → /compact → new session
4. Agents → context fork → isolated work → result only
```
For technical details on cache issues, see `references/cache-deep-dive.md`.
---
## Phase 3: Context Window Optimization
### Reduce default context window
The 1M token window is tempting but dangerous: it encourages bad habits and overloads child agents.
**Conditional recommendation:**
- Small/medium codebase → limit to ~200,000 tokens in `settings.json`:
```json
{ "contextWindow": 200000 }
```
*(not committed by default — use local file)*
- Very large codebase → keep 1M, but optimize practices below even more aggressively.
> **RAM analogy**: having 32GB RAM doesn't justify poor memory management. A constrained window forces better discipline.
### Context forking and isolated agents
Agents inherit parent context at spawn time. **The longer you wait, the heavier they start.**
Target behavior:
- Call each skill or agent in a **forked context** (`context: fork` in parameters)
- Agent works in its own window → at completion, returns *only the result*, not full history
- When agent is destroyed, main context hasn't moved
**Systematic use cases to isolate in subagent:**From valorisa/Claude-Skills, MIT.
More from valorisa/Claude-Skills
- 0.602score
task-observer
valorisa
Monitors task execution for skill improvement opportunities.
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
verification-rigoureuse
valorisa
Produire des réponses factuelles, transparentes et vérifiables en distinguant clairement les faits, les sources, les incertitudes, les hypothèses et les…
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
task-observer
valorisa
Consigne frictions et apprentissages en cours de tâche.
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
dual-llm-contradiction-dialog
valorisa
Orchestration d'un dialogue structuré entre deux LLMs (A et B) autour d'un même sujet, avec cadrage d'intention, génération d'angles morts, recherche…
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
anti-hallucination-anti-acquiescence
valorisa
Enforce rigorous factual accuracy, epistemic discipline, source integrity, uncertainty handling, and resistance to uncritical agreement.
SkillBFreshness: B★ 17Claude Code +9 - 0.594score
collaborative-technical-peer-review
valorisa
Orchestration d'une revue technique collaborative multi-étapes destinée à transformer une analyse initiale en un artefact technique robuste (documentation…
SkillBFreshness: B★ 17Claude Code +9 - 0.576score
find-skills
valorisa
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express…
SkillBFreshness: B★ 17Claude Code +9 - 0.556score
fabuleux
valorisa
Discipline de travail haut de gamme à tenir toute la session.
SkillCFreshness: C★ 17Claude Code +9 - 0.551score
business-revenue-strategy
valorisa
Conceives the shortest path to personalized net revenue by analyzing profile, audience, offer, funnel, unit economics, and conversion bottlenecks.
SkillCFreshness: C★ 17Claude Code +9 - 0.551score
promptor
valorisa
Generate optimized, domain-agnostic prompts via a 5-circle validation pipeline fused with 18 optimization hacks.
SkillCFreshness: C★ 17Claude Code +9 - 0.551score
multi-llm-debate-grill-me
valorisa
Organise un débat structuré entre plusieurs LLM sur un plan, un design ou une idée de projet, avec un cadrage silencieux de type "grill me", des rounds de…
SkillCFreshness: C★ 17Claude Code +9 - 0.551score
rescue-tokens
valorisa
Use when user hits rate limits, quota exceeded errors, context exceeds 40%, or exhibits token waste symptoms (long conversations, wrong model, verbose output…
SkillCFreshness: C★ 17Claude Code +9
Signals
- Stars
- 17
- Forks
- 4
- Open issues
- 0
- Last commit (this folder)
- Jun 20, 2026 (4 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.0.0
- License
- MIT
- Repository
- github.com/valorisa/Claude-Skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from valorisa
- 0.602score
task-observer
valorisa
Monitors task execution for skill improvement opportunities.
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
task-observer
valorisa
Consigne frictions et apprentissages en cours de tâche.
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
anti-hallucination-anti-acquiescence
valorisa
Enforce rigorous factual accuracy, epistemic discipline, source integrity, uncertainty handling, and resistance to uncritical agreement.
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
dual-llm-contradiction-dialog
valorisa
Orchestration d'un dialogue structuré entre deux LLMs (A et B) autour d'un même sujet, avec cadrage d'intention, génération d'angles morts, recherche…
SkillBFreshness: B★ 17Claude Code +9 - 0.598score
verification-rigoureuse
valorisa
Produire des réponses factuelles, transparentes et vérifiables en distinguant clairement les faits, les sources, les incertitudes, les hypothèses et les…
SkillBFreshness: B★ 17Claude Code +9 - 0.594score
collaborative-technical-peer-review
valorisa
Orchestration d'une revue technique collaborative multi-étapes destinée à transformer une analyse initiale en un artefact technique robuste (documentation…
SkillBFreshness: B★ 17Claude Code +9
Cite this page
token-optimization skill. Agent Mart. https://agentmart.dev/skills/valorisa-token-optimization (last updated 2026-10-24)