Claude Code hook

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.

.claude/org-policy.json · click any rule to toggle
Org (by username) read validate deploy data delete execute
Orgs are keyed by username, so changing an alias won't widen access. Fails closed
PreToolUse · sf-org-guard --check Default org: Production
$
    Why use a hook

    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.

    Case CLAUDE.md rule Skipper org policy hook
    Who enforces it

    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.

    Commands without -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.

    Wrapped commands

    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.

    Editing the rules

    Nothing stops the agent from modifying instructions.

    Blocks edits to .claude/org-policy.json, the hook file, and settings.json.

    Install

    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.

    Install globally & configure a project
    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.

    Get it on GitHub All Skipper products