跟讀練習: How to actually force Claude Code to use the right CLI (don't use CLAUDE.md) - 通過影片學習英語口語
選擇練習模式
每種模式都會開啟全屏練習室。
96 句
如果句子過短或過長,請點選 Edit 進行調整。
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.
同頻道
FOR YOU
推薦影片
本節課程介紹
在本節課程中,您將通過觀看一段關於如何引導 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)的技巧。這種方法可以幫助您加深對英語口語的理解和運用。以下是針對該影片的具體建議:
- 將影片的速度調至適合您的水平,可能一開始可以選慢一點,便於您跟讀。
- 在播放過程中,試著模仿講者的語調和語速,特別是在講解技術概念時,注意每一個術語的發音。
- 暫停影片,在每個重要概念後面進行反覆練習,確保能夠順暢使用這些技術性詞彙。
- 使用字幕來幫助理解複雜的術語,同時嘗試關閉字幕進行自我挑戰。
- 與朋友一起觀看並討論影片內容,嘗試將所學的詞彙應用到實際對話中,這將有助於鞏固您的記憶。
通過這種方法,您不僅能夠提高 英語口語練習 的能力,還能在實際工作中更加自信地運用英語,達到更高的溝通效率。觀看這個影片,跟隨講者的節奏進行 英語影子跟讀,相信您會有顯著的進步!
影片中的語法
說話人最常用的結構,並附上影片中的原話:
| 結構 | 影片中的用法 |
|---|---|
| 現在完成進行時 have/has been + -ing — 以前開始、現在仍在繼續的動作 | I've been turning · I've been having |
| 現在完成時 have/has + 過去分詞 — 過去發生但與現在仍有關聯的事 | I've advocated · I've actually prepared · have prevented |
| 被動語態 be + 過去分詞 — 強調發生了什麼,而不是誰做的 | will be created · is linked · can be enforced |
| 定語從句 who / which + 從句 — 補充說明人或事物 | article which is · hooks, which is |
什麼是跟讀法?
跟讀法 (Shadowing) 是一種有科學依據的語言學習技巧,最初開發用於專業口譯員的培訓,並由多語言者Alexander Arguelles博士普及。這個方法簡單而強大:您在聽英語母語原聲的同時立即大聲重複——就像是一個延遲1-2秒緊跟說話者的影子。與被動聽力或語法練習不同,跟讀法強迫您的大腦和口腔肌肉同時處理並模模擬實的講話模式。研究表明它能顯著提高發音準確性,語調,節奏,連讀,聽力理解和口語流利度——使其成為雅思口語備考和真實英語交流最有效的方法之一。























