Skip to content
Original
Reddit · ClaudeCode / Codex / VibeCoding· /u/NaivePresentation449·· 1 day agoAI score66

我如何用 Hook 构建监控 Claude Code 会话的插件,以及踩过的 Windows 坑

Original title: What I learned building a Claude Code plugin to monitor all your sessions.

The title and summary in the selected language are awaiting translation.

AI overview

作者开发了 PeakOS,一个展示所有 Claude Code 会话、花费和休息提醒的桌面应用,核心逻辑放在 Hook 里,插件只发布一个 Rust 可执行文件,无参数时从 stdin 读取一条 Hook 事件 JSON,带 record 时由 Skill 写入数据,带 statusline 时输出状态栏。

Full text
What I learned building a Claude Code plugin to monitor all your sessions.

I built PeakOS, a desktop app that shows all my Claude Code sessions, what they cost and when I need a break. Most of the work was in the hook, so here's how it's built and what went wrong, in case you're writing your own.

The plugin ships one Rust executable. With no arguments, it reads one hook event as JSON on stdin. With `record`, skills pipe data to it. With `statusline`, it prints Claude Code's status line. One binary meant one build and one place to fix bugs.

Hooks can do more than log:

  1. SessionStart hands the session my goals and what was learned from my past ratings.
  2. UserPromptSubmit adds stored memory that's relevant to the prompt.
  3. PreToolUse blocks clearly destructive commands.
  4. Stop keeps Claude going while a task's spec has unverified claims.

Windows problems I hit:

  1. - PowerShell piping JSON to the hook added a byte-order mark, so `serde_json` rejected the input. Strip the BOM before parsing.
  2. - Git checked out .sql migrations with CRLF line endings, which changed their checksums, and the app panicked with "migration was modified". Pin line ending in `.gitattributes`
  3. - Tauri release builds with the GNU toolchain crashed without WebView2Loader.dll. Build releases with MSVC.

How Claude Code helped: it wrote most of the hook and the app. I made the product calls and kept a numbered decision log that every session read first. That log did more for consistency than any prompt trick. 319 Rust tests so far.

The app is free, Windows only for now: https://github.com/maybeanns/peakos-releases. Happy to go deeper on any of the hook design.

submitted by /u/NaivePresentation449 to r/ClaudeCode
[link] [留言]

Source: Reddit · ClaudeCode / Codex / VibeCoding · reddit.com