Bắt đầu ngayBắt đầu miễn phí

Redact instead of block

Blocking a dangerous call is the obvious move. The more interesting one is rewriting it.

What follows is an alternative to the one you just built. A teammate ran a curl against the orders API with a live key pasted straight into the command, and it landed in the shell logs. You want commands like that to keep working, just without the key sitting in them.

A PreToolUse hook can return updatedInput to rewrite a call instead of refusing it. A fresh skeleton is waiting at hooks/redact-secrets.js: it already reads the tool call and spots the key, but it returns nothing. Your .claude/settings.json starts empty here, so you will wire this one up from scratch.

Bài tập này là một phần của khóa học

Claude Code in Action

Xem khóa học

Hướng dẫn bài tập

  • Start Claude Code with claude.
  • Ask Claude to finish the skeleton at hooks/redact-secrets.js so it masks the key with updatedInput and lets the command run, echoing back the fields it isn't changing.
  • Ask Claude to wire that script into .claude/settings.json as a PreToolUse hook matching Bash.
  • Type /exit to exit Claude Code.

Bài tập tương tác thực hành

Biến lý thuyết thành hành động với một trong các bài tập tương tác của chúng tôi

Bắt đầu bài tập