Control which Salesforce orgs Claude Code can touch.
A PreToolUse hook that checks every sf command before it runs. Allow deploys in your sandbox, prompt on UAT, and block production.
| Org (by username) | read | validate | deploy | data | delete | execute |
|---|
Instructions in CLAUDE.md can be ignored. A hook runs every time.
Keep CLAUDE.md to explain how you work; use the hook to actually block mistakes.
The model, if it remembers the rule and chooses to follow it.
Claude Code runs the hook before every Bash command without asking the model.
-o
sf project deploy start doesn't mention production anywhere in the text.
Resolves the target org the same way sf does (-o, SF_TARGET_ORG, .sf/config.json, global config) and looks up the username.
Easy for the model to miss inside a shell wrapper or helper script.
Finds sf and sfdx inside bash -c, eval, $(...), npx, env, heredocs, and project scripts you declare.
Nothing stops the agent from modifying instructions.
Blocks edits to .claude/org-policy.json, the hook file, and settings.json.
Install and add a project policy
Needs only the Salesforce CLI and Claude Code. It uses the Node.js bundled with sf, so there is nothing else to install. Until a project has a policy, the agent cannot reach any org from it.
git clone https://github.com/jboxtel/skipper-org-policy-hook
cd skipper-org-policy-hook && sh install.sh
# restart Claude Code, then inside your Salesforce project:
~/.claude/hooks/sf-org-guard --init
~/.claude/hooks/sf-org-guard --set DevSandbox \
read=allow validate=allow deploy=allow data=ask
~/.claude/hooks/sf-org-guard --show
Add rules before you let the agent run sf.
Read the command table and install instructions on GitHub.