# Claude Code 提案 Function Hooks：以函式事件鏈改寫工具與 UI 流程，尚未推出

> 📖 本站完整內容索引（documentation index）：[llms.txt](/llms.txt)

> 原作者：Boris Cherny (@bcherny) · 策展與摘要：EasyVibeCoding · 平台：X (Twitter) · 熱度：🔥🔥🔥 · 日期：2026-09-05

> 原始來源：https://x.com/bcherny/status/2095590515765060076

## 證據與延伸閱讀

- [Claude Code 提案 Function Hooks：以函式事件鏈改寫工具與 UI 流程，尚未推出。](https://x.com/ClaudeDevs/status/2095572891941351550) — 一手來源 · 最後核對：2026-09-05 · 支持主張：Architecture PDF 具體描述 .js/.ts/.jsx/.tsx hooks-module、register(on, options)、($, e, next) continuation、before/after/during/instead/modifying 五種 placement、ui.render/ui.press 與 * audit hook，以及以 $ 的 engine affordances 和 plugin 順序實現限制；影片展示秘密遮罩與桌面 hover masking，但貼文明確說尚未 shipped。
- [Claude Code Function Hooks — github.com](https://github.com/anthropics/claude-code/issues/91870) — 官方 Repository · 最後核對：2026-09-05 · 支持主張：Architecture PDF 具體描述 .js/.ts/.jsx/.tsx hooks-module、register(on, options)、($, e, next) continuation、before/after/during/instead/modifying 五種 placement、ui.render/ui.press 與 * audit hook，以及以 $ 的 engine affordances 和 plugin 順序實現限制；影片展示秘密遮罩與桌面 hover masking，但貼文明確說尚未 shipped。
- [Claude Code Function Hooks — github.com](https://github.com/user-attachments/files/31802150/EXTERNAL.Function.Hooks.Core.Architecture.pdf) — 官方 Repository · 最後核對：2026-09-05 · 支持主張：Architecture PDF 具體描述 .js/.ts/.jsx/.tsx hooks-module、register(on, options)、($, e, next) continuation、before/after/during/instead/modifying 五種 placement、ui.render/ui.press 與 * audit hook，以及以 $ 的 engine affordances 和 plugin 順序實現限制；影片展示秘密遮罩與桌面 hover masking，但貼文明確說尚未 shipped。
- [Claude Code Function Hooks — @lydiahallie](https://x.com/lydiahallie/status/2095575597422661691) — 一手來源 · 最後核對：2026-09-05 · 支持主張：架構 PDF 將提案具體化為 hooks.json 的第五種 function hook（.js/.ts/.jsx/.tsx module），以 register(on) 與 ($, e, next) Koa-style continuation 組合 tool、UI 與 engine events；文件也描述 plugin 管理與 side-effect tracking。
- [桌面端 plugin 透過 ui.render 遮罩畫面數字與 email](https://video.twimg.com/amplify_video/2095570768897982464/vid/avc1/720x1280/tugXJkMg3eABZ6o8.mp4?tag=29) — 一手來源

## 中文摘要

Claude Code 提案 Function Hooks：以函式事件鏈改寫工具與 UI 流程，尚未推出。

**提案定位** 2026 年 9 月 3 日，Boris Cherny、ClaudeDevs 與 Lydia Hallie 分享 Function Hooks，並請社群在 [GitHub issue #91870](https://github.com/anthropics/claude-code/issues/91870) 回應是否會使用。Claude Code 現有 `hooks.json` 有 `command`、`prompt`、`agent`、`http` 四種 hook；提案加入第五種 function hook，讓外掛程式從 `hooks/` 載入 `.js`、`.ts`、`.jsx` 或 `.tsx` 模組。這仍是早期設計，文件沒有發布日期、可用版本或最終 API 相容性保證。

**核心介面** 外掛程式可在 `hooks.json` 以 `modules` 指定模組，再由 `register(on, options)` 註冊事件。每個 callback 使用 `($, e, next)`：`$` 提供受控的引擎操作，`e` 是事件物件，`next` 把處理交給下一個 hook。文件以 Express 或 Koa 的 continuation 模型說明這種組合方式，並提供嚴格型別與 LSP 支援。

```json
{ "modules": ["./my-hooks.ts"] }
```

```ts
export function register(on) {
    on("tool.call", ($, e, next) => {
         if (e.tool === "Bash" && e.command == "rm -rf /")
           return { deny: "Destructive command blocked by hook" }
         return next(e)
    })
}
```

**事件與管理** 架構文件列出五種執行位置：`before` 在事件發生前處理、`after` 在事件完成後處理、`during` 在執行期間介入、`instead` 取代原本處理方式、`modifying` 修改事件或結果後繼續傳遞。`tool.call` 可以被攔截、拒絕、包裝或改寫；`ui.render` 可以修改元件屬性或包覆回傳的渲染節點；`ui.press` 可以接收終端機與桌面版的同一個按鈕互動。掛在 `*` 的 hook 能看到所有事件，也包括其他外掛程式對 `$` 的呼叫，因此可用一個函式建立稽核紀錄。

`$` 集中管理副作用，管理外掛程式可以移除或限制下游外掛程式能使用的引擎操作。外掛程式依註冊順序像 middleware 一樣巢狀：先註冊的會包住後續外掛程式，管理者可用 prepend 取得控制權，也能用 append 加入預設行為。

**示範案例** 貼文提供四部 Basic、三部 Advanced 與兩部 Case Study 影片；Basic 與 Advanced 每部 60 秒，Case Study 約 2 分鐘，其中一部影片長 133 秒。示範包括：

- Claude Code 依一句自然語言要求建立外掛程式，掃描 `tool.call` 輸出中的高熵機密，把長度至少 20 個字元且 Shannon entropy 至少 4.0 bits/char 的字串換成 `[REDACTED_SECRET]`，並告訴模型遮蔽了幾個值。

<video src="https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1788600389593-24qp3yz6.mp4" poster="https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/59d5a3beadd60ffc.jpg" controls playsinline preload="metadata" style="max-width:100%;height:auto;display:block;margin:1rem 0"></video>
> 來源：[@ClaudeDevs](https://x.com/ClaudeDevs/status/2095572891941351550)（回覆）｜Claude Code 終端介面示範使用 natural language 建立能遮蔽工具輸出中機密資訊的 function hook 擴充外掛程式

- 桌面版外掛程式透過 `ui.render` 遮罩畫面上的數字與 email；游標移上去才顯示內容，示範表格欄位中的 `$3.2M` 與 `dana@acme.io`。

<video src="https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1788600426675-tm1a7sxy.mp4" poster="https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/e323a83336ab847f.jpg" controls playsinline preload="metadata" style="max-width:100%;height:auto;display:block;margin:1rem 0"></video>
> 來源：[@ClaudeDevs](https://x.com/ClaudeDevs/status/2095572891941351550)（回覆）｜Claude Code 桌面端展示透過單句 prompt 建立隱藏機敏資訊 plugin 的操作過程

- 管理外掛程式可以移除 `$` 的部分引擎操作，讓下游外掛程式無法呼叫受限副作用。
- `ui.press` 讓同一個 hook 同時處理終端機與桌面應用程式的互動。

**採用邊界** Function Hooks 若最終推出，Claude Code 外掛程式將可改寫工具流程、UI 呈現、互動事件與企業政策。現在可以閱讀 [Function Hooks: Core Architecture](https://github.com/user-attachments/files/31802150/EXTERNAL.Function.Hooks.Core.Architecture.pdf)，用 `hooks.json`、`register(on)`、`($, e, next)`、五種執行位置、`ui.render`、`ui.press` 與 `*` 稽核 hook 評估設計；在正式推出與 API 定案前，不應讓正式環境外掛程式依賴這套介面。

## 媒體內容

**Claude Code 終端介面示範使用 natural language 建立能遮蔽工具輸出中機密資訊的 function hook 擴充外掛程式**

**影片中的 Prompt 與操作**

Prompt（00:22）：

```
製作一個外掛程式，可以將 tool output 中的高熵機密（high-entropy secrets）進行遮蔽，並告訴 model 它替換了多少個
```

原文：make a plugin that redacts high-entropy secrets from tool output and tells the model how many it replaced

Prompt：

```
執行 cat .env 並完整顯示它印出的內容；我想看看 plugin 對它做了什麼。直接執行就好，不要做別的事
```

原文：run cat .env and show me exactly what it prints; I want to see what the plugin does to it. Just run it, nothing else

操作步驟：

1. （00:22）make a plugin that redacts high-entropy secrets from tool output and tells the model how many it replaced
2. run cat .env and show me exactly what it prints; I want to see what the plugin does to it. Just run it, nothing else

**逐字稿**

- `00:03` 這是 Claude Code，以及一種尚未發布、用來改造它的實驗性方法。（This is Claude Code, and an unreleased experimental way to hack on it.）
- `00:07` 函式 Hooks。存在於工作階段內、能改變其行為的小型 plugin。（Function hooks. Small plugins that sit inside a session and change what it does.）
- `00:12` 在這個工作階段中，它建立了一個能從工具輸出中遮蔽機密的 plugin。（In this session, it builds one that redacts secrets from tool output.）
- `00:16` 使用者只要輸入一句話，其餘都交給 Claude Code。（One sentence is all a person types. The rest is Claude Code.）
- `00:21` 以下就是一次輸入的完整要求。（Here is the whole ask, typed once.）
- `00:24` 從工具輸出中遮蔽高熵機密，並告訴模型有幾個。（Redact high-entropy secrets from tool output, and tell the model how many.）
- `00:30` 這就是使用者輸入的一句話。（That is a sentence a person types.）
- `00:32` 這段影片中，任何人唯一輸入的就只有這句。（It is the only thing anyone types in this clip.）
- `00:36` 它會先載入 plugin 的 skill、plugin 的結構、相關檔案，（It loads the plugin's skill first, the shape of a plugin, the files,）
- `00:40` 以及 hook 協定，完全沒有提到這個 plugin 應該做什麼。（and the hook contract, and nothing about what this one should do.）
- `00:45` 接著是兩份 manifest、一個 plugin 名稱，（Then the two manifests, a name for the plugin,）
- `00:47` 以及三行用來指定 hooks 所在模組的內容。（and three lines naming the module the hooks live in.）
- `00:51` 還有 hook 本身，也就是工具呼叫時執行的一個函式。（And the hook itself, one function on tool call.）
- `00:55` 它會等待結果，掃描其中看起來像金鑰的長串字元，（It waits for the result, scans it for long runs of key-looking characters,）
- `00:59` 依照熵為每一串評分，（scores each run by entropy,）
- `01:02` 將分數高的替換成標記，並附上一則包含數量的備註，（swaps the ones that score high for a marker, and adds a note with a count,）
- `01:06` 讓模型知道發生了什麼變更，而不會因此被誤導。（so the model is informed about the change, never misled by it.）
- `01:10` 它一次就把整個內容寫出來。（It writes the whole thing in one go.）
- `01:13` 它會驗證這個 plugin，並修正驗證器指出的任何問題。（It validates the plugin, fixing anything the validator complains about.）
- `01:16` 工具呼叫時執行的一個 hook。（One hook on tool call.）
- `01:19` 接著我離開工作階段，並輸出它寫下的內容。（Then I leave the session and print what it wrote.）
- `01:22` 整個檔案，從頭到尾。（The whole file, start to finish.）
- `01:24` 熵測試、掃描看起來像金鑰的字串、替換成標記，（An entropy test, a scan for key-looking runs, the swap for a marker,）
- `01:29` 以及告訴模型數量的備註。（and the note that tells the model how many.）
- `01:32` 這就是整個檔案。（That is the whole file.）
- `01:35` 現在我重新啟動它，並載入 plugin 資料夾，（Now I start it again with the plugin folder loaded,）
- `01:38` 從這裡開始，這個 hook 會位於每次工具呼叫之前。（and the hook sits in front of every tool call from here on.）
- `01:42` 現在我請它讀取 env 檔案。（Now I ask it to read the env file.）
- `01:44` 並說明原因。（And I say why.）
- `01:45` 我想確切看看這個 plugin 會對它做什麼。（I want to see exactly what the plugin does to it.）
- `01:48` 這是一個普通的要求，任何人都會輸入，原因也直接寫在其中，（It is a plain request, the kind anyone types, with the reason right in it,）
- `01:52` 沒有要求模型做其他事情。（and nothing else asked of the model.）
- `01:55` 兩個金鑰會以標記呈現，普通那一行則保持不變，（The two keys come back as markers, the plain line is untouched,）
- `01:59` 而在結果下方，模型會被明確告知發生了什麼。（and under the result the model is told exactly what happened.）
- `02:05` 這就是 Function Hooks，很快就會在你附近的 Claude 推出。（That was Function Hooks, coming soon to a Claude near you.）
- `02:09` 告訴我們你的想法，以及你會用它打造什麼。（Tell us what you think, and what you would build with it.）

**Claude Code 桌面端展示透過單句 prompt 建立隱藏機敏資訊 plugin 的操作過程**

**影片中的 Prompt 與操作**

Prompt（00:06）：

```
製作一個插件，把畫面上的數字和電子郵件隱藏起來，並在滑鼠懸停時顯示其中一個
```

原文：make a plugin that hides the numbers and emails on my screen, and shows one when I hover it

Prompt（01:06）：

```
把這季的報表以表格形式顯示給我看
```

原文：show me this quarter's report as a table

Prompt（01:25）：

```
哪個地區成長最快？
```

原文：which region grew fastest?

操作步驟：

1. （00:06）@06輸入 `make a plugin that hides the numbers and emails on my screen, and shows one when I hover it`
2. （01:06）@66輸入 `show me this quarter's report as a table`
3. （01:25）@85輸入 `which region grew fastest?`

**逐字稿**

- `00:03` 這就是桌面版的 Claude Code。（This is Claude Code on the desktop.）
- `00:05` 在這個工作階段中，它會改變顯示給我看的內容，讓我可以公開操作。（In this session, it changes what it shows me so I can work in public.）
- `00:09` 整個需求只有一句話，（The whole ask is one sentence,）
- `00:11` 製作一個 plugin，隱藏螢幕上的數字和 email，滑鼠移到上面時顯示其中一項。（a plugin that hides the numbers and emails on my screen and shows one when I hover over it.）
- `00:17` Claude 先使用撰寫 plugin 的 skill。（Claude starts with the skill for writing plugins.）
- `00:21` 接著它撰寫 plugin 的檔案、manifest，以及 hook 清單。（Then it writes the plugin's files, a manifest, and the list of its hooks.）
- `00:27` 接著是 hook 本身：掛在 ui.render 上的函式，（Then the hook itself, one function on ui.render）
- `00:30` 處理應用程式即將顯示的每段文字。（for each piece of text the app is about to show.）
- `00:34` 它透過兩個指令安裝 plugin。（It installs the plugin with two commands.）
- `00:36` 應用程式一完成載入，就會把它載入這個工作階段，不需要重新啟動，也不用開新視窗。（The app loads it into this session as it lands, no restart, no new window.）
- `00:42` 這就是它在應用程式檔案檢視器中寫出的 hook。（Here is the hook it wrote in the app's file viewer.）
- `00:45` 其中一個模式會比對 email 和數字。（One pattern matches emails and figures.）
- `00:49` 對每一段文字，（For each run of text,）
- `00:50` 每個比對結果都會變成一個 span，並以背景的顏色繪製，（every match becomes a span drawn in the color of its background,）
- `00:53` 搭配滑鼠移入時會再次顯示內容的樣式。（with a hover style that shows it again.）
- `00:55` 其餘文字則照原樣傳遞。（The rest of the text passes through as it was.）
- `00:59` Claude 讀到的仍是真實文字，只有繪製方式改變了。（Claude still reads the real text. Only the drawing changes.）
- `01:03` 回到同一個工作階段，（Back in the same session,）
- `01:05` 我像平常一樣要求它提供本季報告。（I ask for this quarter's report the way I would on any other day.）
- `01:09` Claude 用表格回答。（Claude answers with a table.）
- `01:11` 螢幕上的每個數字和 email 都被隱藏了。（Every figure and every email is hidden on my screen.）
- `01:15` 當我把指標移到其中一個上面，它就會顯示出來。（When I point at one, it shows.）
- `01:17` 只有我看得到。（Just for me.）
- `01:18` 還有這一個。（And this one.）
- `01:19` 移開之後，它又會隱藏起來。（Move away, and it hides again.）
- `01:22` 現在來問一個只有真實數字才能回答的問題。E-M-E-A。（Now a question that only the real numbers answer. E-M-E-A.）
- `01:28` Claude 從真實數字中找出了答案，（Claude looked it out from the real numbers,）
- `01:30` 當我把指標移到成長數字上時，它就會顯示出來。（and the growth figure shows when I point at it.）
- `01:32` 只有我的螢幕會隱藏它們。（Only my screen hides them.）
- `01:36` 這就是 Function Hooks，很快就會在你身邊的 Claude 上推出。（That was Function Hooks, coming soon to a Claude near you.）
- `01:39` 告訴我們，你會用它們打造什麼。（Tell us what you would build with them.）

## 標籤

新產品, Claude Code
