How to actually force Claude Code to use the right CLI (don't use CLAUDE.md)

Matt Pocock| 00:06:51|Feb 25, 2026
Chapters5
The speaker discusses how to steer Claude code and claw code to follow a desired CLI workflow, such as preferring PNPM or a wrapper script, and teases a newsletter and course for engineers.

Deterministically steer Claude Code to use the right CLI with hooks, not brittle claw.md hints.

Summary

Matt Pocock walks through a practical pattern to control Claude Code’s CLI usage without cluttering claw.md. He shows how to convert hand-picked CLI rules into deterministic hooks that run before tool calls, ensuring PNPM is used instead of npm (and blocking other commands like git push). The demo uses a pre-tool-use hook that detects npm commands and substitutes PNPM, with a dedicated npm.sh script executed by the hook. Pocock highlights why claw.md is not ideal for global instructions and explains how hooks preserve instruction budgets while enforcing behavior just-in-time. He also demonstrates creating and testing the hooks, updating settings.json with the pre-tool-use configuration, and validating the block-vs-substitute flow in a fresh Claude Code session. Throughout, he emphasizes deterministic control, reusable patterns, and how this approach scales to other coding agents and even ESLint-style policy enforcement. If you’re building reliable, engineer-focused automation around Claude Code, this video offers a concrete, testable path to steer commands without bloating your instruction budget.

Key Takeaways

  • Convert CLI steering rules into deterministic Claude code hooks using the pre-tool-use event.
  • Use separate bash scripts (e.g., npm.sh) executed by hooks to enforce command substitutions like PNPM over npm.
  • Update project settings.json with a hooks.pre-tool-use block to apply rules only to matching bash tools.
  • Block undesirable commands (e.g., npm or git push) in a deterministic manner rather than via global claw.md constraints.
  • Test the hooks in a fresh Claude Code session to confirm the behavior (e.g., npm install triggers PNPM).
  • Provide a just-in-time enforcement approach that keeps claw.md free of global, noisy instructions and preserves the LLM’s instruction budget.
  • Leverage this pattern to enforce other rules (e.g., style checks or disallowing destructive commands) across different coding agents.

Who Is This For?

Engineers and developers who use Claude Code and want reliable, deterministic CLI control without cluttering claw.md. Ideal for teams building repeatable automation and policy enforcement in AI-assisted workflows.

Notable Quotes

"The way to do this is via clawed code hooks."
Introducing the core technique to deterministically steer tool calls.
"The pre-tool use hook can block it before a tool call executes and steer to the right command."
Explains which hook point enforces CLI substitution.
"blocked use PNPM, not npm."
An example of the hook’s practical output in action.
"We have prevented one command and we’ve automatically steered it to use another command."
Summarizes the success of the hook-based approach.

Questions This Video Answers

  • how do I force Claude Code to use a specific CLI command
  • what are Claude code hooks and how do they work
  • how to create deterministic hooks for Claude Code
  • how to block npm while using PNPM in Claude Code
  • can I apply Claude Code hooks to enforce other policies like disallowing git push
Claude Codeclaw.mdClaude code hookspre-tool-usePNPM vs npmnpm.shsettings.jsondeterministic hooksCLI enforcementgit push blocker
Full Transcript
One of the most common questions I get about agents and about claw code is how do I force it to use the right CLI command? How do I force it to adopt my workflow instead of the workflow that it knows best? For instance, how do I get it to use uh PNPM instead of npm? How do I get it to call this wrapper script that we wrote instead of calling the thing directly with npx? How do I prevent it from using certain commands and only allow it to use other commands? If you're interested in these kind of questions, this is the stuff that I answer on my newsletter. And I'm working on a Claude code course right now for real engineers, not vibe coders. So, if you dig that stuff, the link is down below. The first thing that you probably think about when you think about steering Claude in one direction, but not another, is to put information in a clawed MD file. In other words, to proactively tell it to use PNPM, not npm. Now, this will be pretty effective most of the time, especially if like this you have a claw.md file that is nearly empty apart from that one instruction. However, in various places, including in the previous video I just posted, I've advocated almost always deleting your claw.md because if you think about it, this instruction here is only relevant for certain tasks. And putting it in claw.md makes it global for every action that you're going to do in the repo. LLMs have an instruction budget that you can really only put about 500 instructions in before it starts getting less and less powerful and more and more confused. And we want our LLM thinking about the complicated plans and the implementation that it's going to put together, not having irrelevant instructions about using npm or PNPM. And the final thing that makes me uncomfortable about this is the fact that it's not a deterministic way of preventing a command. For instance, we may want to disallow it from running destructive commands. for instance, we never want it to get pushed. These kind of negative instructions to the LLM are really bad, I think, because they burn instruction budget in something that we're not actually using the instruction budget to prevent deterministically. By adding this, we're reducing our chances of running git push or reducing our chances of running npm, but we're not preventing it. So, instead, I'm going to show you an approach that prevents it deterministically and guides the LLM towards the correct solution. The way to do this is via clawed code hooks. Hooks allow you to run deterministic code at certain points during claw code's execution cycle. When one of these events fire, all matching hooks run in parallel. So for instance, you can run a hook when the session starts. You can run a hook when a permission dialogue appears to automatically approve things. The one that we're interested in is pre-tool use before a tool call executes can block it. Our plan here is to use this pre-tool use hook to before it calls uh npm to use PNPM instead. And the cool thing about this is that Claude code already knows how to do this. And I've actually prepared a prompt inside this file to take the claw.md, turn it into deterministic hooks, and then put those hooks into your project. Here's what it looks like. Take the instructions in your claw.md file, turn them into deterministic claude code hooks in this project directory. Not all the instructions will be deterministic. Only do the ones you can, such as instruction to use one CLI command over another or disallowing certain CLI commands. use separate bash scripts for running the hooks. In other words, this is its own.sh file and it gives some syntax here for how to construct that. This is directly lifted from the claude code docs. And then finally below here, first confirm with the user which hooks will be created. Second, implement the hooks. Third, provide the user with instructions on how to test the newly created hooks. I'll include this in an article which is linked below for you. So, I'm going to copy and paste this. I'm going to go into a fresh clawed code session here. I'm going to zoom up the terminal a bit. I'm going to paste it in and see what happens. All right, it's given me two options here. It says there are two rules that can be enforced deterministically. Block npm commands or block git push. Now, I've actually already got some git push blockers in my global setup. So, I'm just going to say, yeah, do the npm one only. So, that sounds good. Let's run this and see what happens. So, it's now given us something to review. It's given us a nice version of the bash command that we saw earlier, except it just checks if it's npm. Crucially, it's checking if the command starts with npm as a command. It echoes use PNPM, not npm. And then it exits with an exit code of two. So that is looking good to me. Let's accept that. It's then going to make it ex uh executable by running chimod plus x. So I'm happy with that. It's then created the configuration inside settings.json here where we've got now hooks which is um you know a property on the settings pre-tool use which is the one we saw earlier. It's mashing matching any bash tools here. And then when it matches any bash tool, it runs this command block npm.sh. So that looks good to me. We're in a good spot. And it's now appearing to verify that the hook works in line. I'm just going to try and run this to see what happens. And you can see here just up there, it said blocked use PNPM, not npm. So we're definitely getting somewhere. And finally, it's given us some instructions here to test it. to restart claw code in this project. Try asking it to run something like npm install fu. All right, the first thing I'm going to do is actually remove the instruction from claw.md here. And then we're going to pull open a fresh clawed code instance and we're going to say npm install let's say react query. Okay, let's give it something kind of juicy. And we can see that the pre-tool use here it said bash hook error blocked. Use pnpm not npm. And now it's running pnpm install tenstack react query instead. So that's it. We have prevented one command and we've automatically steered it to use another command. And crucially, we've managed to kill an instruction inside our global claw.md file. This is what I love so much about this approach. You get to take instructions out of your instruction budget and enforce them deterministically. This means that the instructions that we have in claude.md, they are available just in time. They get to hover in the background until Claude actually progressively kind of discovers them. And this idea of these rules just being enforced just in time. You can take this and apply it to lots of different things. For instance, I've been turning my style rules, like I really hate positional parameters in functions and turning them into ESLint rules so that I can lint Claude into the right thing without needing to warn it or instruct it. So creating these feedback loops for Claude is so so powerful. Now, if you dig this, then this and all of my ideas are going to be in my newsletter so you never miss a trick. and the link for that is below if you want to click it and sign up. But thank you so much for watching. I've been having a blast making these videos and discovering lots of new ideas about Claude. What else do you think you can do with hooks? What else do you want to see me cover with Claude code? And now, of course, Claude is not the be all and end all, right? Like I'm pretty keen to try out other coding agents, too. And the hooks idea is not exclusive to Claude, too. So, you can take this knowledge and probably take it to Codeex or whatever you're using. But anyway, that's enough rambling. Uh, thanks for watching and I will see you in the next

Get daily recaps from
Matt Pocock

AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.