Hook
Block Global Installs
A Claude Code hook that refuses global npm, pnpm, yarn, pip and gem installs so tools are added to the project and not to your whole machine.
1node -e "let d='';process.stdin.on('data',x=>d+=x).on('end',()=>{let j={};try{j=JSON.parse(d)}catch(e){return}const i=j.tool_input||{};const c=String(i.command||'').replace(/\x22[^\x22]*\x22|\x27[^\x27]*\x27/g,' ')+' ';const e=process.env.VIRTUAL_ENV;const rules=[[/(^|[ ])npm[ ]+(i|install|add)[ ].*(-g|--global)[ ]/.test(c),'npm install -g'],[/pnpm[ ]+(add|install|i)[ ].*(-g|--global)[ ]/.test(c),'pnpm add -g'],[/yarn[ ]+global[ ]/.test(c),'yarn global'],[/gem[ ]+install[ ]/.test(c)&&!/--user-install|--install-dir|bundle/.test(c),'gem install'],[/pip3?[ ]+install[ ]/.test(c)&&!e&&!/venv|--target|[ ]-t[ ]/.test(c),'pip install outside a virtual environment']];const h=rules.find(r=>r[0]);if(h){console.error('Blocked: '+h[1]+' would change the whole machine. Install the tool in the project instead (devDependencies, a virtualenv, or the Gemfile) and run it through npx, python -m or bundle exec.');process.exitCode=2}})"
Claude Code
Block Global Installs
HookDevOps and cloud
Free