Skip to content
Agentmart
Submit a tool

token-optimization

Optimize token consumption in Claude Code through cache management, context forking, model selection, and input filtering.

Skill by valorisa

IndexedMIT★ 17
Write a review

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.

We use your email only for this newsletter. Privacy

About

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.

Use cases: agent-building

No 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

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
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from valorisa

Cite this page

token-optimization skill. Agent Mart. https://agentmart.dev/skills/valorisa-token-optimization (last updated 2026-10-24)