ClaudeMods
☰
ZH-CN
● 0 人在线 · 浏览 0 次
赞助提交作品
GitHub 仓库 · 发布者 MichaelP17

cache-watch

显示提示缓存保持热状态的时长,并在压缩大型上下文最划算的时机建议执行压缩。

MichaelP17@MichaelP17

MichaelP17/claude-mods/tree/main/cache-watch

已翻译

关于这个 mod

一个 Claude Code 模组,会在状态栏跟踪提示缓存的热度;超过可配置的上下文大小后,它会提供 Compact、Write handoff 和 Dismiss,以便在昂贵的缓存重建之前缩小上下文。它会从服务器响应中学习真实的缓存生命周期,在过期前发出警告,并可以从仓库根目录的 HANDOFF.md 为新会话植入内容。

安装

请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。

claude plugin marketplace add MichaelP17/claude-mods
claude plugin install cache-watch
原文 / README

cache-watch

Shows how long the prompt cache stays warm and suggests compacting a large context at the moments where it pays off.

Every model request re-sends the whole conversation. The prompt cache makes that cheap, but it expires a fixed time after the last request — one hour in Claude Code, five minutes under usage overage. A request on an expired cache re-reads the entire context at the cache write price, which on a large context is the most expensive single request of a session. This mod keeps that moment visible and offers to shrink the context before it happens.

Status line

| Line | Meaning | | --- | --- | | cache 42m · ctx 250k | Warm for another 42 minutes; the last request carried 250k tokens | | cache cold · ctx 250k | Expired; the next request rebuilds the cache over the whole context | | cache rebuilds · ctx 90k | A compaction just ran; the next request writes the cache for the smaller context |

The line only appears when there is something to decide: from statusFromTokens of context on, or while the cache is about to expire. A small context on a cold cache shows nothing.

The timer starts over with every model request of the main conversation, including the steps Claude takes on its own between tool calls. Subagents have a cache of their own and do not count.

Suggestions

From largeContextTokens of context on, a band above the prompt offers Compact, Write handoff and Dismiss:

| When | Why then | | --- | --- | | The cache expires in warnMinutes and you are idle | Compacting on a warm cache reads the context at the cache read price | | A turn committed or ran tests green | A unit of work ended; nothing in flight gets lost |

A running turn is never interrupted.

Write handoff sends a prompt that asks Claude to write HANDOFF.md at the repository root: goal, state, decisions with their reasons, rejected approaches, open points and the exact next step.

When a conversation starts in a repository that has a HANDOFF.md, a toast names it and Claude is told where it lies, so asking it to continue is enough for the next session. Only the path is added to the context, not the file's content.

When you send a prompt on a cold cache with a large context, a dialog asks whether to compact first. The rebuild is paid either way; compacting first pays it on the smaller remainder.

Lifetime learned from the server

The server reports with every response how much of the prompt came from the cache. When a request finds nothing cached although the timer still ran, the mod switches to a five-minute lifetime; when a request is served from the cache after more than five minutes, it switches back. Prompts under 20k tokens teach nothing, since they may be too short to be cached at all.

Configuration

| Option | Default | Meaning | | --- | --- | --- | | ttlMinutes | 60 | Cache lifetime Claude Code uses | | warnMinutes | 10 | How early before expiry to suggest compacting | | statusFromTokens | 300000 | Context size from which the status line shows | | largeContextTokens | 300000 | Context size from which the mod suggests compacting |

Change them in /config, or in ~/.claude/settings.json under pluginConfigs["cache-watch"].options.

Works with compact-shaper

Compact runs a normal compaction. With compact-shaper loaded, its summary follows the structure of a handoff.

Uninstall

Remove the mod from CLAUDE_CODE_PLUGIN_DIRS. Its options in pluginConfigs can be deleted.

其他同名作品

更多类似作品