ClaudeMods
☰
KO
● 0 명 접속 중 · 조회 0 회
후원프로젝트 제출
GitHub 저장소 · 작성자 mediavee

cold-cache-guard

프롬프트 캐시가 만료된 대규모 대화를 다시 보내기 전에 어떻게 할지 묻는 Claude Code mod입니다.

번역 완료

이 mod 소개

cold-cache-guard는 Claude Code 플러그인으로, 프롬프트 캐시가 만료된 대규모 대화를 다시 보내기 전에 사용자에게 묻습니다. 대화가 프롬프트 캐시 수명(구독은 기본 1시간, API 키는 기본 5분)을 넘겨 유휴 상태가 되면 다음 메시지에서 전체 컨텍스트를 캐시 기록으로 다시 처리합니다. 긴 세션에서는 이 짧은 메시지 하나의 비용이 다른 하루치 작업보다 커질 수 있습니다. 콜드 스타트 복구(claude --resume, --continue, /resume)와 유휴 후 첫 프롬프트 입력에 개입해 바로 보내기, 먼저 압축하기, 다시 시작하기(/clear), 취소 중에서 선택하게 하고 유휴 시간, token 수, 가격 추정치를 표시합니다. 사람이 입력하지 않은 메시지(다른 세션, 예약 작업, -p 실행)는 가로채지 않습니다. 대화 상자는 Claude Code의 language 설정을 지원하며 현재 영어와 프랑스어를 지원합니다. plugin marketplace를 통해 추가하고 설치하며 early access function hooks를 활성화해야 합니다. ttlMinutes(기본 60)와 minTokens(기본 30000)을 설정할 수 있습니다.

설치

먼저 작성자의 README에서 marketplace와 플러그인 이름을 확인하세요. 저장소 구조에 따라 명령어가 달라질 수 있습니다.

claude plugin marketplace add mediavee/cold-cache-guard
claude plugin install cold-cache-guard
원문 / README

cold-cache-guard

A Claude Code mod that asks what to do before a large conversation whose prompt cache has expired is sent again.

When a conversation sits idle past the prompt cache lifetime (one hour on a subscription, five minutes on an API key by default), the next message re-processes the whole context as a cache write. On a long session that one short message can cost more than the rest of the day. cold-cache-guard stops at that moment and lets you choose:

 ☐ Cache
│ Cold prompt cache: last answer 17h38 ago, ~109k tokens to cache again (~$0.54). What now?
❯ 1. Send as is
  2. Compact first
  3. Start over (/clear)
  4. Cancel

It asks in two places:

  • On a cold resume (claude --resume, --continue, /resume), before you type anything: keep the session as is, compact now, or start over. The idle time, the token count and the price estimate are Claude Code's own.
  • On the first prompt typed after an idle spell in a session that stayed open, the case a resume never sees: send as is, compact first, start over, or cancel. Compact, start over and cancel put your prompt back in the box.

Messages that are not typed by a person (another session's message, a scheduled task, a -p run) go through untouched. The dialog follows Claude Code's language setting (English and French so far).

Install

cold-cache-guard is a mod: a plugin built on Claude Code's function hooks, which are in early access. It needs function hooks enabled; it was built and tested on Claude Code 2.1.283.

claude plugin marketplace add mediavee/cold-cache-guard
claude plugin install cold-cache-guard@cold-cache-guard

Then enable function hooks, either for one launch:

CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude

or for good, in ~/.claude/settings.json:

{ "env": { "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS": "1" } }

Sessions started before that change do not load it.

Configure

/plugin configure cold-cache-guard@cold-cache-guard, or the config menu:

| Option | Default | Meaning | | --- | --- | --- | | ttlMinutes | 60 | How long an idle conversation stays cached, for the prompt check. Set 5 on an API key, a cloud provider or usage credits unless you raised promptCacheTtl. Resumes use Claude Code's own estimate instead. | | minTokens | 30000 | Below this context size, nothing is asked. |

How it works

  • A classic.SessionStart hook reads what Claude Code reports on a resume (seconds_since_last_response, context_tokens, prompt_cache_likely_expired, estimated_cache_write_usd) and asks while the session loads.
  • A turn.complete hook records when the last answer arrived, in the session's $.state, so a reload of the mod keeps it.
  • A prompt.submit hook compares that time with ttlMinutes and the live context size with minTokens, then asks through $.ui.ask. A prompt hook cannot compact or run /clear while it holds the prompt, so those run right after the prompt is dropped, and the prompt comes back to the box rather than being resubmitted.
  • A choice holds until the next answer, so a cancelled prompt asks again and an accepted one does not.

Limits

  • Function hooks are early access: the API can change with any Claude Code release. If a hook fails, Claude Code skips it and the prompt goes through as if the mod were not there.
  • The prompt check uses your ttlMinutes, not the live cache state, which mods cannot read yet. A wrong setting means asking too early or too late.
  • Anything typed into the terminal counts as a person's prompt, including text a terminal multiplexer or an orchestrator sends by keystrokes.
  • On Pro and Max plans, Claude Code's own "Resume from summary" dialog can also appear for a resumed session over 100k tokens. Answer "Don't ask me again" there if you prefer this one.
  • Changing the model or the effort level also rebuilds the cache; Claude Code already asks before those while the cache is warm, so this mod does not.

Related

cache-tax takes another approach to the same cost: it keeps the cache warm with periodic pings while you are away, and refuses a cold send once with its price.

Develop

claude plugin validate .claude-plugin/plugin.json
claude plugin test .

To type-check, run /plugin-types in a Claude Code session opened in this folder (it writes .claude/types), then npx -p typescript tsc -p ..

License

MIT

비슷한 프로젝트