Hook
Block Generated File Edits
A Claude Code hook that refuses edits to files whose first lines say they are generated, so the agent changes the source and not the output.
1node -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');if(!f||!fs.existsSync(f))process.exit(0);let h='';try{h=fs.readFileSync(f,'utf8').slice(0,1500)}catch(e){process.exit(0)}const m=h.split('\n').slice(0,10).join('\n').match(/@generated|do not edit|auto-?generated|code generated|generated by|this file is generated/i);if(m){console.error('Blocked: '+f+' is marked as generated ('+m[0]+'). Change the source or the generator and regenerate it instead of editing the output.');process.exit(2)}process.exit(0)})"
Claude Code
Block Generated File Edits
HookCode quality
Free