Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

claude-keysmith

Claude Code 指令文件部署:可管理的 CLAUDE.md import block,及可选的 user-scope runtime wrapper。

简体中文 · English · Reference · 智能体安装 / Agent install · License

Prompt v4.0 Python 3.8+ License MIT

简体中文

这是什么

claude-keysmith 是 Claude Code 的本地指令部署工具:它把一份 Markdown 指令保存到 keysmith 管理目录,并在 CLAUDE.mdCLAUDE.local.md 中插入可识别、可卸载的 import block。

可选的 --runtime 会额外对齐 settings.jsonsystemPrompt,并安装 managed shell wrapper,使每次 shell 调用自动带上 --system-prompt-file--append-system-prompt-file:macOS / Linux 使用 ~/.zshrc 中的 claude(),Windows PowerShell 使用 profile 中的 function global:claude

默认只预览;显式传入 --yes 才写入。写入前备份,卸载时只移除自己的 block 和文件。

[!WARNING] user scope 的 import block 会影响加载 ~/.claude/CLAUDE.md 的新会话;--runtime 还会影响通过 managed shell wrapper 启动的后续会话。先阅读 examples/claude-project-rules.mdexamples/claude-append-prompt.md,运行 dry-run 确认路径与变更后,再使用 --yes。本工具不修改二进制、网络、MCP 或凭证,也不承诺覆盖 Claude Code、模型提供方或 API 网关的策略。

快速开始(macOS / Linux)

# 1. 先预览项目级部署;默认不写入
python3 claude-instruct.py install \
  --scope project \
  --project-dir /path/to/repo

# 2. 确认后才写入
python3 claude-instruct.py install \
  --scope project \
  --project-dir /path/to/repo \
  --name claude-project-rules \
  --yes

# 3. 检查状态
python3 claude-instruct.py status \
  --scope project \
  --project-dir /path/to/repo \
  --name claude-project-rules \
  --json

需要 user-scope runtime 时:

python3 claude-instruct.py install --scope user --runtime       # 先预览
python3 claude-instruct.py install --scope user --runtime --yes
source ~/.zshrc
python3 claude-instruct.py doctor --json

Windows PowerShell:

python .\claude-instruct.py install --scope user --runtime       # 先预览
python .\claude-instruct.py install --scope user --runtime --yes
. $PROFILE
python .\claude-instruct.py doctor --json

Windows 可用以下可选环境变量覆盖自动检测:CLAUDE_KEYSMITH_HOMECLAUDE_KEYSMITH_SHELLCLAUDE_KEYSMITH_SHELL_RCCLAUDE_KEYSMITH_CLAUDE_BIN

不要用 curl | python 直接执行;先下载或 clone 仓库、检查脚本与示例,再运行。

它会改哪些文件

路径会发生什么
~/.claude/CLAUDE.md<repo>/CLAUDE.md<repo>/CLAUDE.local.md插入或替换一个同名 managed import block;已有文件先备份
相邻的 keysmith/<name>.md.claude/keysmith/<name>.md新建,或先备份再替换
~/.claude/keysmith/system-prompt.mdappend-prompt.md--runtime:新建或备份后替换
~/.claude/settings.json--runtime:对齐顶层 systemPrompt;使用 --max-tokens 时才更新该字段;其余字段保留
~/.zshrc(macOS / Linux)或 PowerShell profile(Windows)--runtime:插入或替换一个带边界标记的 managed wrapper;已有文件先备份

完整所有权、settings 更新与恢复语义见 docs/reference.md

撤销

# 项目级:先预览,再加 --yes
python3 claude-instruct.py uninstall \
  --scope project \
  --project-dir /path/to/repo \
  --name claude-project-rules

# user-scope runtime:移除 keysmith prompt 文件和 managed wrapper
python3 claude-instruct.py uninstall --scope user --runtime --yes

uninstall --runtime 不自动恢复 settings.json 的旧 systemPrompt,避免覆盖安装后由其他工具或用户写入的配置。需要恢复时,从安装前生成的 timestamp 备份显式执行:

python3 claude-instruct.py restore \
  --target ~/.claude/settings.json \
  --backup ~/.claude/settings.json.bak_YYYYMMDD_HHMMSS_pre_runtime \
  --yes

出问题了怎么办

现象应该做的事
不确定会改什么不加 --yes 运行同一条 install / uninstall,检查 dry-run 输出
import block 或文件状态异常运行 status --scope … --json,确认目标路径、block 与指令文件
runtime 看起来没有生效macOS / Linux 先 source ~/.zshrc,Windows 先 . $PROFILE;然后运行 doctor --json,确认 prompt 文件、settings 对齐与 managed wrapper
需要回滚指定对应的 timestamp 备份运行 restore;恢复前工具会再为当前文件创建备份

兼容性与限制

  • 推荐 Python 3.8+;runtime wrapper 支持 macOS / Linux 的 zsh 与 Windows 的 PowerShell。
  • Windows 默认检测 PowerShell profile 与 npm 全局安装的 claude.cmd;可用 CLAUDE_KEYSMITH_* 环境变量覆盖路径。
  • 只管理 claude-keysmith 自己插入的 HTML 注释 block,不覆盖用户其余 memory 内容。
  • 不管理 Claude Code 二进制、运行中进程、网络、MCP、token、cookie、Base URL、hooks 或 permissions。
  • 不验证某个既有会话是否重新加载指令;部署后启动新会话并做实际 smoke test。
  • 备份不会自动删除;确认无需回滚后再手动清理。

参与贡献

python3 -m py_compile claude-instruct.py
python3 -m pytest tests

智能体安装流程见 docs/agent-install.md;文件所有权和完整运行时参考见 docs/reference.md

友链 / Community

本项目接受 LINUX DO 社区佬友监督与反馈:LINUX DO

同系列项目 / Same series:

关于 About

Claude Code CLAUDE.md import-block installer for local instruction files

语言 Languages

Python100.0%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
9
Total Commits
峰值: 6次/周
Less
More

核心贡献者 Contributors