theagitist/claude-mods/tree/main/dot-guard
dot-guard
一個 Claude Code function-hook 外掛,會阻止 `git add` 將整個 `$HOME` 工作樹加入暫存區(`dot add -A`、`dot add .`、`dot add *`)。提供透過 `CLAUDE_CODE_PLUGIN_DIRS` 或 `--plugin-dir` 安裝的說明,也能用 `dot-guard.wrappers` 設定自訂 dotfiles 別名。
關於這個 mod
dot-guard 是 theagitist/claude-mods 儲存庫中的五個小型 Claude Code function-hook mod 之一。當 Bash 的 git add 指令會將整個 $HOME 工作樹加入暫存區時,它會拒絕這次呼叫(例如 dot add -A、dot add .、dot add *),向模型回傳拒絕原因,而不是執行指令。
安裝(每台機器一次):
- 將儲存庫複製到每台機器上的相同相對路徑,例如
git clone <remote> ~/apps/claude-mods。 - 將 Claude Code 指向 mod 資料夾。例如,在
~/.claude/settings.json的env區塊中將CLAUDE_CODE_PLUGIN_DIRS設為 mod 目錄,或使用claude --plugin-dir ~/apps/claude-mods/dot-guard依工作階段載入。
設定:
dot-guard.wrappers── 使用--work-tree=$HOME執行 git 的逗號分隔指令名稱(預設值為dot)。如果自己的 dotfiles 別名不同,請改成對應別名。
結構:
dot-guard/.claude-plugin/plugin.json── 外掛資訊清單。dot-guard/hooks/hooks.json和dot-guard/hooks/register.ts── hook 註冊;攔截tool.call的Bash,並從環境讀取HOME。
使用 claude plugin validate <mod> 和 claude plugin test <mod> 驗證並測試。
安裝
請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。
claude plugin marketplace add theagitist/claude-mods claude plugin install dot-guard
原文 / README
claude-mods
Five small Claude Code mods (function-hook plugins). They run in the terminal CLI (no GUI panes), and they are written to work the same on every machine: Linux or macOS, any username, any home directory. Nothing personal is baked into the source. Per-machine values (a Telegram chat id, an email address) come from the environment, so the same checkout is safe to push publicly and hand to other people.
The mods
| Mod | What it does | How it shows |
|---|---|---|
| dot-guard | Blocks a git add that would stage your whole $HOME work-tree (dot add -A, dot add ., dot add *). One fat-finger away from committing your entire home directory. | Denies the tool call with a reason. |
| emdash-watch | Flags em-dashes the model writes into public-facing prose (.md, .html, .css, .txt, .rst). Internal files (CLAUDE.md, anything under memory/ or .claude/) are exempt. | Non-blocking note appended to the write's result, visible to the model only. |
| home-path-guard | Flags a hardcoded user home (/home/<user>, /Users/<user>) written into a file, nudging $HOME / ~. Machine-local files (*.local.*) are exempt. | Non-blocking note to the model. |
| box-status | Status line showing which box you are on, which out-of-band channel it can reach you on (telegram / email / none), and whether passwordless sudo works. | One status-line entry under the prompt. |
| idle-ping | When a turn that did real work ends, pings you out of band so you can step away. Telegram when a bot token and chat id are present, otherwise email. | Sends a message; logs to the debug sink when no channel is configured. |
Install (per machine)
Clone this repo to the same relative path on each box, for example:
git clone <your-remote> ~/apps/claude-mods
Then point Claude Code at the five folders. The cleanest cross-machine way is
CLAUDE_CODE_PLUGIN_DIRS in the env block of ~/.claude/settings.json
(which uses ~, so the one line works on every machine):
{
"env": {
"CLAUDE_CODE_PLUGIN_DIRS": "~/apps/claude-mods/dot-guard:~/apps/claude-mods/emdash-watch:~/apps/claude-mods/box-status:~/apps/claude-mods/home-path-guard:~/apps/claude-mods/idle-ping"
}
}
(On Windows the list separator is ; instead of :.)
Or load them for a single session without touching settings:
claude --plugin-dir ~/apps/claude-mods/dot-guard --plugin-dir ~/apps/claude-mods/idle-ping
Per-machine configuration (idle-ping)
idle-ping reads its target from the environment, never from source:
- Telegram (preferred when set): it reads
TELEGRAM_BOT_TOKEN(and optionallyTELEGRAM_CHAT_ID) from~/.claude/channels/telegram/.env, andTELEGRAM_CHAT_IDfrom the process environment if not in that file. Keep that file out of version control (mode600). - Email (fallback): set
CLAUDE_PING_EMAILto the recipient. The mod sends through the first mailer it finds onPATH(msmtp,sendmail,mail,mailx). - If neither is configured, it writes what it would have sent to the debug log and does nothing else.
box-status reports the same channel resolution, so a glance at the status line
tells you whether a ping would actually go out on this box.
Settings knobs
dot-guard.wrappers(defaultdot): comma-separated command names that run git with--work-tree=$HOME. Set it to your own dotfiles alias if it is notdot.idle-ping.minTools(default2): how many tool calls a turn needs before it counts as real work worth a ping. Raise it to ping less often.
Developing
Each mod is a folder with .claude-plugin/plugin.json, hooks/hooks.json, and
hooks/register.ts. Check and test one with:
claude plugin validate <mod>
claude plugin test <mod>
