ClaudeMods
☰
ZH-CN
● 0 人在线 · 浏览 0 次
赞助提交作品
GitHub 仓库 · 发布者 mutlumehmet

shared-file-guard

拒绝本会话未读取的共享文件(STATUS.md、CLAUDE.md、MEMORY.md 或您命名的文件)的 shell 写入,或者自上次读取以来被其他会话更改的共享文件的 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

更多类似作品