---
title: "在经历了太多次险情之后，我构建了 5 个小型 Claude Code 模组"
url: "https://claudemods.dev/zh-cn/builds/i-built-5-small-claude-code-mods-after-one-too-many-close-ca-bbda35"
source: "https://www.reddit.com/r/ClaudeCode/comments/1x401ga/i_built_5_small_claude_code_mods_after_one_too"
source_type: "reddit"
author: "ITower__Education"
author_handle: "ITower__Education"
stars: 0
category: "安全与隐私"
categories: ["security"]
tags: ["guardrails", "hooks", "safety", "statusline", "task-board"]
permission_level: null
scan_complete: false
added: "2026-10-16T16:49:50.897Z"
updated: "2026-10-16T16:49:50.897Z"
locale: "zh-cn"
content_locale: "zh-cn"
---

# 在经历了太多次险情之后，我构建了 5 个小型 Claude Code 模组

一位 Reddit 用户分享了他们在多次险情之后构建的五个小型 Claude Code hook 模组：一个破坏性命令防护，会在 git reset --hard 或 rm -rf 时暂停并列出有风险的未提交文件；一个提示上方的上下文用量天气预报指示器；一个用于粘贴密钥的 API 密钥过滤器；一个对推送到 main 以及周五下午的阻止；以及一个 Claude 可读取并可追加的任务看板。作者指出 hook 会失败开放——崩溃的 hook 会被跳过，因此他们添加了一个捕获，将任何崩溃转换为拒绝——并承认这些防护只是模式匹配，并非万无一失。

## Description

r/ClaudeCode 上的 Reddit 帖子，描述了作者构建的五个小型 Claude Code 模组，每个大约 20-50 行。最突出的一个是破坏性命令防护：当 Claude 尝试 git reset --hard 或 rm -rf 时，它会暂停，显示哪些未提交文件会丢失，并请求确认，通常会提议改为 stash。作者强调，崩溃的 hook 会被静默跳过，因此未加防护的失败会让一切通过，于是他们添加了一个捕获，将崩溃转为拒绝。另外四个模组：一个提示上方的上下文用量天气预报指示器，一个用于意外粘贴密钥的 API 密钥过滤器，一个对推送到 main（以及周五下午 3 点之后的任何操作）的阻止，以及一个 Claude 可读取并可添加内容的看板。作者指出，密钥过滤器只检查键入输入，命令防护是模式匹配，因此隐藏在脚本中的代码可能溜过去。未提供仓库链接或安装说明。

## Original README

Claude Code opened up to mods recently so I built a few for stuff that kept biting me. Each one is 20-50 lines. I built them with Claude Code itself. I described what each mod should do, Claude wrote the first version, then I tested it in a live session and asked it to fix whatever broke. The regex lists for risky commands and API key formats were mostly Claude’s, I just trimmed them down. The most useful one by far stops destructive commands. If Claude tries git reset --hard or rm -rf , it pauses, shows which uncommitted files would be lost and asks me. If I say no, Claude usually just offers to stash first. Funny thing I didn’t expect: if a hook crashes, Claude Code just skips it. So a broken guard lets everything through. Had to add a catch that turns any crash into a deny. Lesson for me: always decide what your mod should do when it fails, because the default is “do nothing”. The other four: context usage shown as a little weather forecast above the prompt, a filter that hides API keys if you paste them by accident, a block on pushing to main (and on anything after 3pm Friday), and a task board Claude can read and add to. None of them are bulletproof btw. The key filter only sees what you type, and the command guard is just pattern matching, so something hidden inside a script gets past it. Is anyone else making mods? I’d like to see what people come up with.   submitted by   /u/ITower__Education   to   r/ClaudeCode [link]   [comments]
