agentleFS
belentani7belentani7/claude-skills-pack/skills/token-optimizer/SKILL.md

token-optimizer

Skill0 starsChanged 3 months agoMITView on GitHub

Expert in LLM token optimization and cost reduction. Reduces API costs 60-90% through intelligent prompt compression, context management, caching strategies, and efficient token usage patterns.

24 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use mcp-builder, webapp-testing and 1 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MicrosoftSkill

    mcp-builder

    Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

    Also in 4 projects that use this

  • JetBrainsSkill

    webapp-testing

    Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

    Also in 3 projects that use this

  • SentrySkill

    skill-creator

    Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.

    Also in 5 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 18 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Compress prompts: - Remove redundancy, use abbreviations, merge similar instructions

    line 34
  2. Distinctive:

    Use smaller models for simple tasks

    line 113

“Common” is measured: kept by at least 6 in 10 of the 18 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Token Optimizer

Expert in maximizing LLM value while minimizing token consumption and API costs.

When to Use This Skill

  • Reducing LLM API costs (OpenAI, Anthropic, Google)
  • Optimizing prompts for token efficiency
  • Implementing prompt caching strategies
  • Managing context window limits
  • Designing cost-aware AI architectures
  • Compressing context without losing quality
  • Building token usage monitoring

Core Workflow

  1. Audit current usage - Measure tokens per request, identify waste
  2. Compress prompts - Remove redundancy, use abbreviations, merge similar instructions
  3. Optimize context - Summarize history, prioritize relevant information
  4. Implement caching - Cache common prefixes, system prompts, few-shot examples
  5. Monitor costs - Track token usage per feature, set budgets

Token Reduction Techniques

Prompt Compression

# Before (verbose - 150 tokens)
You are a helpful assistant that helps users with their coding questions.
When you receive a question, you should analyze it carefully and provide
a comprehensive answer. Make sure to include code examples when relevant.

# After (compressed - 45 tokens)
Role: Coding assistant. Analyze questions, provide answers with code examples.

System Prompt Optimization

# Before (redundant)
- Do not include unnecessary information
- Be concise
- Avoid repetition
- Keep answers short
- Don't ramble

# After (deduplicated)
Constraints: Be concise. No redundancy.

Few-Shot Example Optimization

# Before (full examples - 500 tokens)
Example 1: [100 tokens]
Example 2: [100 tokens]
Example 3: [100 tokens]

# After (compressed - 150 tokens)
Examples:
- Input: X -> Output: Y
- Input: A -> Output: B
- Input: C -> Output: C

Caching Strategies

StrategySavingsImplementation
System prompt caching30-50%Keep prefix stable
Few-shot caching20-40%Use same examples
Semantic caching40-70%Cache similar queries
Response caching60-90%Cache exact matches

Cost Comparison Guide

ModelInput CostOutput CostBest For
GPT-4o-mini$0.15/M$0.60/MSimple tasks
GPT-4o$2.50/M$10/MComplex reasoning
Claude 3.5 Sonnet$3/M$15/MCode, analysis
Gemini 1.5 Flash$0.075/M$0.30/MHigh volume

Monitoring Template

const trackTokens = (model, inputTokens, outputTokens) => {
  const cost = calculateCost(model, inputTokens, outputTokens);
  console.log(`Tokens: ${inputTokens} in / ${outputTokens} out / $${cost}`);
};

Constraints

MUST DO

  • Measure token usage before and after optimization
  • Maintain response quality while reducing tokens
  • Implement streaming for long responses
  • Cache stable prefixes (system prompts, few-shot)
  • Use smaller models for simple tasks
  • Set token budgets per feature

MUST NOT DO

  • Sacrifice accuracy for token savings
  • Skip quality validation after compression
  • Hardcode token limits (make configurable)
  • Ignore model-specific tokenization differences
  • Cache sensitive/user-specific data

Knowledge Reference

Tokenization, tiktoken, prompt engineering, context windows, semantic caching, KV-cache, prompt compression, cost optimization, model routing, streaming responses

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.