liquid1982/claude-plugins/tree/main/plugins/pin
pin
一個 Claude Mod(function-hooks 外掛),將內容包在 `<pin>...</pin>` 標籤中,並在每次壓縮後逐字重新注入釘選文字,讓它能撐過 `/compact`、自動壓縮、外掛觸發的壓縮與 precompute。它透過 `session.compact` hook 註冊,也可選擇顯示 `ui.render` 指示器。
關於這個 mod
pin 是一個提供抗壓縮上下文的 Claude Code function-hooks 外掛。包在 <pin>...</pin> 區塊中的提示內容,會在 session.compact 下行時被擷取(並附帶指示,告訴摘要器要保留釘選內容),接著在壓縮後以一則標籤完整保留的承載使用者訊息重新附加;下一次壓縮就能再次擷取它們,讓 pin 可以無限期持續而不會累積。使用 CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude --plugin-dir ./pin-mod 載入。可選的 ui.render hook 會在提示列上方顯示 📌 N pinned。已知限制:hook 的時間預算可能跳過外掛;沒有環境變數開關時,modules 欄位會被靜默忽略;不會掃描工具輸出中的 pin;ui.render 條帶針對 early-access AbovePrompt 元件,而該元件可能在版本之間變動。
安裝
請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。
claude plugin marketplace add liquid1982/claude-plugins claude plugin install pin
原文 / README
pin — compaction-proof context for Claude Code
A Claude Mod (function-hooks plugin). Wrap anything in <pin>...</pin> in your prompts and it will survive /compact, auto-compaction, plugin-triggered compaction, and precompute.
Usage
<pin>
The prod database is read-only until Friday. Never suggest migrations.
API base: https://api.internal.example/v2
</pin>
Now help me refactor the ingestion job.
Run with the mod loaded (Mods are early access and gated behind function hooks):
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude --plugin-dir ./pin-mod
How it works
- Hooks
session.compact. On the way down it extracts every unique<pin>block from the transcript and appends an instruction telling the summarizer to preserve pinned content. - On the way up (after the engine compacts), it appends a single "carrier" user message containing all pins, tags intact. Because the tags survive, the next compaction re-extracts them — pins persist indefinitely. Old carriers are dropped before a new one is appended, so nothing accumulates.
- An optional
ui.renderhook draws📌 N pinnedin the band above the prompt on the terminal surface.
Verify before trusting it
claude plugin validate ./pin-mod
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude plugin test ./pin-mod
Then in a throwaway session: pin something, generate filler conversation, run /compact, and confirm the pinned text is still in context (ask the model to repeat it, or inspect with /context).
Regenerate type declarations after any Claude Code update with /plugin-types — the API is early access and may change between releases without notice.
Known limits
- Hooks have a time budget; a hook that overruns is skipped and core compaction runs alone (your pins would be lost for that pass). This mod does no I/O beyond one transcript read, so it stays well under budget.
- Without
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1, themodulesfield in hooks.json is silently ignored — no error, no pinning. - Pins are extracted from message text (user and assistant). Pins inside tool output are not scanned; move important tool findings into a pinned prompt line if you need them kept.
- The strip in
ui.renderis written against theAbovePromptcomponent of Claude Code 2.1.277's published types; if your build's contract differs, delete that block — the compaction hook is independent of it.
