context-canary
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Canary
上下文金丝雀
A context canary is a trivially checkable standing instruction whose only job is to fail visibly. The classic form: "start every response with my name." The agent costs almost nothing to comply — so when the name disappears, that absence is data. The instruction didn't get harder; the agent's hold on its early-context instructions got weaker. Like the coal-mine canary, it dies first, before the failures you actually care about (forgotten constraints, ignored conventions, re-litigated decisions) start landing in your code.
This works because context degradation is silent and gradual. Models don't announce that they've stopped attending to instructions from 80k tokens ago, and compaction summaries quietly drop standing instructions. The canary converts an invisible failure into a binary, per-turn, zero-effort check. The research behind why this happens — context rot, lost-in-the-middle, instruction drift, compaction loss — is in references/research.md.
上下文金丝雀是一种易于验证的固定指令,其唯一作用就是在失效时清晰显现。经典形式为:“每条回复都以我的名字开头。”Agent遵守该指令几乎没有成本——因此当名字消失时,这种缺失就是一种信号。指令本身并没有变难,只是Agent对早期上下文指令的掌控变弱了。就像煤矿里的金丝雀,它会先“死亡”,在那些你真正关心的故障(遗忘的约束、忽略的规则、重新讨论已决定的事项)影响到你的代码之前发出预警。
之所以有效,是因为上下文退化是隐蔽且渐进的。模型不会宣布自己不再关注80k token之前的指令,而压缩摘要会悄悄丢弃固定指令。金丝雀将无形的故障转化为一种逐轮的、零成本的二元检查。关于这种现象背后的研究——上下文腐烂、中间遗忘、指令漂移、压缩丢失——可查看**references/research.md**。
When to use this skill
何时使用此技能
- Installing a canary at the start of a long or high-stakes session.
- The user notices the canary stopped appearing and asks what happened.
- The agent itself realizes it can no longer find its canary contract in context.
- The user asks how trustworthy the current context still is.
- 在长时间或高风险会话开始时安装金丝雀。
- 用户注意到金丝雀不再出现并询问原因时。
- Agent自身发现无法在上下文中找到金丝雀协议时。
- 用户询问当前上下文的可信度时。
The canary contract
金丝雀协议
When invoked, install the canary by stating the contract explicitly in one short message, then follow it. Default format — first line of every response from then on:
**Julius · t14 · ctx ok**Three fields, each probing something different:
| Field | Example | What its failure means |
|---|---|---|
| Name | | The standing instruction itself fell out of effective context — adherence drift or compaction dropped it. |
| Turn counter | | Increment by 1 every response. A reset, skip, or repeat means continuity broke — almost always compaction or a summarization boundary. |
| Self-check | | The agent's honest estimate. |
Use the user's actual name (ask if unknown). If the user wants the minimal version, name-only is fine — it's the original trick and still catches the big failures. Never explain, apologize for, or decorate the canary line; it must stay byte-stable so a human can pattern-match it in half a second.
Session canary vs. standing canary. A canary that lives only in the conversation tests whether conversation context survives (compaction, truncation, drift). A canary written into or agent memory survives compaction by design — which means it tests whether file-based instructions are being attended to, a different and weaker signal. Default to the session canary; that's the one that detects degradation. Offer the standing variant only if the user wants the habit across all sessions, and tell them what it no longer measures.
CLAUDE.md调用时,通过一条简短消息明确声明协议来安装金丝雀,随后遵循该协议。默认格式——此后每条回复的第一行:
**Julius · t14 · ctx ok**三个字段,每个字段探测不同的内容:
| 字段 | 示例 | 失效意味着什么 |
|---|---|---|
| 姓名 | | 固定指令本身已脱离有效上下文——要么是遵守性漂移,要么是压缩过程中被丢弃。 |
| 轮次计数器 | | 每条回复递增1。重置、跳过或重复意味着连续性中断——几乎总是由压缩或摘要边界导致。 |
| 自我检查 | | Agent的真实评估。 |
使用用户的真实姓名(未知时可询问)。如果用户想要最简版本,仅保留姓名即可——这是最初的技巧,仍能捕捉重大故障。切勿解释、道歉或修饰金丝雀行;它必须保持字节稳定,以便人类能在半秒内识别模式。
会话金丝雀 vs. 固定金丝雀。仅存在于对话中的金丝雀测试的是对话上下文是否能存续(压缩、截断、漂移)。写入或Agent内存的金丝雀设计上可抵御压缩——这意味着它测试的是基于文件的指令是否被关注,这是一种不同且较弱的信号。默认使用会话金丝雀;它能检测退化情况。仅当用户希望在所有会话中保持此习惯时,才提供固定变体,并告知用户它不再能测量哪些内容。
CLAUDE.mdEmission rules
输出规则
- Canary is the first line of every response, including short ones, error reports, and responses after tool calls.
- Increment the counter every response. If unsure of the count, that uncertainty IS a signal — emit and flag it, never guess a plausible number.
t? - The self-check must be honest. Reporting by reflex defeats the entire instrument.
ctx ok - If at any point the canary contract cannot be found in context (you only know about it from a summary, or not at all), declare a trip yourself — don't wait for the user to notice.
- 金丝雀是每条回复的第一行,包括简短回复、错误报告和工具调用后的回复。
- 每条回复递增计数器。如果不确定计数,这种不确定性本身就是一种信号——输出并标记,切勿猜测合理数字。
t? - 自我检查必须真实。习惯性报告会完全破坏这个工具的作用。
ctx ok - 如果在任何时候无法在上下文中找到金丝雀协议(仅从摘要中得知,或完全不知道),自行宣布触发——不要等用户发现。
Trip protocol
触发协议
A trip is: the canary missing, malformed, a counter discontinuity, or an agent-side self-declaration.
Calibrate before alarming — one missed canary on an otherwise coherent response is a warning (note it, resume the canary, keep going). Two consecutive misses, a counter discontinuity, or the agent failing its own contract check is a confirmed trip. Then:
- Stop trusting drifted state. Do not barrel ahead on the current task using context you can no longer vouch for.
- Checkpoint. Write the durable state somewhere outside the conversation: current goal, decisions made and why, files touched, what's verified vs. in-progress, next step. A or notes file in the repo works.
HANDOFF.md - Re-anchor. Re-read the project instructions (, the original task statement) and the checkpoint. State back to the user, in three or four lines, what you believe the task and constraints are — so they can correct any drift cheaply.
CLAUDE.md - Reset deliberately. Recommend the user start a fresh session (or run an explicit compact) seeded with the checkpoint file, rather than limping on. Degraded context doesn't heal; it compounds.
- Re-install the canary with the counter reset to , noting the generation:
t1.t1 (gen 2)
Never silently resume the canary after a gap as if nothing happened — that destroys the instrument's credibility, which is all it has.
触发情况包括:金丝雀缺失、格式错误、计数器不连续,或Agent自行声明触发。
触发前先校准——在其他回复连贯的情况下,一次缺失金丝雀只是警告(记录下来,恢复金丝雀,继续会话)。连续两次缺失、计数器不连续,或Agent未遵守自身协议检查,则确认触发。此时:
- 停止信任漂移状态。不要使用你无法担保的上下文继续当前任务。
- 创建检查点。将会话之外的持久状态写入某处:当前目标、已做出的决策及原因、涉及的文件、已验证内容与进行中内容、下一步计划。仓库中的或笔记文件均可。
HANDOFF.md - 重新锚定。重新阅读项目指令(、原始任务说明)和检查点。用三到四行向用户说明你认为的任务和约束是什么——以便用户能低成本纠正任何漂移。
CLAUDE.md - 主动重置。建议用户启动一个新会话(或执行显式压缩),并以检查点文件为种子,而非继续勉强维持。退化的上下文无法自行修复,只会恶化。
- 重新安装金丝雀,计数器重置为,并标注版本:
t1。t1 (gen 2)
切勿在中断后悄悄恢复金丝雀,仿佛什么都没发生——这会破坏该工具的可信度,而可信度是它唯一的价值。
What the canary does and doesn't tell you
金丝雀能告诉你什么,不能告诉你什么
The test is one-sided. A missing canary is strong evidence of degradation. A present canary is weak evidence of health — a cheap stylistic habit can survive while harder constraints (architecture decisions, "never touch X") quietly rot, and a canary stuffed into memory files can outlive the context it was meant to monitor. Treat the canary as a smoke detector, not a structural inspection: when it fires, act; when it's quiet, stay reasonably suspicious in sessions past roughly 50% of the context window or after any compaction event.
Pair it with the cheap structural habits that reduce what the canary has to catch: keep durable decisions in files instead of chat, compact at deliberate boundaries instead of waiting for forced compaction, and prefer fresh sessions per task over one immortal session. Details and sources in references/research.md.
该测试是单向的。缺失金丝雀是退化的有力证据。存在金丝雀则是健康的弱证据——一个低成本的风格习惯可能存续,而更严格的约束(架构决策、“永远不要触碰X”)却在悄悄腐烂,而塞进内存文件的金丝雀可能比它要监控的上下文更长寿。将金丝雀视为烟雾报警器,而非结构检查:当它触发时,采取行动;当它安静时,在会话超过上下文窗口约50%或任何压缩事件后,仍保持合理的怀疑态度。
搭配那些能减少金丝雀需要捕捉的问题的低成本结构习惯:将持久化决策存入文件而非聊天记录,在主动设定的边界进行压缩而非等待强制压缩,每个任务优先使用新会话而非一个永久会话。详情和来源见**references/research.md**。