Courses / Build a Claude Code Verification HarnessProLesson 5 of 75:06

Deny Rules and Hooks That Refuse

Deny rules keep the agent out of secrets and holdout tests, and a PreToolUse hook refuses every route around them.

Transcript

Okay, let's go for you know deny rule. so for example, in your coding agent, you might have set settings.json or settings.local.json kind of setup where you put what are all the bash commands or what are all the comments which is allowed, what are all the comments which is not allowed. So I have some examples of what are all the comments which is denied, like don't read holdout for for Claude. Now I will spin up Claude. So basically, I I I'm using Sonet model again, like it is a very simple process. I usually use Opus 5.5 as default, but in this case, this is very simple thing, and sonat 5.5 itself is enough. Use the read tool to open hold out. so you read it, so I'm I'm directing again, like I'm stressed testing a little bit on whether Claude is able to do that. And Claude says I couldn't open hold out one discount code dot test dot ts. The read call failed because of permission settings deny across holdout directory, kudos that it is able to check the permission and it is able to deny that. So read is refused exactly as it says, and then print it in bash cat basically you you you you you can't read, but you can print it, and the pre-tool use that is the hook which caught it. So in this case, what exactly happened is like your permission which denies only the read and those permission layer will handle. But what if there is a layer which can cat or you know, which can copy and which can paste it. This is oftentimes you will see such examples, even though your .gitignore file or your permission layer doesn't allow reading your environmental variable .env or something like that. But if you haven't written your pre-tool hook, what happens is like sometimes you might say, okay, you can copy some of this environment and put it to your coolify or your your aw AWS you know deployment in a secure way or in your gh cli GitHub CLI and push it as a secret securely, then what happens is like it won't be able to read directly, but it will still be able to print it out if you haven't provided a hook to say you should stop such operation. So that is where pre-tool hooks can easily help. in situations like, for example, you are dealing with PHI or PII, these tool hooks will help you to you know not call anything which is malicious or which will expose your data or things like that. So read about read more about hooks in Claude. It will have again, like it doesn't only have pre-tool and post-tool. There are multiple other hooks which is available as well, which will be very very helpful in terms of controlling the lifecycle of execution. Like when it happens, whether to call it, whether to refuse it, it will decide and do it. So when you are setting up your repository, you can set up with deterministic gates, and you can set up with actual permissions, and you can set up with actual hooks, which is needed for you. Again, whether you need to hand code all these things, it doesn't matter. So you can simply use AI to you know do the research and you can direct AI to say what exactly I want, what are all the things I wanted to avoid, and you can set these process first and then you operate around that process, then you will be able to control what output you are expecting and what output you are getting. Then I say add a test for format sense to test slash cart test dot ts. And then you know it it errored and it says I couldn't add the test, the edit to was denied because the permission setting block right to the test directory that matches cloud.md, which says only SRC is mine to change. Great. so it is able to follow Cloud.md's instructions as well, even without actual enforcement.

This lesson comes with Pro, $149 a year: Get Pro. This lesson is cut from the free Lightning session Build a Claude Code Verification Harness. The Live Labs build the same system with you, free, on Thursdays: see the Live Labs.