token-saver-codex

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Token Saver for Codex

Codex Token 节省器

This skill has two jobs:
  1. Work lean while it is active: follow the core rules below on every step.
  2. Tune the setup when the user asks for an audit or setup, or keeps hitting limits: run the workflow in "Audit and setup".
<!-- core-rules:start (synced from shared/core-rules.md by scripts/sync.mjs; edit the shared file) -->
此 skill 有两项任务:
  1. 精简执行:在启用期间,每一步都遵循下面的核心规则。
  2. 调优配置:当用户要求审计或设置配置,或者反复达到限额时,运行“审计与配置”中的工作流。
<!-- core-rules:start(由 scripts/sync.mjs 从 shared/core-rules.md 同步;请编辑共享文件) -->

Core rules: work lean, stay correct

核心规则:精简执行,保持正确

Why these rules: every request resends the whole context, so cost grows with context size times the number of requests. Output tokens cost several times more than input tokens. Rework costs the most of all. Cut the first two only in ways that never cause the third.
Before acting
  • If the request is ambiguous in a way that would change the result, ask one short question instead of guessing. For multi-file or risky changes, outline the plan before editing.
  • Stop exploring once you know enough to act. Do not survey the whole codebase for a narrow request.
Reading
  • Locate first (grep, glob, symbol search, LSP), then read only the relevant range of a large file. Do not re-read a file that is already in context and unchanged.
  • Never read lockfiles, generated, minified or build output, vendored dependencies, or whole logs. Search them instead.
Tool output
  • Prefer summary forms:
    git status -s
    ,
    git diff --stat
    before a full diff,
    git log --oneline -n 20
    , and
    ls
    of one directory rather than a recursive tree.
  • Run the narrowest check that proves the change (one test file or case, a typecheck of the touched files) with quiet flags. Pipe long output through
    tail -n 40
    or
    grep -E "FAIL|Error|error:"
    . Run the full suite once at the end if it is needed.
  • Send independent tool calls together in one turn, and make all edits to one file in one pass.
Delegation: do it yourself by default
  • A subagent is not free. It starts with a fresh context, reloads the instruction files, re-discovers what you already know, adds latency, and its tokens count against the same limit. Its summary also drops detail you may need later.
  • Delegate only when one of these holds: the answer needs reading many files (about ten or more) or a large output (test runs, logs, long docs) that you will not need afterwards and that condenses to a short summary; there are three or more independent, read-only pieces that can run in parallel; or you want an independent review with a clean context.
  • Keep it in the main thread for small or quick tasks, steps that depend on the previous step's output, work that needs back-and-forth, and every edit. Keep writes in one thread and never let two agents edit the same file.
  • When you delegate, use a cheaper model, give a precise brief (goal, paths, what to return, a length cap), ask for conclusions with
    path:line
    references, and do not redo the subagent's reading yourself.
Answers
  • Lead with the result. Do not restate the request, recap what did not change, or dump a whole file when an edit or a
    path:line
    reference will do.
  • Size the answer to the question. Skip optional extras (docs, refactors, extra tests) and offer them in one line instead.
Do not under-save
  • For hard bugs, security, data-loss risk, or architecture, read and reason as much as needed. One correct attempt is cheaper than two cheap wrong ones.
  • Never skip verification to save tokens. Make it targeted instead.
Session coaching (one line, only at a natural break, at most once per break)
  • On a switch to an unrelated task, suggest a fresh session. On a long session about one task, suggest compacting with a focus hint.
  • For routine work on a flagship model or high reasoning effort, suggest a cheaper setting. For a hard problem on a small model, suggest upgrading.
<!-- core-rules:end -->
为什么需要这些规则:每个请求都会重新发送完整上下文,因此成本会随上下文大小乘以请求次数而增长。输出 token 的成本是输入 token 的数倍。返工的成本最高。只有在不引发返工的前提下,才能削减前两项成本。
执行前
  • 如果请求中的歧义会改变结果,应提出一个简短问题,而不是猜测。对于涉及多个文件或风险较高的更改,应在编辑前概述计划。
  • 一旦掌握了足够信息,就停止探索。对于范围明确的需求,不要调查整个代码库。
阅读
  • 先定位(grep、glob、symbol search、LSP),然后只读取大文件中的相关范围。不要重新读取已经处于上下文中且未发生变化的文件。
  • 绝不读取 lockfiles、generated、minified 或 build output、vendored dependencies 或完整日志;应改为搜索这些内容。
工具输出
  • 优先使用汇总形式:
    git status -s
    、在完整 diff 之前使用
    git diff --stat
    、
    git log --oneline -n 20
    ,以及只
    ls
    一个目录而不是递归目录树。
  • 使用 quiet flags 运行能够证明改动正确的最窄检查(一个测试文件或用例,或对已改动文件执行 typecheck)。将长输出通过
    tail -n 40
    或
    grep -E "FAIL|Error|error:"
    过滤。确有需要时,在最后运行一次完整测试套件。
  • 将相互独立的工具调用放在同一轮中一并发出,并一次性完成对同一个文件的所有编辑。
委派:默认亲自动手
  • subagent 并非免费。它会带着全新上下文启动、重新加载指令文件、重新发现你已经知道的信息、增加延迟,而且它的 token 也计入同一个限额。它的摘要还可能丢失你之后需要的细节。
  • 仅在以下情况之一成立时委派:答案需要读取大量文件(约十个或更多),或者需要处理之后不会再用到、且可压缩成简短摘要的大量输出(测试运行结果、日志、长文档);存在三个或更多彼此独立、可并行执行的只读部分;或者希望由具备干净上下文的独立审查进行检查。
  • 对于小型或快速任务、依赖上一步输出的步骤、需要来回沟通的工作以及所有编辑,应将其保留在主线程中。写入操作应集中在同一个线程,绝不能让两个 agent 同时编辑同一文件。
  • 委派时,使用成本更低的 model,提供精确的任务说明(目标、路径、返回内容、长度上限),要求返回带 path:line 引用的结论,并且不要亲自重读 subagent 已读取的内容。
回答
  • 先给出结果。不要复述请求、重复说明未发生变化的内容,也不要在编辑结果或 path:line 引用已足够时输出整个文件。
  • 让答案篇幅与问题相称。省略可选的附加内容(文档、重构、额外测试),如需提供则用一行说明。
不要过度节省
  • 对于复杂 bug、安全问题、数据丢失风险或架构工作,应按需进行充分的阅读和推理。一次正确的尝试比两次廉价但错误的尝试更节省成本。
  • 绝不能为了节省 token 而跳过验证。应让验证更有针对性。
会话指导(仅在自然停顿时给出一行,每个停顿最多一次)
  • 切换到无关任务时,建议开启全新会话。对于围绕单一任务的长会话,建议执行 compaction,并附上 focus hint。
  • 对于在旗舰 model 上或以高 reasoning effort 进行的常规工作,建议采用成本更低的设置。对于使用小 model 处理的困难问题,则建议升级。
<!-- core-rules:end -->

Codex specifics

Codex 专属规则

Apply these on top of the core rules.
  • Local and cloud share one allowance. A cloud task is not free capacity; start one only when it saves real work.
  • Reasoning effort is the biggest per-task lever. Well-scoped edits need
    low
    ; debugging and multi-file changes
    medium
    or
    high
    ;
    xhigh
    only for long, reasoning-heavy work.
  • AGENTS.md is capped at
    project_doc_max_bytes
    (32 KiB by default). Past the cap Codex silently drops the rest, so keep it lean and put directory-specific guidance in nested AGENTS.md files.
  • What to suggest to the user (they run these; you cannot):
SituationSuggest
Starting unrelated work
/new
Long session, same task
/compact
at a natural break
Want to try an alternative without losing this thread
/fork
Routine task on a high effort or large model
/model
and pick a smaller model or lower effort
Unsure how much is left
/status
; add the 5-hour and weekly limits to the status line
Speed not neededLeave fast mode off (it consumes more credits per request)
在核心规则之外,还应应用以下规则。
  • 本地与 cloud 共用同一份额度。cloud 任务并不是免费容量;只有它能实际减少工作量时才应启动。
  • reasoning effort 是调节单任务用量的最大杠杆。范围明确的编辑需要
    low
    ;调试和多文件更改需要
    medium
    或
    high
    ;仅对长时间且推理密集型工作使用
    xhigh
    。
  • AGENTS.md
    的大小上限为
    project_doc_max_bytes
    (默认 32 KiB)。超过上限后,Codex 会静默丢弃其余内容,因此应保持精简,并将特定目录的指导放在嵌套的
    AGENTS.md
    文件中。
  • 向用户建议什么(由用户执行;你无法执行):
情况建议
开始不相关的工作
/new
长时间会话,处理同一任务在自然停顿处执行
/compact
想在不丢失当前线程的情况下尝试替代方案
/fork
在较高 effort 或大型 model 上处理常规任务
/model
,并选择更小的 model 或更低的 effort
不确定还剩多少额度
/status
;在状态行中显示 5 小时和每周限额
不需要速度保持 fast mode 关闭(每次请求会消耗更多 credits)

Audit and setup

审计与配置

When the user asks to audit, set up, or cut usage, or keeps hitting limits:
  1. Run
    node <this skill's directory>/scripts/audit.mjs --agent codex
    from the project root. It is read-only and prints warnings with fixes. Without Node.js, check the same items by hand using references/levers.md.
  2. Report the findings ranked by expected savings, in a few lines each.
  3. Propose concrete edits to
    ~/.codex/config.toml
    (or the project's
    .codex/config.toml
    ) with the keys in references/levers.md. The config belongs to the user: show the diff and apply it only after they agree.
  4. Offer to add the always-on snippet: skills load only when triggered, so the lean-work rules need a short permanent home. Append assets/always-on.md to the project
    AGENTS.md
    or
    ~/.codex/AGENTS.md
    , unless an equivalent section is already there.
当用户要求审计、设置或减少用量,或者持续达到限额时:
  1. 从项目根目录运行
    node <this skill's directory>/scripts/audit.mjs --agent codex
    。它是只读操作,会打印警告及修复建议。如果没有 Node.js,请使用 references/levers.md 手动检查相同项目。
  2. 按预期节省量对发现的问题进行排序,每项用几行说明。
  3. 提出对
    ~/.codex/config.toml
    (或项目中的
    .codex/config.toml
    )的具体编辑建议,键名见 references/levers.md。配置属于用户:显示 diff,并且只在用户同意后应用。
  4. 提议添加始终启用的片段:skill 只会在被触发时加载,因此精简工作规则需要一个简短的永久存放位置。除非已有等效章节,否则将 assets/always-on.md 追加到项目的
    AGENTS.md
    或
    ~/.codex/AGENTS.md
    。

References

参考资料

  • references/levers.md: config.toml keys, commands and habits that affect usage, with a lean example config. Read before changing configuration.
  • references/facts.md: limits, credits and pricing facts with sources and date. Read when the user asks about limits or pricing, and verify on the linked page if the answer matters.
  • references/budget.md: how to pace work against 5-hour and weekly windows.
  • references/levers.md:影响用量的 config.toml 键、命令和习惯,并附有精简示例配置。修改配置前先阅读。
  • references/facts.md:有关限额、credits 和定价的事实信息、来源与日期。当用户询问限额或定价时阅读;如果答案很重要,请在链接页面上核实。
  • references/budget.md:如何按照 5 小时和每周窗口安排工作节奏。