ClaudeMods
☰
ZH-TW
● 0 人在線上 · 瀏覽 0 次
贊助提交作品
GitHub 儲存庫 · 發布者 mutlumehmet

shared-file-guard

拒絕本工作階段未讀取,或自上次讀取後被其他工作階段變更的共享檔案(STATUS.md、CLAUDE.md、MEMORY.md 或您指定的檔案)的 shell 寫入

mutlumehmet@mutlumehmet

mutlumehmet/claude-plugins/tree/main/plugins/shared-file-guard

原貼文圖片1
已翻譯

關於這個 mod

shared-file-guard

一個 Claude Code 模組,用於在同一個專案上執行多個工作階段。如果本工作階段從未讀取過共享檔案(STATUS.md、CLAUDE.md、MEMORY.md 或您指定的檔案),或者自上次讀取後被其他工作階段變更,它將拒絕寫入該檔案的 shell 命令。它是 claude-plugins 的一部分。

功能

  • 編輯和寫入工具已經會拒絕自讀取後已變更的檔案。這彌補了 shell 的不足:heredocs、python3 腳本、sed -i、tee、mv 和 cp。
  • 拒絕時會指出檔案名稱,並告知 Claude 重新讀取、合併,然後寫入。
  • cat 或 grep 算作一次讀取;工作階段自己的寫入不會阻止其下一次寫入;允許建立尚不存在的檔案。
  • /shared-file-guard 列出本工作階段已查看的檔案;/shared-file-guard off|on。
  • 如果模組失敗,命令將正常執行。

設定

| 設定 | 預設值 | 功能 | |---|---|---| | watched_files | STATUS.md,CLAUDE.md,MEMORY.md | 以逗號分隔的檔案名稱;* 匹配任何名稱字元序列,例如 *register*.md |

讀取和執行

  • 讀取:本工作階段讀取了哪些共享檔案(專案的狀態、指令、記憶體和暫存器檔案),以及它們上次在磁碟上變更的時間,以及每個 shell 命令的命令列。
  • 執行:拒絕 shell 寫入自本工作階段讀取後被其他工作階段變更的共享檔案,並記錄一行說明。
  • 掛鉤:Read、Edit 和 Write 上的 tool.call 僅記錄讀取的內容。Bash 上的 tool.call 可能會拒絕該命令;它從不變更它。command.run 回答它自己的 /shared-file-guard 命令,而不回答其他命令。
  • 隱私:請參閱 PRIVACY.md。
  • 從不:不發送任何內容到任何地方(無網路呼叫,無遙測)。

安裝

需要 Claude Code 2.1.287 或更高版本(模組)。在 2.1.289 上測試。

/plugin marketplace add mutlumehmet/claude-plugins
/plugin install shared-file-guard@mehmetmutlu

模組在 Claude Code 中以您的權限執行。在安裝任何模組之前請閱讀程式碼。 安裝時或之後使用 /plugin configure shared-file-guard@mehmetmutlu 會要求設定。

已知不足

  • 腳本內部建立的路徑,以及同一命令中 cd 之後的相對路徑,無法識別。
  • 它比較日期和大小,而不是雜湊值。

關於

Mehmet Mutlu: work that's shipped, at mehmetmutlu.dev

由 Mehmet Mutlu 製作,是 claude-plugins 的一部分。他的更多作品請訪問 mehmetmutlu.dev。

授權

MIT

安裝

請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。

claude plugin marketplace add mutlumehmet/claude-plugins
claude plugin install shared-file-guard
原文 / README

shared-file-guard

A Claude Code mod for running several sessions on the same project. It refuses a shell command that would write a shared file (STATUS.md, CLAUDE.md, MEMORY.md, or the files you name) when this session never read it, or another session changed it since. Part of claude-plugins.

What it does

  • The Edit and Write tools already refuse a file that changed since it was read. This closes the shell gap: heredocs, python3 scripts, sed -i, tee, mv and cp.
  • The refusal names the file and tells Claude to read it again, merge, then write.
  • A cat or grep counts as a read; a session's own writes do not block its next one; creating a file that does not exist yet is allowed.
  • /shared-file-guard lists the files this session has seen; /shared-file-guard off|on.
  • If the mod fails, the command runs as normal.

Settings

| Setting | Default | What it does | |---|---|---| | watched_files | STATUS.md,CLAUDE.md,MEMORY.md | Comma separated file names; * matches any run of name characters, such as *register*.md |

What it reads and does

  • Reads: which shared files (the project's status, instructions, memory and register files) this session read and when they last changed on disk, and the command line of each shell command.
  • Does: refuses a shell write to a shared file that another session changed since this one read it, and logs a line saying so.
  • Hooks: tool.call on Read, Edit and Write only records what was read. tool.call on Bash may refuse that one command; it never changes it. command.run answers its own /shared-file-guard command and no other.
  • Privacy: see PRIVACY.md.
  • Never: sends anything anywhere (no network calls, no telemetry).

Install

Needs Claude Code 2.1.287 or later (mods). Tested on 2.1.289.

/plugin marketplace add mutlumehmet/claude-plugins
/plugin install shared-file-guard@mehmetmutlu

A mod runs inside Claude Code with your permissions. Read the code before you install any mod. Settings are asked for at install, or later with /plugin configure shared-file-guard@mehmetmutlu.

Known gaps

  • Paths built inside a script, and relative paths after a cd in the same command, are not seen.
  • It compares date and size, not a hash.

About

Mehmet Mutlu: work that's shipped, at mehmetmutlu.dev

Made by Mehmet Mutlu, part of claude-plugins. More of his work at mehmetmutlu.dev.

License

MIT

更多類似作品