
file-protection
Warns on large files and large reads
- version
- 1.7.3
Install
/plugin install file-protection@claude-hooksRun it inside Claude Code after adding the marketplace with /plugin marketplace add steeef/claude-hooks.
Contents
Discovered from sourceAgents 1
file-protection
File protection hooks for Claude Code that guard against accidental overwrites and encourage modular code.
Hooks
PreToolUse: file_hook.py
Unified entry point that runs all file protection checks:
- worktree_check - Deny-then-ask speed bump for edits outside a git worktree
- file_length_check - Warns when files exceed 10000 lines
Worktree Edit Guard
Two-phase speed bump for edits outside a git worktree:
- First edit → deny (agent sees error + guidance to use
EnterWorktree) - Second edit (same session) → ask (user is prompted to approve or switch)
- Cycle resets after the ask step
Flag validity is tied to the session_id from the hook's JSON stdin payload:
- A new session sees any existing flag as stale and re-denies
- Missing
session_idgracefully allows the edit (speed bump, not security gate)
Edits inside a worktree or outside a git repo are always allowed.
Headless sessions (claude -p / SDK, where CLAUDE_CODE_ENTRYPOINT starts with
sdk) skip the speed bump entirely — there's no human to answer the ask, so the
edit is allowed. Interactive terminals, IDEs, and Task-tool subagents keep the guard.
File Length Limits
Uses a "speed bump" pattern:
- First attempt to write >10000 lines is blocked with a warning
- A flag file is created
- Second attempt proceeds (user has acknowledged the warning)
- Flag is cleared after use
Configuration
No configuration required. The hooks are automatically loaded by Claude Code
when CLAUDE_HOOKS_DIR points to the parent claude-hooks directory.
Hooks 1
Sponsors
Details
- Marketplace
- steeef/claude-hooks
- Source
- plugins/file-protection
- Category
- Security