Claude Code CLAUDE.md import-block installer for local instruction files.
Status boundary / 状态边界
claude-keysmithis a small local helper for managing Claude CodeCLAUDE.mdimport blocks and separate Markdown instruction files. It is not a Claude Code fork, does not patch binaries, does not intercept network traffic, does not save credentials, tokens, cookies, or MCP secrets, and does not guarantee that installed instructions will improve model behavior.
claude-keysmith是一个小型本地工具,用来管理 Claude CodeCLAUDE.md中的 import 区块,以及独立存放的 Markdown 指令文件。它不是 Claude Code 分叉版,不修改二进制,不劫持网络,不保存凭证、token、cookie 或 MCP 机密,也不保证安装后的指令一定改善模型行为。
把下面这段话复制到 Codex、Claude Code、Cursor Agent 或其他智能体:
请使用 https://github.com/Jia-Ethan/claude-keysmith 帮我安全安装 Claude Code 的 user scope 本地 CLAUDE.md import-block 指令文件,也就是写入 ~/.claude/CLAUDE.md 和 ~/.claude/keysmith/<name>.md。先阅读 README 和脚本,默认只做静态审计和 dry-run,不要直接写入;写入前展示将修改的准确文件路径、备份路径和 import block,并等我确认;确认后先备份再安装。不要修改 Claude Code 二进制、settings、MCP、网络、运行进程,也不要保存任何 token、cookie 或私密配置。
本项目接受 LINUX DO 社区佬友监督与反馈:LINUX DO
Claude Code already supports persistent instructions through CLAUDE.md, CLAUDE.local.md, project .claude files, and @path/to/import imports. This tool does not replace that system. It only gives you a safer, repeatable way to place one instruction file under a keysmith-managed directory and insert a small managed import block into the appropriate Claude memory file.
Official references:
claude-keysmith 是 codex-keysmith 思路的 Claude Code 版改造。原项目围绕 Codex CLI 的 model_instructions_file 与 ~/.codex/config.toml;本项目不写 Codex 配置,也不写 Claude Code 的真实设置 JSON、token、cookie、MCP 或二进制。
Claude Code 版的核心是:
- 将指令 Markdown 写入 keysmith 管理目录;
- 在目标
CLAUDE.md或CLAUDE.local.md中插入一个可识别、可卸载的 import block; - 只管理自己的 block,不覆盖整份用户文件。
| scope | 被修改的 Claude memory 文件 | 指令文件位置 | import 目标 |
|---|---|---|---|
user |
~/.claude/CLAUDE.md |
~/.claude/keysmith/<name>.md |
@keysmith/<name>.md |
project |
<repo>/CLAUDE.md |
<repo>/.claude/keysmith/<name>.md |
@.claude/keysmith/<name>.md |
local |
<repo>/CLAUDE.local.md |
<repo>/.claude/keysmith/<name>.md |
@.claude/keysmith/<name>.md |
Managed block example:
<!-- claude-keysmith:start name=claude-project-rules -->
@.claude/keysmith/claude-project-rules.md
<!-- claude-keysmith:end name=claude-project-rules -->- 默认 dry-run:没有
--yes时只预览,不写入;如果--dry-run和--yes同时出现,--dry-run优先。 - 写入前备份已存在的
CLAUDE.md/CLAUDE.local.md。 - 覆盖同名 keysmith 指令文件前先备份。
uninstall只移除同名 managed block,并备份后移除对应 keysmith 指令文件。restore会先备份当前 target,再用指定 backup 恢复。--name只允许字母、数字、点、下划线、连字符,拒绝路径、绝对路径、..、空文件名和空格。- 不修改
~/.claude/settings.json、.claude/settings.json、MCP、凭证、二进制或运行中进程。
先预览,不写入:
python3 claude-instruct.py install --scope project --project-dir /path/to/repo确认后写入项目级规则:
python3 claude-instruct.py install \
--scope project \
--project-dir /path/to/repo \
--name claude-project-rules \
--yes安装到用户级 ~/.claude/CLAUDE.md:
python3 claude-instruct.py install --scope user --name personal-rules --yes安装到本地项目偏好 CLAUDE.local.md:
python3 claude-instruct.py install \
--scope local \
--project-dir /path/to/repo \
--name local-rules \
--yes使用自己的 Markdown 指令文件:
python3 claude-instruct.py install \
--scope project \
--project-dir /path/to/repo \
--file ./my-claude-rules.md \
--name team-rules \
--yespython3 claude-instruct.py status --scope project --project-dir /path/to/repo --name team-rulesJSON 输出:
python3 claude-instruct.py status --scope user --name personal-rules --json默认只预览:
python3 claude-instruct.py uninstall --scope project --project-dir /path/to/repo --name team-rules确认卸载:
python3 claude-instruct.py uninstall --scope project --project-dir /path/to/repo --name team-rules --yesuninstall 不会清空整份 CLAUDE.md;它只删除:
<!-- claude-keysmith:start name=team-rules -->
...
<!-- claude-keysmith:end name=team-rules -->以及对应的 .claude/keysmith/team-rules.md 文件。
从指定备份恢复:
python3 claude-instruct.py restore \
--target /path/to/repo/CLAUDE.md \
--backup /path/to/repo/CLAUDE.md.bak_YYYYMMDD_HHMMSS \
--yes没有 --yes 时只预览,不写入。
python3 -m py_compile claude-instruct.py
python3 -m pytest tests额外建议用临时 HOME / 临时 project directory 跑 user、project、local 三种 scope,确认不会触碰真实 Claude Code 配置。
claude-keysmith/
├── claude-instruct.py
├── examples/
│ └── claude-project-rules.md
├── tests/
│ └── test_claude_instruct.py
├── README.md
├── LICENSE
└── .gitignore
- 目前是单文件 Python CLI,还没有打包成
pip install工具。 - 只管理
claude-keysmith自己插入的 HTML 注释区块。 - 不验证 Claude Code 是否实际加载了 import;需要在 Claude Code 内通过
/memory或真机 smoke test 确认。 - 不管理
.claude/rules/、settings、hooks、permissions、MCP 或自动记忆目录。
claude-keysmith is a local helper for installing Markdown instruction files into Claude Code's official memory/import model. It writes a separate instruction file and inserts a small managed import block into CLAUDE.md or CLAUDE.local.md.
It is adapted from the safety posture of codex-keysmith, but it intentionally does not reuse Codex-specific logic such as ~/.codex/config.toml or model_instructions_file.
| scope | Memory file | Instruction file | Import target |
|---|---|---|---|
user |
~/.claude/CLAUDE.md |
~/.claude/keysmith/<name>.md |
@keysmith/<name>.md |
project |
<repo>/CLAUDE.md |
<repo>/.claude/keysmith/<name>.md |
@.claude/keysmith/<name>.md |
local |
<repo>/CLAUDE.local.md |
<repo>/.claude/keysmith/<name>.md |
@.claude/keysmith/<name>.md |
Preview install:
python3 claude-instruct.py install --scope project --project-dir /path/to/repoWrite after explicit confirmation:
python3 claude-instruct.py install --scope project --project-dir /path/to/repo --yesCheck status:
python3 claude-instruct.py status --scope project --project-dir /path/to/repo --name claude-project-rulesUninstall only the matching managed block:
python3 claude-instruct.py uninstall --scope project --project-dir /path/to/repo --name claude-project-rules --yesRestore from a selected backup:
python3 claude-instruct.py restore --target ./CLAUDE.md --backup ./CLAUDE.md.bak_YYYYMMDD_HHMMSS --yes- Preview-only unless
--yesis provided; if--dry-runand--yesare both provided,--dry-runwins. - Backups before modifying existing memory files or instruction files.
- Safe filename validation for
--name. - Atomic writes.
uninstallremoves only the matching managed block.- No binary patching, no network interception, no credential storage, no MCP changes, no running-process changes.
python3 -m py_compile claude-instruct.py
python3 -m pytest testsMIT