跟读练习: How to actually force Claude Code to use the right CLI (don't use CLAUDE.md) - 通过视频学习英语口语

正在创建课程...
1
One of the most common questions I get about agents
2
and about claw code is how do I force it to use the right CLI command?
3
How do I force it to adopt my workflow instead of the workflow that it knows best?
4
For instance, how do I get it to use PNPM instead of NPM?
5
How do I get it to call this wrapper script that we wrote instead of calling the thing directly with NPX?
6
How do I prevent it from using certain commands and only allow it to use other commands?
7
If you're interested in these kind of questions, this is the stuff that I answer on my newsletter.
8
I'm working on a Claude code course right now for real engineers, not Vibecoders.
9
So if you dig that stuff, the link is down below.
10
The first thing that you probably think about
11
when you think about steering Claude in one direction but not another is to put information in a Claude.md file.
12
In other words, to proactively tell it to use PNPM, not NPM.
13
Now, this will be pretty effective most of the time, especially if like this, you have a Claude.md file that is nearly empty apart from that one instruction.
14
However, in various places, including in the previous video I just posted, I've advocated almost always deleting your claw.md.
15
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.
16
LLMs have an instruction budget
17
that you can really only put about 500 instructions in before it starts getting less
18
and less powerful and more and more confused.
19
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.
20
And the final thing that makes me uncomfortable about this is the fact
21
that it's not a deterministic way of preventing a command.
22
For instance, we may want to disallow it from running destructive commands.
23
For instance, we never want it to git push.
24
These kind of negative instructions to the LLM are really bad,
25
I think, because they burn instruction budget in something that we're not actually using the instruction budget to prevent deterministically.
26
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.
27
So instead, I'm going to show you an approach that prevents it deterministically and guides the LLM towards the correct solution.
28
The way to do this is via Claude Code hooks.
29
Hooks allow you to run deterministic code at certain points during Claude Code's execution cycle.
30
When one of these events fire, all matching hooks run in parallel.
31
So for instance, you can run a hook when the session starts.
32
You can run a hook when a permission dialogue appears to automatically approve things.
33
The one that we're interested in is pre-tool use before a tool call executes can block it.
34
Our plan here is to use this pretool use hook to before it calls npm to use pnpm instead.
35
And the cool thing about this is that Claude code already knows how to do this.
36
And I've actually prepared a prompt inside this file to take the Claude.md, turn it into deterministic hooks, and then put those hooks into your project.
37
Here's what it looks like.
38
Take the instructions in your Claude.md file, turn them into deterministic Claude code hooks in this project directory.
39
Not Once all the instructions will be deterministic, only do the ones you can, such as instructions to use one CLI command over another or disallowing certain CLI commands.
40
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.
41
This is directly lifted from the Claude code docs.
42
And then finally below here, first confirm with the user which hooks will be created,
43
second implement the hooks, third provide the user with instructions on how to test the newly created hooks.
44
I'll include this in an article which is linked below for you.
45
So I'm going to copy and paste this, I'm going to go into a fresh Claude Code session here, I'm going to zoom up the terminal a bit, I'm going to paste it in and see what happens.
46
Alright, it's given me two options here.
47
It says there are two rules that can be enforced deterministically, block NPM commands or block git push.
48
Now I've actually it already got some git push blockers in my global setup so I'm just going to say, yeah, do the npm one only.
49
So that sounds good.
50
Let's run this and see what happens.
51
So it's now given us something to review.
52
It's given us a nice version of the bash command that we saw earlier, except it just checks if it's npm.
53
Crucially it's checking if the command starts with npm as a command.
54
It echoes use pnpm not npm and then it exits with an exit code of 2.
55
So that is looking good to me.
56
Let's accept that.
57
It's then going to make it executable by running chmod plus x, so I'm happy with that.
58
It's then created the configuration inside settings.json here, where we've got now hooks, which is a property on the settings, pretool use, which is the one we saw earlier.
59
It's matching any bash tools here.
60
And then when it matches any bash tool, it runs this command, block npm.sh.
61
So that looks good to me.
62
We're in a good spot.
63
And it's now appearing to verify that the hook works in line.
64
I'm just going to try and run this to see what happens.
65
And you can see here just up there it said blocked use PNPM not NPM.
66
So we're definitely getting somewhere.
67
And finally it's given us some instructions here to test it.
68
To restart claw code in this project try asking it to run something like NPM install foo.
69
Alright the first thing I'm going to do is actually remove the instruction from claw.md here.
70
And then we're going to pull open a fresh clawed code instance
71
and we're going to say npm install let's say React query.
72
Okay, let's give it something kind of juicy.
73
And we can see that the pre-tooled use here,
74
it said bash hook error blocked use pnpm not npm and now it's running pnpm install tanstat react query instead.
75
So that's it.
76
We have prevented one command and we've automatically steered it to use another command.
77
And crucially we've managed to kill an instruction inside our global clawed.md file.
78
This is what I love so much about this approach.
79
You get to take instructions out of your instruction budget and enforce them deterministically.
80
This means that the instructions that we have in clawed.md, they are available just in time.
81
They get to hover in the background until clawed actually progressively kind of discovers them.
82
And this idea of these rules just being enforced just in time, you can take this and apply it to lots of different things.
83
For instance, I've been turning my style rules, like I really hate positional parameters in functions, and turning them into ESLint rules so
84
that I can lint Claude into the right thing without needing to warn it or instruct it.
85
So creating these feedback loops for Claude is so, so powerful.
86
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.
87
And the link for that is below if you want to click it and sign up.
88
But thank you so much for watching.
89
I've been having a blast making these videos and discovering lots of new ideas about Clawed.
90
What else do you think you can do with Hooks?
91
What else do you want to see me cover with Clawed Code?
92
And now of course Clawed is not the be all and end all, right?
93
Like I'm pretty keen to try out other coding agents too.
94
And the Hooks idea is not exclusive to Clawed too, so you can take this knowledge and probably take it to Codex or whatever you're using.
95
But anyway, that's enough rambling.
96
Thanks for watching and I'll see you in the next one.

本节课程介绍

在本节课程中,您将通过观看一段关于如何引导 Claude Code 使用正确的命令行工具(CLI)的视频来练习英语口语。这段视频将向您展示如何使用条件钩子(hooks)来控制命令的执行,确保在开发工作流中采用您所希望的工具。通过这次练习,您将提高您的英语理解力,同时增强使用技术性语言的能力。

关键词汇与短语

  • 命令行工具 (CLI) - Command Line Interface
  • 钩子 (hooks) - Mechanisms to intercept certain functions
  • 指令预算 (instruction budget) - Limit on the number of instructions
  • 阻止 (block) - Prevent something from happening
  • 会话 (session) - A period of interaction between a user and a system
  • 包装脚本 (wrapper script) - A program that encases another program
  • 影子跟读 (shadowing) - Technique for language practice
  • 确定性 (deterministic) - Ensuring consistent outcomes

练习技巧

在观看视频时,建议您使用 英语影子跟读(shadowspeak)的技巧。这种方法可以帮助您加深对英语口语的理解和运用。以下是针对该视频的具体建议:

  • 将视频的速度调至适合您的水平,可能一开始可以选慢一点,便于您跟读。
  • 在播放过程中,试着模仿讲者的语调和语速,特别是在讲解技术概念时,注意每一个术语的发音。
  • 暂停视频,在每个重要概念后面进行反复练习,确保能够顺畅使用这些技术性词汇。
  • 使用字幕来帮助理解复杂的术语,同时尝试关闭字幕进行自我挑战。
  • 与朋友一起观看并讨论视频内容,尝试将所学的词汇应用到实际对话中,这将有助于巩固您的记忆。

通过这种方法,您不仅能够提高 英语口语练习 的能力,还能在实际工作中更加自信地运用英语,达到更高的沟通效率。观看这个视频,跟随讲者的节奏进行 英语影子跟读,相信您会有显著的进步!

什么是跟读法?

跟读法 (Shadowing) 是一种有科学依据的语言学习技巧,最初开发用于专业口译员的培训,并由多语言者Alexander Arguelles博士普及。这个方法简单而强大:您在听英语母语原声的同时立即大声重复——就像是一个延迟1-2秒紧跟说话者的影子。与被动听力或语法练习不同,跟读法强迫您的大脑和口腔肌肉同时处理并模仿真实的讲话模式。研究表明它能显着提高发音准确性,语调,节奏,连读,听力理解和口语流利度——使其成为雅思口语备考和真实英语交流最有效的方法之一。