# Token Optimization

> Use when the user asks to reduce token usage, optimize context, handle long-running tasks, work with large files/logs/transcripts/images, or keep AI collaboration efficient without losing evidence.

- **Type:** Skill
- **Install:** `agentstack add skill-smwswk-xiaoming-agent-skills-token-optimization`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [smwswk](https://agentstack.voostack.com/s/smwswk)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [smwswk](https://github.com/smwswk)
- **Source:** https://github.com/smwswk/xiaoming-agent-skills/tree/main/skills/token-optimization
- **Website:** https://smwswk.github.io/skill-store/

## Install

```sh
agentstack add skill-smwswk-xiaoming-agent-skills-token-optimization
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Token Optimization

Use this skill to keep long or material-heavy work cheap and controlled without hiding uncertainty.

## Core Rule

Do not make the model reread the world every turn. Let tools process bulk material, then bring only the evidence, summaries, and decisions that need model judgment into context.

## Routing Policy

When the task is about saving tokens, controlling context, or keeping long work cheap, route by the real bottleneck:

| Situation | Default route | Why |
|---|---|---|
| General large files, logs, transcripts, PDFs, images, repo exploration, or long tasks | `token-optimization` | Inspect lists and summaries first, then read only the evidence needed for judgment. |
| Need a global compression layer for Claude, Codex, Cursor, Aider, Copilot, or an OpenAI-compatible client | `headroom` | Headroom can run as proxy, MCP server, or wrapper. Do not run durable `headroom init`, `headroom wrap`, or `headroom unwrap` without explicit user confirmation. |
| Memory index is bloated, duplicate, stale, or has dead links | `memory-thin` | Clean `MEMORY.md` indexes and dead links without deleting underlying memory files. |
| Current web facts, URL extraction, or multi-query search | `anysearch` | Use direct search/extract commands and vertical/batch search instead of pulling broad raw result pools into context. |
| Batch content ingestion across B站, 小宇宙, 小红书, 公众号, 知乎, AI HOT, or reminders links | `content workflow` or `quantum-speed-reading` | Download/extract/ASR to files first, then work from `summary.md`, `full.txt`, and review queues. |
| Single content item that needs the full summary-to-insight pipeline | Platform ingestion skill, then `全自动总结迭代` | Finish extraction/ASR first; use 全自动总结迭代 only as the insight and review hook after a summary exists. |
| AI news lookup | `external AI-news provider` | Use server-side keyword and time-window filtering; do not fetch a large pool and grep locally. |
| Lark/Feishu mail verification or operation checks | `lark-mail` with `--html=false` when possible | Avoid fetching HTML bodies when only status or metadata is needed. |
| Need quota visibility in the final response | `quota-footer` | Append the short quota footer only; do not expand raw usage details unless requested or near limit. |

## Default Workflow

1. Clarify the goal and minimum evidence needed.
2. Inspect directory/file lists before opening content.
3. Prefer summaries, indexes, manifests, stats, and short error reports before full text.
4. For logs, read extracted errors, warnings, failing tests, and tail sections before complete logs.
5. For images/PDFs, use previews, contact sheets, or cropped regions before high-resolution pages.
6. For mechanical bulk work, use scripts/tools and read their concise report.
7. For long tasks, end each phase with a 1-2 KB handoff card and suggest a new thread when context becomes stale.

## Handoff Card

Use this format when a task changes phase or the thread gets long:

```markdown
## 当前目标

## 已确认决定

## 关键材料

## 已完成

## 下一步

## 风险和注意事项
```

## User-Facing Prompt Pattern

When useful, ask or restate the task in this compact structure:

```markdown
目标：
材料：
你先做：
不要做：
输出格式：
```

## Reporting

For token-sensitive tasks, briefly state:

- what was actually read;
- what was intentionally not read;
- the smallest next material needed, if any.

## Full Reference

The original installed rule document is at `references/token-optimization-rules.md`. Read it only when the user asks for the full rules or when the compact workflow above is insufficient.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [smwswk](https://github.com/smwswk)
- **Source:** [smwswk/xiaoming-agent-skills](https://github.com/smwswk/xiaoming-agent-skills)
- **License:** MIT
- **Homepage:** https://smwswk.github.io/skill-store/

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-smwswk-xiaoming-agent-skills-token-optimization
- Seller: https://agentstack.voostack.com/s/smwswk
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
