How to Efficiently Prompt Claude Code

How to Efficiently Prompt Claude Code

如何高效地向 Claude Code 发送提示词

In this article, I’ll discuss how to prompt your coding agents effectively. 在本文中,我将探讨如何有效地向你的编程智能体(coding agents)发送提示词。

Prompt engineering was a very hot topic a few years ago. This is where you would tweak your prompt, even just a bit — for example, the format of your prompt, what the last sentence of your prompt is, and so on. You could achieve vastly different results with LLMs. 几年前,“提示词工程”(Prompt engineering)是一个非常热门的话题。当时,你只需对提示词进行微调——例如调整格式、修改最后一句措辞等——就能让大语言模型(LLM)产生截然不同的结果。

However, in the years since, the LLMs have become a lot stronger and smarter, and are now much less likely to change outputs just based on the format or text order or similar things in the prompt. 然而,几年过去了,大语言模型变得更加强大和智能,现在它们不太可能仅仅因为提示词的格式、文本顺序或类似因素而改变输出结果。

However, prompting is still very important, and the knowledge on how to effectively prompt LLMs is still incredibly important. It just requires a different skill set and a different way of thinking to effectively prompt agents nowadays. 尽管如此,提示词依然非常重要,掌握如何高效地向大语言模型发送提示词的知识依然至关重要。只是在当今时代,想要高效地引导智能体,需要一套不同的技能和思维方式。

It’s worth noting that, likely, in the next year or two, the way you prompt your agents will have evolved further, and you just have to keep track of all the changes happening to the models in order to know how to prompt them effectively and get the best results out of the models. 值得注意的是,在未来一两年内,你引导智能体的方式很可能会进一步演变。你必须持续关注模型的所有变化,才能知道如何有效地进行提示,并从模型中获得最佳结果。

In this article, I’ll discuss how I prompt the LLMs I’m working with to make them effectively perform a lot of work, and I’ll essentially discuss my workflow to get engineering tasks done. 在本文中,我将讨论我如何向我所使用的模型发送提示词,以促使它们高效地完成大量工作,并分享我完成工程任务的工作流程。

Why optimize the way you prompt

为什么要优化提示词方式

First of all, you might think that the way you write prompts doesn’t really matter that much anymore because the LLMs have become so strong that they can understand you anyway. To a certain extent, I agree with this way of thought. However, there are still good and bad ways to prompt models. 首先,你可能认为编写提示词的方式已经不再那么重要了,因为大语言模型已经足够强大,无论如何都能理解你的意图。在某种程度上,我同意这种观点。然而,提示模型的方式依然有好坏之分。

For example, a good prompt would be: Be explicit about what you want; Include how to test the implementation; Clarify any ambiguities. While a bad prompt would, for example be: Be vague; Make assumptions that don’t fit with the existing codebase. 例如,好的提示词应该是:明确你的需求;包含如何测试实现方案;澄清任何歧义。而糟糕的提示词则是:含糊不清;做出与现有代码库不符的假设。

Furthermore, prompting is not just a singular thing you do for a specific thread. Prompting is also the science of iteratively working with the model to make a plan to implement the feature, for example. So, a good prompt could also include stuff like asking the model to discover any ambiguities and discuss them with you. Or telling the model which assumptions to make. 此外,提示不仅仅是针对特定对话线程的一次性操作。提示也是一种与模型进行迭代协作的科学,例如共同制定功能实现计划。因此,一个好的提示词还可以包括要求模型发现潜在歧义并与你讨论,或者明确告知模型应基于哪些假设进行工作。

How I prompt Claude Code

我如何向 Claude Code 发送提示词

Now I’ll move on to how I prompt Claude Code specifically. I’ll talk you through a few of the techniques that I use to prompt effectively and get the most out of Claude Code, though these techniques are very general and also apply to all other coding agents, basically, such as Codex as well. 现在,我将具体谈谈我如何向 Claude Code 发送提示词。我将介绍几种我用来高效提示并充分利用 Claude Code 的技巧,尽管这些技巧非常通用,基本上也适用于所有其他编程智能体(如 Codex)。

Transcription

语音转录

The first topic I’d like to cover is that I use a transcription tool to get all my thoughts into the coding agents. Currently, I’m using a transcription tool called FluidVoice, which is a model you can run locally for free that is incredibly good, both fast and accurate for transcribing English text. 我要讨论的第一个话题是,我使用语音转录工具将我的想法输入给编程智能体。目前,我使用的是一款名为 FluidVoice 的转录工具,这是一个可以免费在本地运行的模型,它非常出色,在转录英语文本时既快速又准确。

Now, the transcription tools are obviously very valuable because they’re faster than typing by hand. Of course, how much faster depends on how fast you can actually type by hand, but it’s fair to assume that you can talk, on average, two to three times faster than you can type on your computer. And of course you get the benefit of not straining your hands and not having to focus on the typing. 显然,转录工具非常有价值,因为它们比手动打字快得多。当然,具体快多少取决于你的打字速度,但可以肯定的是,平均而言,你说话的速度比在电脑上打字的速度快两到三倍。此外,你还能避免手部疲劳,无需将精力集中在打字上。

However, another benefit I’ve noticed is that I’m more willing to include all the context that my coding agent needs to perform a task. When I had to type everything by hand, there would be times when I didn’t want to write out all the context, simply because it took a lot of time to type. This is, of course, very bad because if you don’t give Claude Code the context it needs to solve a task, it’s very hard for it to actually solve that task. 然而,我注意到的另一个好处是,我更愿意提供编程智能体执行任务所需的所有上下文。当我必须手动输入所有内容时,有时我不想写出完整的上下文,仅仅是因为打字太耗时了。这当然非常糟糕,因为如果你不给 Claude Code 提供解决任务所需的上下文,它就很难真正完成任务。

However, now that I transcribe instead of type, it’s way easier for me to actually include all the context that I need to include, and it’s very low effort as well. So all in all, transcription tools are very good because they save you a lot of time, and it makes it easier for you to include all the context you actually need to provide the coding agent for it to perform the task effectively. 现在,我改用语音转录代替打字,包含我需要的所有上下文变得容易多了,而且非常省力。总而言之,转录工具非常棒,因为它们节省了大量时间,并让你更容易提供编程智能体有效执行任务所需的全部上下文。

Telling the model how to test

告知模型如何测试

Another very important point is telling the model how to test. So let’s say you tell the model to implement feature A. This is of course great. You tell it what the feature includes; you should include why you want to build this feature. You should include any context around the feature, how the feature ties into other parts of your application, and so on. 另一个非常重要的点是告诉模型如何进行测试。假设你让模型实现功能 A,这当然很好。你告诉它该功能包含什么;你应该说明为什么要构建此功能;你应该包含与该功能相关的任何上下文,以及该功能如何与应用程序的其他部分关联等等。

However, you also need to tell the model how to test the feature. For example, if you implement a chat feature into your application, you should tell the model that it should open the chat in Chrome, type in a query itself, and ensure that the AI responds properly and that the tokens stream in, for example. Essentially, you need to tell the model how it can know that it implemented the feature correctly. 然而,你还需要告诉模型如何测试该功能。例如,如果你在应用程序中实现了聊天功能,你应该告诉模型,它应该在 Chrome 中打开聊天窗口,自己输入查询,并确保 AI 能正确响应且 Token 能正常流式传输。本质上,你需要告诉模型它如何判断自己是否正确实现了该功能。

Doing this will save you a lot of time because you don’t have to test the feature as much yourself, and the model will present you with a more working feature right away. 这样做会为你节省大量时间,因为你不需要自己进行过多的测试,模型会直接为你呈现一个功能更完善的实现。

Having a discussion with the model

与模型进行讨论

A common misconception when it comes to prompting coding agents is that you just provide them a singular prompt and fire it off, and then you let them work until they’re done. If you have the perfect prompt setup, this is possible because the agents are very capable of working for many hours and getting a lot of work done. However, this doesn’t take into account how to build the perfect prompt. For a human, it’s basically impossible. 关于提示编程智能体,一个常见的误区是:你只需提供一个单一的提示词并发送,然后让它们一直工作直到完成。如果你有完美的提示词设置,这确实可行,因为智能体非常有能力连续工作数小时并完成大量任务。然而,这忽略了如何构建“完美提示词”的难度。对于人类来说,这基本上是不可能的。