scope-locker
v0.1.1
Published
PreToolUse hook that enforces filesystem permissions per project
Downloads
161
Readme
scope-lock
PreToolUse hook for Claude Code that enforces filesystem permissions per project. Define which files the agent can read and write in a manifest — everything else is denied.
Install
npm install -g scope-lockSetup
- Create
.scope-lock.jsonin your project root:
{
"allow": {
"read": ["src/**", "package.json", "README.md", "tsconfig.json", "*.config.*"],
"write": ["src/**"]
},
"deny": [".env*", "node_modules/**", ".git/**", "**/secrets/**"]
}- Add to
~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Read|Write|Edit|Glob|Grep|Bash",
"hooks": [
{
"type": "command",
"command": "scope-lock",
"timeout": 5
}
]
}
]
}
}How It Works
- Claude wants to call a tool (Read, Write, Edit, Bash, etc.)
- The hook intercepts the call and extracts file paths from the tool input
- Paths are matched against your manifest's allow/deny rules
- Deny rules take precedence over allow rules
- Paths matching no rule are denied by default
- Exit 0 = allow, Exit 2 = deny with reason
Manifest Format
Supports both .scope-lock.json and .scope-lock.yaml:
JSON:
{
"allow": {
"read": ["src/**", "docs/**", "*.md"],
"write": ["src/**"]
},
"deny": [".env*", ".git/**", "node_modules/**"]
}YAML:
allow:
read:
- src/**
- docs/**
- "*.md"
write:
- src/**
deny:
- .env*
- .git/**
- node_modules/**Glob Patterns
*— matches any characters except/**— matches any characters including/(recursive)?— matches a single character.env*— matches.env,.env.local,.env.productionsrc/**— matches everything undersrc/
Tool Path Extraction
| Tool | Path Source |
|------|------------|
| Read, Write, Edit | tool_input.file_path |
| Glob | tool_input.path (default: .) |
| Grep | tool_input.path (default: .) |
| Bash | Best-effort regex extraction from command |
Requirements
- Node.js >= 22
- ESM only
License
MIT
