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

Đang mở
#21,086 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, shell, typescript
Lĩnh vực
devtools, performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Shell
Star
22
Fork
2
Merge trung bình
3 giờ 20 phút
Pull request đã merge (30 ngày)
956

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của melodic-software/claude-code-plugins

Tất cả issue của melodic-software/claude-code-plugins

Issue tương tự

Thêm issue về Shell/Bash

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.