---
title: "pin"
url: "https://claudemods.dev/zh-cn/builds/pin-2e9a20"
source: "https://github.com/liquid1982/claude-plugins/tree/main/plugins/pin"
source_type: "github"
repo: "https://github.com/liquid1982/claude-plugins/tree/main/plugins/pin"
author: "liquid1982"
author_handle: "liquid1982"
stars: 0
category: "记忆与上下文"
categories: ["memory"]
tags: ["compaction", "context-management", "hooks", "pin", "plugin", "session-compact"]
permission_level: 0
scan_complete: true
install: "claude plugin marketplace add liquid1982/claude-plugins\nclaude plugin install pin"
added: "2026-10-05T20:13:08.816Z"
updated: "2026-09-21T13:19:51Z"
locale: "zh-cn"
content_locale: "zh-cn"
---

# pin

一个 Claude Mod（function-hooks 插件），把内容包在 `<pin>...</pin>` 标签中，并在每次压缩后逐字重新注入固定文本，使其能够经过 `/compact`、自动压缩、插件触发的压缩和 precompute。它通过 `session.compact` hook 注册，并可选地显示 `ui.render` 指示器。

## Description

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 组件，该组件可能在不同版本间变化。

## Install

```
claude plugin marketplace add liquid1982/claude-plugins
claude plugin install pin
```

## Original 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):

```bash
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.render` hook draws `📌 N pinned` in the band above the prompt on the terminal surface.

## Verify before trusting it

```bash
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`, the `modules` field 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.render` is written against the `AbovePrompt` component 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.
