Skip to content

hookCode quality

Block Vendor Edits

A Claude Code hook that denies edits to files inside node_modules, vendor and dist folders, so fixes go to your own source and not copies.

npx workspacetemplates add block-vendor-edits --tool claude-code

Writes 1 file to .claude/

.claude/settings.jsonmerge into your file16 lines · 786 BFile
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"process.on('uncaughtException',()=>process.exit(0));let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{let j={};try{j=JSON.parse(d)||{}}catch(e){process.exit(0)}const i=j.tool_input||{};const f=String(i.file_path||'');const fs=require('fs');const p=f.split(String.fromCharCode(92)).join('/');const m=p.match(new RegExp('(^|/)(node_modules|vendor|dist)/'));if(m){console.error('Blocked: '+f+' is inside '+m[2]+'. Edit the source files or the package version instead, never the installed or built copy.');process.exit(2)}process.exit(0)})\"",
            "timeout": 10
          }
        ]
      }
    ]
  }
}

What it does

Changes made inside an installed package or a build folder disappear on the next install or build. This PreToolUse hook checks the path of each Edit or Write and refuses it when a folder named node_modules, vendor or dist is part of it.

The error text points the agent back at your own sources. Windows and Unix paths are both handled.

Example

you › The date parsing bug is in node_modules/dayjs, fix it there.

agent › The edit is refused. The agent proposes a version bump, a patch file or a wrapper in your own code.

Questions

Does it block reading those folders?
No. It only watches Edit and Write, so the agent can still read dependency code to understand a bug.
What about a build folder with another name?
Only node_modules, vendor and dist are matched. Add more names inside the pattern in the command for others.
  • Block Generated File Edits

    HookCode quality

    Free
  • Block Large Writes

    HookCode quality

    Free
  • Ensure Final Newline

    HookCode quality

    Free
  • Format After Edit

    HookCode quality

    Free