Optimizing Tokens
Quick Start
- Analyze - Identify input vs output token distribution
- Minimize Context - Read only relevant file sections, not entire files
- Optimize Prompts - Use direct commands, remove filler words
- Structure Outputs - Request concise formats (JSON over prose)
- Batch Operations - Combine related requests, avoid duplicate context
- Select Model - Match model tier to task complexity
Features
| Feature |
Description |
Guide |
| Context Targeting |
Read only needed code sections |
Line ranges, pattern search, summaries |
| Prompt Efficiency |
Direct commands vs verbose requests |
79% reduction possible |
| Output Formatting |
Structured concise responses |
JSON/YAML over verbose explanations |
| Model Selection |
Right model for task complexity |
Haiku: simple, Sonnet: standard, Opus: complex |
| Batching |
Combine related operations |
Single request with multiple outputs |
| Caching |
Avoid redundant computation |
Cache by content hash + timestamp |
Common Patterns
# Prompt Optimization (79% reduction)
INEFFICIENT (120 tokens):
"I would really appreciate it if you could help me
with this task. What I need you to do is to please
analyze this code and look for any bugs..."
EFFICIENT (25 tokens):
"Analyze for bugs, error handling issues, security.
For each: location, problem, fix."
# Context Optimization
INEFFICIENT: Read entire 1000-line file
EFFICIENT: Read lines 45-60 around target function
# Output Format
INEFFICIENT: "Please explain in detail..."
EFFICIENT: "Output: JSON {name, severity, fix}"
# Batching
INEFFICIENT:
Request 1: "Given code [100 lines], find bugs"
Request 2: "Given code [same 100 lines], add types"
EFFICIENT:
Single request: "Given code [100 lines]:
1. Find bugs
2. Add types"
# Model Selection Guide
| Task Type | Model | Examples |
|-----------|-------|----------|
| Simple | Haiku | Formatting, syntax check, lookups |
| Standard | Sonnet | Features, bugs, reviews, tests |
| Complex | Opus | Architecture, security, critical code |
# Search Efficiency
INEFFICIENT: grep ".*" / (matches everything)
EFFICIENT: grep "handleAuth" src/ --type ts
Best Practices
| Do |
Avoid |
| Read only what's needed - use line ranges |
Reading entire files for one function |
| Use direct language - commands over requests |
Verbose, polite phrasing in prompts |
| Structure outputs - JSON/YAML over prose |
Requesting detailed explanations for simple tasks |
| Batch operations - combine related requests |
Repeating context across multiple requests |
| Choose right model - Haiku for simple tasks |
Using most powerful model for everything |
| Limit search results - use head_limit |
Unbounded searches returning thousands of results |
| Cache results - avoid redundant computation |
Re-analyzing unchanged files |
| Progressive loading - start minimal, expand |
Loading full context when partial suffices |
Related Skills
dispatching-parallel-agents - Efficient multi-agent patterns
writing-plans - Structured planning reduces iteration
thinking-sequentially - Organized reasoning saves tokens
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: optimizing-tokens3description: AI agent maximizes efficiency and minimizes costs through strategic token usage while maintaining output quality. Use when managing AI interactions, designing prompts, or reducing costs. Use when this capability is needed.4---56# Optimizing Tokens78## Quick Start9101. **Analyze** - Identify input vs output token distribution112. **Minimize Context** - Read only relevant file sections, not entire files123. **Optimize Prompts** - Use direct commands, remove filler words134. **Structure Outputs** - Request concise formats (JSON over prose)145. **Batch Operations** - Combine related requests, avoid duplicate context156. **Select Model** - Match model tier to task complexity1617## Features1819| Feature | Description | Guide |20|---------|-------------|-------|21| Context Targeting | Read only needed code sections | Line ranges, pattern search, summaries |22| Prompt Efficiency | Direct commands vs verbose requests | 79% reduction possible |23| Output Formatting | Structured concise responses | JSON/YAML over verbose explanations |24| Model Selection | Right model for task complexity | Haiku: simple, Sonnet: standard, Opus: complex |25| Batching | Combine related operations | Single request with multiple outputs |26| Caching | Avoid redundant computation | Cache by content hash + timestamp |2728## Common Patterns2930```31# Prompt Optimization (79% reduction)32INEFFICIENT (120 tokens):33"I would really appreciate it if you could help me34with this task. What I need you to do is to please35analyze this code and look for any bugs..."3637EFFICIENT (25 tokens):38"Analyze for bugs, error handling issues, security.39For each: location, problem, fix."4041# Context Optimization42INEFFICIENT: Read entire 1000-line file43EFFICIENT: Read lines 45-60 around target function4445# Output Format46INEFFICIENT: "Please explain in detail..."47EFFICIENT: "Output: JSON {name, severity, fix}"4849# Batching50INEFFICIENT:51 Request 1: "Given code [100 lines], find bugs"52 Request 2: "Given code [same 100 lines], add types"5354EFFICIENT:55 Single request: "Given code [100 lines]:56 1. Find bugs57 2. Add types"58```5960```61# Model Selection Guide62| Task Type | Model | Examples |63|-----------|-------|----------|64| Simple | Haiku | Formatting, syntax check, lookups |65| Standard | Sonnet | Features, bugs, reviews, tests |66| Complex | Opus | Architecture, security, critical code |6768# Search Efficiency69INEFFICIENT: grep ".*" / (matches everything)70EFFICIENT: grep "handleAuth" src/ --type ts71```7273## Best Practices7475| Do | Avoid |76|----|-------|77| Read only what's needed - use line ranges | Reading entire files for one function |78| Use direct language - commands over requests | Verbose, polite phrasing in prompts |79| Structure outputs - JSON/YAML over prose | Requesting detailed explanations for simple tasks |80| Batch operations - combine related requests | Repeating context across multiple requests |81| Choose right model - Haiku for simple tasks | Using most powerful model for everything |82| Limit search results - use head_limit | Unbounded searches returning thousands of results |83| Cache results - avoid redundant computation | Re-analyzing unchanged files |84| Progressive loading - start minimal, expand | Loading full context when partial suffices |8586## Related Skills8788- `dispatching-parallel-agents` - Efficient multi-agent patterns89- `writing-plans` - Structured planning reduces iteration90- `thinking-sequentially` - Organized reasoning saves tokens9192---93> Converted and distributed by [TomeVault](https://tomevault.io/claim/doanchienthangdev) — claim your Tome and manage your conversions.94<!-- tomevault:4.0:skill_md:2026-04-13 -->