A plugin for Claude Code that protects external folders from modifications while allowing read access.
Why? When working on a project, you may need Claude to reference code from other folders (libraries, boilerplates, other projects) without accidentally modifying them. This plugin adds read-only protection to any folder you specify. You can manage restrictions by project, or globally.
How it works:
- Installs a PreToolUse hook that intercepts Bash commands before execution
- Adds slash commands (
/add-readonly,/remove-readonly,/list-readonly) to manage protected folders - Stores configuration in
~/.claude/settings.jsonalongside your other Claude Code settings - Supports per-project folders (only accessible from a specific project) and global folders (accessible from all projects)
- Cross-platform: Works on Linux, macOS, and Windows
- No dependencies: Uses only Node.js (included with Claude Code)
- Per-project configuration: Each project can have its own list of read-only folders
- Global folders: Share read-only folders across all projects
- Bash protection: Blocks dangerous commands (rm, mv, cp, touch, etc.)
- Edit/Write protection: Blocks Claude's Edit and Write tools
- Safe commands allowed: ls, cat, grep, find, head, tail, etc.
curl -fsSL https://raw.githubusercontent.com/PublikoFR/Claude-Code-ReadOnly/main/install.js | nodegit clone https://github.com/PublikoFR/Claude-Code-ReadOnly.git
cd claude-code-readonly
node install.js
# You can delete the folder after installationIf you prefer not to run any scripts:
-
Copy the hook to
~/.claude/hooks/:cp hooks/protect-readonly.js ~/.claude/hooks/ -
Copy the commands to
~/.claude/commands/:cp commands/*.md ~/.claude/commands/
-
Add the hook to
~/.claude/settings.jsonin thehookssection:{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "node ~/.claude/hooks/protect-readonly.js", "timeout": 5 } ] } ] } } -
Add readonlyFolders to
~/.claude/settings.json:{ "readonlyFolders": { "projects": {}, "global": [] } }
- Claude Code CLI (includes Node.js)
No external dependencies required.
/add-readonly /path/to/folder
/add-readonly /path/to/folder --global
/list-readonly
/remove-readonly /path/to/folder
Configuration is stored in ~/.claude/settings.json under the readonlyFolders key:
{
"hooks": { ... },
"permissions": { ... },
"readonlyFolders": {
"projects": {
"/home/user/project-a": [
"/home/user/shared-lib"
],
"/home/user/project-b": [
"/home/user/another-lib"
]
},
"global": [
"/home/user/always-readonly"
]
}
}- PreToolUse Hook: Intercepts every Bash command before execution
- Project Detection: Uses current working directory to identify the project
- Path Matching: Checks if the command targets a protected folder
- Command Classification: Allows read commands, blocks write commands
rm,mv,cp,touch,mkdir,rmdirecho >,cat >,tee,sed -ichmod,chown,truncate,ddgit checkout,git reset,git clean,git rm- Any command with
>or>>redirection
ls,cat,head,tailgrep,rg,grepai,findfile,wc,diff,stat,dutree,bat,less,more
MIT