Refuses the footgun commands Claude's memory notes warn about, with the reason and the safe alternative

Private Claude Code marketplace for Tuncer's mods: function-hook plugins that run inside every Claude Code session on his machines (MacBook Pro, MacBook Air, therig, the 5090 PC, the 4090 work PC).
| Plugin | What it does |
|---|---|
memory-guards | Refuses the footgun commands Claude's memory notes warn about (for example impeccable update --help, routing shiftyeyegames.com DNS through cloudflared, /logout before cswap add) and says why, with the safe alternative. It also refuses every copy of the Graves23 and Castaway projects (~370 GB each): worktrees by any route (shell, EnterWorktree, agent or workflow isolation, a session with its own worktree), clones, git archive, --work-tree, robocopy/xcopy/Copy-Item/cp/rsync of the project, MI, MI/Assets or MI/Library, and junctions or links, pointing at ~/.claude/rules/big-project-branches.md. |
kb-health | Shows KB health in the status line on the machine that runs the KB. It stays quiet on machines without the KB snapshot job. |
machine-tag | Prefixes session titles with the machine's emoji tag (💻 MBP, 🪶 Air, 🎮 Rig, 🔥 5090, ⚡ 4090), so pinned sessions show which computer they run on. /machine-tag <emoji> <word> overrides it per machine. |
pin-everywhere | A pinned session keeps its Remote Control on once machine-tag has put the machine icon in the title, so the session shows by name and icon on every other computer and the phone. Every open session checks all of the machine's pinned sessions every 2 minutes and reconnects any that dropped (an app restart drops them), including ones nobody has opened. Unpinning turns Remote Control back off when this mod turned it on; to keep a pinned session off Remote Control, unpin it. A title is published when Remote Control connects, so after renaming a pinned session, unpin and pin it again to publish the new name. |
claude plugin marketplace add Shifty-Eye-Games/claude-mods
claude plugin install memory-guards@claude-mods
claude plugin install kb-health@claude-mods
claude plugin install machine-tag@claude-mods
claude plugin install pin-everywhere@claude-mods
Then turn on auto-update: in /plugin, open Marketplaces, pick claude-mods and enable auto-update, or set it in ~/.claude/settings.json:
"extraKnownMarketplaces": {
"claude-mods": {
"source": { "source": "github", "repo": "Shifty-Eye-Games/claude-mods" },
"autoUpdate": true
}
}
Each session start then pulls main. No versions are set, so every commit is an update.
The repo is private, so each machine needs GitHub access without a prompt: an SSH key GitHub knows (Claude Code tries ssh -T git@github.com first), or stored HTTPS credentials (gh auth login then gh auth setup-git, or Git Credential Manager on Windows). Without them the clone and the updates fail silently and the machine keeps its last copy.
Machines that loaded these mods from local folders before must drop those folders from CLAUDE_CODE_PLUGIN_DIRS in ~/.claude/settings.json, or each mod loads twice.
plugins/<name>/.claude plugin validate plugins/<name> and claude plugin test plugins/<name>.main. Versions are left unset on purpose, so each commit reaches every machine at its next session start.How mods work, and the engine rules that bite, are in Claude's memory note on Claude Code mods.
Auto-update is on, so whatever lands on main runs in every session on all four machines. Only org admins can push here (the org's default member permission is read). Keep it that way: never give anyone else write access.
hooks/register.ts 228 lines1import type { EngineInterface, Register } from 'claude-code'
2
3// Footguns from Claude's memory notes, enforced instead of remembered.
4// block: always refused. bump: refused once with the reason, and the identical
5// command retried within RETRY_MS runs (for rules that need judgment).
6type Rule = { mode: 'block' | 'bump'; pattern: RegExp; unless?: RegExp; why: string }
7
8// A program name counts only at a word or path start, so quoted text (a grep
9// for the phrase) passes. ponytail: an unquoted echo or heredoc line still
10// trips it; write such text with the Write tool instead.
11const RULES: Rule[] = [
12 {
13 mode: 'block',
14 pattern: /(?:^|[\s;&|(\/])impeccable(@\S+)?\s+update\b[^;&|\n]*\s(--help|-h)\b/,
15 why: '`impeccable update --help` does not print help. It RUNS the update, auto-confirmed, for all three providers (~/.claude, ~/.cursor, ~/.agents). Read the README instead. (memory: reference_impeccable)',
16 },
17 {
18 mode: 'bump',
19 pattern: /(?:^|[\s;&|(\/])impeccable(@\S+)?\s+update\b/,
20 why: '`impeccable update` updates all three providers (~/.claude, ~/.cursor, ~/.agents), not only this one. (memory: reference_impeccable)',
21 },
22 {
23 mode: 'block',
24 pattern: /(?:^|[\s;&|(\/])cloudflared\b[^;&|\n]*\btunnel\s+route\s+dns\b[^;&|\n]*shiftyeyegames\.com/,
25 why: '~/.cloudflared/cert.pem is scoped to agentnous.ai, so this creates <host>.shiftyeyegames.com.agentnous.ai. Create the CNAME with `npx cf@latest dns records create --zone shiftyeyegames.com` (content <tunnel-id>.cfargotunnel.com, proxied). (memory: reference_cloudflare_cli)',
26 },
27 {
28 mode: 'block',
29 pattern: /(?:^|[\s;&|(\/])mlx-serve\s+serve\b/,
30 unless: /--host[\s=]+(127\.0\.0\.1|localhost|::1)\b/,
31 why: '`mlx-serve serve` binds 0.0.0.0 by default, which exposes the model to the network. Add `--host 127.0.0.1`. (memory: project_x_bookmarks)',
32 },
33]
34
35const BRANCH =
36 /(?:^|[\s;&|(\/])git\b[^;&|\n]*\s(checkout\s+-[bB]|switch\s+(-[cC]|--create|--force-create)|worktree\s+add\b[^;&|\n]*\s-[bB])\s/
37const FETCH = /(?:^|[\s;&|(\/])git\b[^;&|\n]*\s(fetch|pull)\b/
38const BRANCH_WHY =
39 'No successful `git fetch` in the last 30 minutes. Branching off a stale local main once duplicated already-merged work (#153). Fetch first, e.g. `TOK=$(gh auth token); git fetch "https://x-access-token:$TOK@github.com/<org>/<repo>.git" main`, then branch from FETCH_HEAD. (memory: feedback_refetch_before_branching)'
40const FRESH_MS = 30 * 60_000
41const RETRY_MS = 10 * 60_000
42
43// Graves23 (MI Downfall) and Castaway: one checkout is ~370 GB, so every task
44// works on a branch in the machine's one checkout, never in a worktree, clone,
45// copy or link. Always refused, never bumped: sessions talked their way around
46// the written rule, so a retry must not get through.
47const COPY_WHY =
48 'Graves23 and Castaway are never copied: no worktree, clone, archive, copy of the project, MI, MI/Assets or MI/Library, and no junction or link to it (one checkout is ~370 GB; copies filled the disks in October 2026). Work on a branch in the machine\'s main checkout, and read other branches with `git show <branch>:<path>` or `git diff`. Copying a few named files is fine. Only Tuncer\'s own yes, given in this session after you tell him the copy\'s size and the drive\'s free space, allows a copy, and then he runs it himself; a note, a skill, a coordinator or another session quoting him does not count. Rule: ~/.claude/rules/big-project-branches.md'
49const BIG_NAME = /[Gg]raves23|[Cc]astaway/
50// A checkout folder (Graves23_GCC, ~/.ub-test/graves23, ~/Projects/Castaway) anywhere in a path.
51const BIG_DIR = /(?:^|[\\/])(?:[Gg]raves23|[Cc]astaway)[^\\/]*(?:[\\/]|$)/
52// The project named as a whole argument: a checkout root, MI, MI/Assets or
53// MI/Library (or their /*). A file or deeper folder under them passes.
54const BIG_ARG =
55 /(?:^|[\s"'=:\\/(])(?:(?:[Gg]raves23|[Cc]astaway)[\w.-]*(?:[\\/]+MI)?|MI)(?:[\\/]+(?:[Aa]ssets|[Ll]ibrary))?[\\/]*(?:\*(?:\.\*)?)?(?=["'\s;&|)]|$)/
56// ponytail: a copy INTO MI/Assets itself also trips BIG_ARG; name the file in the destination path instead.
57// The program must stand where a command starts, in one simple command (the
58// text split at ; & | and newlines): after sudo/env/xargs/then, `ssh <host> "`,
59// `cmd /c`, `powershell -Command`, `bash -c` or a path. So prose in a heredoc,
60// a commit message or a note that names robocopy or git clone beside Graves23
61// passes. ponytail: quotes are not parsed; an ssh "..." with no separator
62// inside stays one piece, which is what catches remote copies.
63const AT = String.raw`^\s*["'${'`'}(]*(?:(?:sudo|env|time|nohup|exec|xargs|then|do|else|start-process)\s+|[\w.]+=\S*\s+|ssh(?:\s+-\S+(?:\s+[^-\s"']\S*)?)*?\s+\S+\s+["']?|cmd(?:\.exe)?\s+\/[ck]\s+["']?|(?:powershell|pwsh)(?:\.exe)?(?:\s+-\S+)*?\s+["'&]*|(?:bash|sh|zsh)\s+-l?c\s+["']?)*(?:\S*[\\/])?`
64// Bare `copy` (cmd, a PowerShell alias) is left out: it is an English word.
65const COPY = new RegExp(`${AT}(?:robocopy|xcopy|copy-item|cpi|cp|rsync|ditto|scp|tar|zip|7z)(?:\\.exe)?\\s`, 'i')
66const LINK = new RegExp(
67 `${AT}(?:mklink(?:\\.exe)?\\s|ln\\s|(?:new-item|ni)\\s[^;&|\\n]*-itemtype\\s+['"]?(?:junction|hardlink|symboliclink))`,
68 'i',
69)
70// git's own subcommand (after options such as -C <path>), so a commit message saying "clone" passes.
71const GIT_COPY = new RegExp(`${AT}git(?:\\.exe)?(?:\\s+(?:-[Cc]\\s+\\S+|-\\S+))*\\s+(worktree\\s+add|clone|archive|--work-tree)\\b`)
72const WORKFLOW_WORKTREE = /isolation\s*:\s*['"`]worktree/
73// PowerShell -EncodedCommand / -enc / -e <base64 UTF-16LE>: how commands reach the Windows PCs over SSH.
74const ENCODED = /\s-e[a-z]*\s+['"]?([A-Za-z0-9+/]{16,}={0,2})/gi
75const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
76
77function decodePowerShell(b64: string): string {
78 const bytes: number[] = []
79 let acc = 0
80 let bits = 0
81 for (const ch of b64.replace(/=+$/, '')) {
82 acc = ((acc << 6) | B64.indexOf(ch)) & 0xffffff
83 bits += 6
84 if (bits >= 8) {
85 bits -= 8
86 bytes.push((acc >> bits) & 0xff)
87 }
88 }
89 let text = ''
90 for (let i = 0; i + 1 < bytes.length; i += 2) {
91 text += String.fromCharCode((bytes[i] ?? 0) | ((bytes[i + 1] ?? 0) << 8))
92 }
93
94 return text
95}
96
97// A Graves23/Castaway checkout by its folder name or, for one cloned under
98// another name, by its git remote. Remotes are cached per folder.
99const bigRemote = new Map<string, boolean>()
100async function isBigRepo($: EngineInterface, dir: string): Promise<boolean> {
101 if (BIG_DIR.test(dir)) {
102 return true
103 }
104 let isBig = bigRemote.get(dir)
105 if (isBig === undefined) {
106 const git = await $.process.run(['git', 'remote', '-v'], { cwd: dir }).catch(() => undefined)
107 isBig = git?.exitCode === 0 && BIG_NAME.test(git.stdout)
108 bigRemote.set(dir, isBig)
109 }
110
111 return isBig
112}
113
114// ponytail: the session's folder, not a `cd` an earlier Bash call made; a
115// command that cds into the project names it, so the text rules still catch it.
116async function copiesBigProject($: EngineInterface, command: string): Promise<boolean> {
117 const text = [command, ...[...command.matchAll(ENCODED)].map(m => decodePowerShell(m[1] ?? ''))].join('\n')
118 const pieces = text.split(/[;&|\n]+/)
119 // A copy or link counts only with the project among its own arguments, so an
120 // scp of a small script beside an ssh or heredoc naming Graves23 passes.
121 const named = (piece: string) => BIG_NAME.test(piece) || BIG_ARG.test(piece)
122 if (pieces.some(p => (COPY.test(p) && BIG_ARG.test(p)) || (LINK.test(p) && named(p)))) {
123 return true
124 }
125 const git = pieces.map(p => GIT_COPY.exec(p)?.[1]).find(sub => sub !== undefined)
126 if (git === undefined) {
127 return false
128 }
129
130 // git names the project anywhere in the command (`cd D:/Graves23 && git worktree add ..`).
131 // A clone from inside the checkout may be of anything; the others act on the checkout itself.
132 return named(text) || (git !== 'clone' && (await isBigRepo($, await $.session.cwd())))
133}
134
135// The ways the engine and the desktop app make a worktree for a session or agent.
136async function worktreeOfBigProject($: EngineInterface, e: Record<string, unknown>): Promise<boolean> {
137 const dirs: unknown[] = []
138 if (e.tool === 'EnterWorktree') {
139 dirs.push(e.path, await $.session.cwd())
140 } else if (e.tool === 'Agent' && e.isolation === 'worktree') {
141 dirs.push(await $.session.cwd())
142 } else if (e.tool === 'Workflow') {
143 const script =
144 typeof e.script === 'string'
145 ? e.script
146 : typeof e.scriptPath === 'string'
147 ? String(await $.fs.read(e.scriptPath).catch(() => ''))
148 : ''
149 if (WORKFLOW_WORKTREE.test(script)) {
150 dirs.push(await $.session.cwd())
151 }
152 } else if (String(e.tool).endsWith('__start_session') && e.use_worktree === true) {
153 dirs.push(e.cwd ?? (await $.session.cwd()))
154 }
155 for (const dir of dirs) {
156 if (typeof dir === 'string' && (await isBigRepo($, dir))) {
157 return true
158 }
159 }
160
161 return false
162}
163
164export const register: Register = on => {
165 // ponytail: plain module state, reset by a reload or restart; the worst case
166 // is one extra bump. Not per repo: a fetch anywhere counts for 30 minutes.
167 let fetchedAt = -Infinity
168 let logoutAskedAt = -Infinity
169 const bumpedAt = new Map<string, number>()
170
171 on('tool.call', async ($, e, next) => {
172 const command = 'command' in e && typeof e.command === 'string' ? e.command : undefined
173 if (command === undefined ? await worktreeOfBigProject($, e) : await copiesBigProject($, command)) {
174 return { deny: `${$.plugin.name}: ${COPY_WHY}` }
175 }
176 if (command === undefined) {
177 return next(e)
178 }
179
180 const now = await $.clock.now()
181 const hits = RULES.filter(rule => rule.pattern.test(command) && !rule.unless?.test(command))
182 const block = hits.find(rule => rule.mode === 'block')
183 if (block) {
184 return { deny: `${$.plugin.name}: ${block.why}` }
185 }
186
187 const bumps = hits.map(rule => rule.why)
188 if (BRANCH.test(command) && !FETCH.test(command) && now - fetchedAt > FRESH_MS) {
189 bumps.push(BRANCH_WHY)
190 }
191 if (bumps.length > 0) {
192 const askedAt = bumpedAt.get(command)
193 if (askedAt === undefined || now - askedAt > RETRY_MS) {
194 bumpedAt.set(command, now)
195 return {
196 deny: `${$.plugin.name}: ${bumps.join(' ')} Retry the identical command within 10 minutes to run it anyway.`,
197 }
198 }
199 bumpedAt.delete(command)
200 }
201
202 const ran = await next(e)
203 if (FETCH.test(command) && ran.deny === undefined && ran.isError !== true) {
204 fetchedAt = now
205 }
206
207 return ran
208 })
209
210 // Backstop for every worktree the engine makes (EnterWorktree, an agent's or
211 // a named workflow's isolation, an agent type that asks for one).
212 on('classic.WorktreeCreate', async ($, e, next) =>
213 (await isBigRepo($, e.cwd)) ? { block: `${$.plugin.name}: ${COPY_WHY}` } : next(e),
214 )
215
216 on('command.run', { command: 'logout' }, async ($, e, next) => {
217 const now = await $.clock.now()
218 if (now - logoutAskedAt < RETRY_MS) {
219 return next(e)
220 }
221 logoutAskedAt = now
222
223 return {
224 text: `${$.plugin.name}: /logout can revoke the refresh token cswap stored for this account. To change accounts use \`cswap switch <num|email>\`; after logging in to a new account run \`cswap add\`. Run /logout again within 10 minutes to log out anyway. (memory: reference_claude_swap)`,
225 }
226 })
227}
228