Skip to content

Deny Bash writes to memory files unless the command only reads - #58

Merged
bguidolim merged 2 commits into
mainfrom
bruno/kb-gate-bash-memory-writes
Nov 3, 2026
Merged

bguidolim merged 2 commits into
mainfrom
bruno/kb-gate-bash-memory-writes

Conversation

@bguidolim

Copy link
Copy Markdown
Collaborator

Why

The memory gate checked Bash only for deletes, so a session could rewrite a memory with a heredoc script, a redirect or sed -i and skip the continuous-learning checks that a file-tool edit is held to. It also matched the bare word "memories", which denied harmless reads such as a grep whose pattern mentioned it.

Now any Bash command that names a memory path, including the real directory behind a symlinked one, is denied unless every part of it is a plain read. This holds even while a memory skill is active, since memory edits belong to Edit and Write. Deletes still need memory-audit. The per-turn budget still lets a misjudged read through.

Test plan

  • mcs sync, then in a session run echo x > .claude/memories/tmp.md → expect a denial pointing to Edit/Write
  • Run cat or grep on a memory file → expect it to run
  • Run git commit -m "…memories…" → expect no denial

- Gate any Bash command naming a memories path, including a symlinked dir's target, not only deletes
- Match memory paths instead of the bare word, so read-only commands mentioning it pass
- Drop the shared-memories layout from tests and document the rule in CLAUDE.md
- Match the resolved memories dir with escapeRegExp and under() instead of a hand-rolled scan
- Skip symlink resolution when the command already names .claude/memories
- Key deny reasons by kind and drop a duplicated sub-agent assertion
@bguidolim
bguidolim force-pushed the bruno/kb-gate-bash-memory-writes branch from 7346806 to 00eb670 Compare October 31, 2026 23:47
@bguidolim
bguidolim merged commit 2b14ea1 into main Nov 3, 2026
5 checks passed
@bguidolim
bguidolim deleted the bruno/kb-gate-bash-memory-writes branch November 3, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant