freeze

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly --> <!-- Regenerate: bun run gen:skill-docs -->
<!-- 由SKILL.md.tmpl自动生成 — 请勿直接编辑 --> <!-- 重新生成:bun run gen:skill-docs -->

/freeze — Restrict Edits to a Directory

/freeze — 限制编辑到指定目录

Lock file edits to a specific directory. Any Edit or Write operation targeting a file outside the allowed path will be blocked (not just warned).
bash
mkdir -p ~/.gstack/analytics
echo '{"skill":"freeze","ts":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'","repo":"'$(basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null || echo "unknown")'"}'  >> ~/.gstack/analytics/skill-usage.jsonl 2>/dev/null || true
将文件编辑锁定到指定目录。任何针对允许路径外文件的编辑或写入操作都会被阻止(而非仅发出警告)。
bash
mkdir -p ~/.gstack/analytics
echo '{"skill":"freeze","ts":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'","repo":"'$(basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null || echo "unknown")'"}'  >> ~/.gstack/analytics/skill-usage.jsonl 2>/dev/null || true

Setup

设置步骤

Ask the user which directory to restrict edits to. Use AskUserQuestion:
  • Question: "Which directory should I restrict edits to? Files outside this path will be blocked from editing."
  • Text input (not multiple choice) — the user types a path.
Once the user provides a directory path:
  1. Resolve it to an absolute path:
bash
FREEZE_DIR=$(cd "<user-provided-path>" 2>/dev/null && pwd)
echo "$FREEZE_DIR"
  1. Ensure trailing slash and save to the freeze state file:
bash
FREEZE_DIR="${FREEZE_DIR%/}/"
STATE_DIR="${CLAUDE_PLUGIN_DATA:-$HOME/.gstack}"
mkdir -p "$STATE_DIR"
echo "$FREEZE_DIR" > "$STATE_DIR/freeze-dir.txt"
echo "Freeze boundary set: $FREEZE_DIR"
Tell the user: "Edits are now restricted to
<path>/
. Any Edit or Write outside this directory will be blocked. To change the boundary, run
/freeze
again. To remove it, run
/unfreeze
or end the session."
询问用户要将编辑限制到哪个目录。使用AskUserQuestion工具:
  • 问题:“我应该将编辑限制到哪个目录?此路径外的文件将被禁止编辑。”
  • 文本输入(非选择题)—— 用户输入路径。
用户提供目录路径后:
  1. 将其解析为绝对路径:
bash
FREEZE_DIR=$(cd "<user-provided-path>" 2>/dev/null && pwd)
echo "$FREEZE_DIR"
  1. 确保路径末尾带有斜杠并保存到冻结状态文件:
bash
FREEZE_DIR="${FREEZE_DIR%/}/"
STATE_DIR="${CLAUDE_PLUGIN_DATA:-$HOME/.gstack}"
mkdir -p "$STATE_DIR"
echo "$FREEZE_DIR" > "$STATE_DIR/freeze-dir.txt"
echo "Freeze boundary set: $FREEZE_DIR"
告知用户:“编辑操作现已限制到
<path>/
。任何在此目录外的编辑或写入操作都会被阻止。如需修改限制范围,请重新运行
/freeze
。如需解除限制,请运行
/unfreeze
或结束当前会话。”

How it works

工作原理

The hook reads
file_path
from the Edit/Write tool input JSON, then checks whether the path starts with the freeze directory. If not, it returns
permissionDecision: "deny"
to block the operation.
The freeze boundary persists for the session via the state file. The hook script reads it on every Edit/Write invocation.
钩子脚本从编辑/写入工具的输入JSON中读取
file_path
,然后检查该路径是否以冻结目录开头。如果不是,则返回
permissionDecision: "deny"
以阻止操作。
冻结边界通过状态文件在会话期间保持有效。钩子脚本会在每次调用编辑/写入工具时读取该文件。

Notes

注意事项

  • The trailing
    /
    on the freeze directory prevents
    /src
    from matching
    /src-old
  • Freeze applies to Edit and Write tools only — Read, Bash, Glob, Grep are unaffected
  • This prevents accidental edits, not a security boundary — Bash commands like
    sed
    can still modify files outside the boundary
  • To deactivate, run
    /unfreeze
    or end the conversation
  • 冻结目录末尾的
    /
    可防止
    /src
    匹配到
    /src-old
  • 冻结仅适用于编辑和写入工具——读取、Bash、Glob、Grep操作不受影响
  • 此功能仅用于防止意外编辑,并非安全边界——诸如
    sed
    之类的Bash命令仍可修改边界外的文件
  • 如需停用,请运行
    /unfreeze
    或结束对话