Write context-usage snapshots without starting a node process per write

未關閉
#21,086 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
重構
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
node.js, shell, typescript

研究方向

Read .claude/rules/mod-authoring.md, load the built-in plugin-authoring skill, then check the current mods reference for available $.fs calls. Trace writes in plugins/context-usage/hooks/register.tsx and the atomic write, lock, and prune behavior in lib/write-snapshot.mjs; review plugins/context-usage/reference/reader-contract.md and its contract tests. Done means changed writes avoid a process or document the missing filesystem call and chosen floor change, preserve reader-visible content and atomicity, and include before and after start-rate measurements in the PR.

由索引模型根據 Issue 內容生成。

描述

Problem

The context-usage mod writes each session's snapshot by starting a separate process:
plugins/context-usage/hooks/register.tsx:642-644 runs node lib/write-snapshot.mjs <target> --prune
through $.process.run whenever the snapshot body changes, and again after FLOOR_MS (60 s, :12)
when it has not. The mod already runs inside Claude Code's process, so each write adds a node start
(and its Defender scan on Windows) for a small JSON file.

Evidence

  • Read on origin/main this pass: the spawn at register.tsx:642-644, the floor at :12, and the
    helper's job in lib/write-snapshot.mjs (atomic temp-file write and rename, lock with retries,
    hourly prune at :26, :110).
  • Measured by another session (5-minute Windows process trace, 16 concurrent sessions, 2026-12-04, not
    re-measured here): write-snapshot.mjs started about 11 times a minute across the sessions. On that
    trace Defender CPU tracked process start rate at about 54 ms per start (correlational).
  • $.fs.write exists in the mod API (used in plugins/session-flow/hooks/register.tsx:45). Not
    checked: whether the mod API offers an atomic rename, directory listing and removal, which the
    helper's atomic write and prune need.

Proposed approach

  1. Check the current mods reference for the $.fs calls available.
  2. If they cover an atomic write, write the snapshot in the mod and keep the helper only for the
    hourly prune (or move the prune in too).
  3. If not, raise the floor or write only on a zone change, whichever keeps the documented reader
    contract (plugins/context-usage/reference/reader-contract.md).

The helper is shared with rate-limits (scripts/sync-shared-copies.sh); keep the readers' contract
unchanged.

Acceptance criteria

  • A snapshot write that changes the body starts no process, or the issue records which $.fs
    call is missing and the floor change taken instead.
  • Readers see the same file content and atomicity as today (contract tests pass).
  • Measured starts per minute for one active session, before and after, in the PR.

Constraints and gotchas

  • Follow .claude/rules/mod-authoring.md (load the built-in plugin-authoring skill first).
  • A mod hook that throws is skipped (fails open); keep write errors logged once, as today.

Context

Part of the process-start ranking on #20549.

主要語言
Shell
星號
22
分支
2
平均合併
3 小時 20 分鐘
30 天內合併 PR
956

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

melodic-software/claude-code-plugins 的其他 Issue

查看 melodic-software/claude-code-plugins 的全部 Issue

相似的 Issue

更多 Shell/Bash Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。