跳到正文
Skillpedia
通用编程48k · #6002

tokenleak

它能做什么

这个技能可以教 AI 在编写代码时更加高效,避免发送重复或不必要的信息。这样既能节省时间,也能减少计算资源的消耗。

适用场景

  • ✓在大型复杂项目中编写代码时。
  • ✓成本或 AI 使用额度是你的顾虑时。
  • ✓AI 在对话中发送了太多重复数据时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tokenleak/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tokenleak/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“如何让 AI 在编写代码时占用更少的资源?”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会学会只获取所需的具体信息,而不是通读全部内容;会先计算出结果,而不是发送原始数据;并在每个步骤限制发送的内容量。它还会避免重复执行任务,或重复发送已经知道的信息。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

tokenleak

Overview

Every tool result an agent pulls into context is re-sent on every later call until compaction, so a 6k-token log read early in a 60-call session is paid about 55 more times. These rules make the agent let in only what the next decision needs: locate before reading, compute instead of reading data, bound command output, never re-read, batch independent calls. Over 80 A/B runs in Claude Code (Sonnet 5) they cut cost by 32% with the same 40/40 pass rate; on Haiku 4.5 they only help together with the plugin's read guard (-20%). Method and raw results are in the source repo.

When to Use This Skill

  • Use on coding tasks that read files, run tests, builds or installs, use git, or search a codebase.
  • Use when the user wants to save tokens, reduce cost, or stay under usage limits.
  • Use when a session keeps hitting compaction because tool output fills the context.

Rules

  1. Locate, then read. Don't know a file's size? Check it (wc -l) along with your first search. Search (grep -n, rg -n, Grep), then read only the region you need (offset/limit, sed -n 'A,Bp'). Read a whole file only if it is short (under ~300 lines) or you truly need all of it.
  2. Compute, don't read. For questions about data (counts, totals, filters, lookups in big data files, CSV, JSON, logs), run a short script or one-liner that prints only the answer. Never pull the data itself into context.
  3. Bound every command. Never let tests, builds, installs or logs stream into context unbounded.
    • Quiet or failures-only modes: pytest -q -x, vitest run --reporter=dot, go test ./... 2>&1 | grep -v '^ok', cargo test -q, npm ci --silent, make -s.
    • Long jobs: L="${TMPDIR:-/tmp}/out.log"; cmd > "$L" 2>&1; echo "exit=$?"; tail -n 40 "$L". Need more? grep -n -m 20 -E 'error|FAIL|panic' "$L" on the saved log. Never re-run a job just to see more of its output.
    • Iterate on the one failing test, not the whole suite. Run the full suite once at the end, quietly.
  4. Never re-read what you have. A file you read or wrote is still in context. Re-read only after compaction or after something else changed it.
  5. Batch independent calls. Reads and searches that don't depend on each other go in one turn (parallel tool calls), and shell steps that need no judgment in between go in one command (wc -l a b; grep -n x a | head). Each extra round-trip re-sends everything.
  6. Diffs over files. git status -s, git diff --stat then git diff -- <path>, git log --oneline -n 15, git show --stat <sha>.
  7. Edit, don't rewrite. Targeted edits only. Never rewrite a whole file to change a few lines, and never paste back into chat code that is already on disk.
  8. Narrow searches and fetches. Scope by path and file type, cap results (-m, head_limit, | head -n 30, -l for names only). Pick fields from APIs and JSON (--json a,b, jq '.items[] | {id,name}', per_page). Ask a web fetch a precise question instead of dumping the page.
  9. Delegate wide exploration. If an answer means opening 10+ files and you only need the conclusion, hand it to a subagent if your agent has them. Only its summary enters your context.
  10. Answer lean. Lead with the result. No step-by-step recap, no restating the diff, no closing summary of what the user can already see, no filler.

Never save tokens by

  • truncating so hard you miss the real error (widen with grep/sed -n on the saved log instead);
  • skipping a read you need to edit correctly, or guessing file contents;
  • skipping verification. Run the tests, quietly.

Limitations

  • The savings depend on the workload and the model: in the benchmark a short test-fixing task gained 5%, noisy builds and multi-file features 24-51%; small models such as Haiku 4.5 barely follow the rules without the plugin's read guard.
  • The benchmark covers two models and four small tasks on a synthetic repo, and runs vary 2 to 4x.
  • The rules cost about 850 tokens of context themselves; on very short sessions they may not pay for themselves.
  • The companion transcript audit (tokenleak.py) lives in the source repo and is not included here.

Examples

Locate before reading, and hand the agent only what the next decision needs:

wc -l app/service.py          # size, alongside the search
rg -n "def handle_" app/      # find the region first
sed -n '120,180p' app/service.py

Bound a noisy build and keep the failure visible:


…
常见问题

为什么 AI 会发送重复的信息?

默认情况下,AI 可能会在每次收到新指令时重新发送之前对话中的信息,从而消耗大量资源。这个技能会教它变得更有选择性。

这会影响 AI 编写代码的准确性吗?

不会。目标是在降低资源消耗的同时保持准确性。AI 学会的是高效工作,而不是牺牲质量。

这个技能会自动生效吗?

不会。它是一套 AI 应当遵循的规则。使用这个技能,就是在指示 AI 应用这些高效规则。

详情

作者的原始描述

Token-lean rules for coding agents: cut the context re-sent on every later call (big reads, noisy logs, re-reads, serial calls) without losing correctness.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#6002
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能