Note: phiên bản Tiếng Việt của bài này ở link dưới.
https://duongnt.com/amp-custom-command-vie
I kept a 200-line prompt in a text file and copy-pasted it into Amp whenever needed. After months of this tedium, I finally built a better solution. Custom commands let you turn any prompt into a reusable tool. Here’s how.
The need for reusing prompts
As we all know, an AI Agent is only as useful as the prompts we feed to it. And for complex tasks, the prompt itself can get quite long. As an example, my prompt to perform a System Design Review is around 200 lines, while the only part that changes between usages is the path to the design file. My first approach to this problem was to save that prompt to a text file and update the file path whenever I use it. It worked, but a bit clunky, and I needed to jump between apps, which broke my concentration.
After that, I tried to add the prompt itself into Amp’s rule files, which is called AGENTS.md
or AGENT.md
depending on Amp’s version. Essentially, my rule file looked like this.
Whenever asked to review a System Design File, follow these guidelines.
// 200 lines of prompt go here
Then I can simply tell Amp review the design at <path>
, and it will automatically incorporate the prompt in the rule file when generating the response. This solved the problem of jumping between apps, but it created new ones that were even more troublesome.
- Amp is not guaranteed to use the rule file. It is supposed to, but sometimes it forgets (just like us).
- More importantly, the rule file is loaded on start up. Because of that, the prompt will be stored in the context no matter if we actually use it or not. And the more irrelevant information in the context, the worse Amp’s responses become.
Custom commands solve both issues: they inject prompts on-demand (so Amp never forgets), and only load when actually triggered (keeping the context clean).
Set up custom command for Amp
What is an Amp command
An Amp command is a quick way to perform an action, triggered by typing /
followed by the command name. One command most Amp users are familiar with is /compact
, which is used to compact the current context window once it reaches the limit.
Create our own command
In the following sections, we will look into creating our own command, similar to the /compact
one above. The simplest way to do that is creating a Markdown file in Amp’s commands folder (default at ~/.config/amp/commands
). As an example, we will create a custom command to perform fact check on Amp’s response. Copy this to the commands folder in your machine and restart Amp.
After that, you can trigger that command by typing /fact-check
in Amp CLI.
On pressing Enter, the command will automatically insert the content of fact-check.md
like this.
As an example, below is Amp’s response when I asked it to verify the claim that Kotlin optimizes +
concatenation to StringBuilder.
With the custom command, we can now quickly fact check Amp’s responses whenever needed, without polluting its context. But there’s one inconvenience: we must press Enter twice, once to inject the prompt, once to send it. Let’s fix that.
Executable custom command
As you might know, built-in commands like /compact
we mentioned earlier gets executed immediately when we press Enter. How can we make our command do the same? In this section, we will change our command to be executable. Also, we will make it receive an argument from the terminal, as the statement we want to fact check.
To do that, we need to modify the fact-check.md
file into a bash script like this. As we can see, the prompt stays mostly the same, with the following changes:
- We have the shebang
#!/bin/bash
at the top. - The actual prompt is now wrapped inside a heredoc.
- On line 3, we have
$*
to capture all arguments passed to the script. We need to use$*
because Amp does not respect shell quoting.
We also need to make it executable by running this command: chmod +x ~/.config/amp/commands/fact-check
.
After that, we can use it to fact-check the statement the Earth is flat.
/fact-check "the Earth is flat"
On the first Enter press, the command will expand into a proper prompt, with our statement injected at the correct place.
And Amp will return this response.
Conclusion
Custom commands turn repetitive prompts into reusable tools without polluting Amp’s context. Start with simple commands like fact-checking, then build more sophisticated ones as you identify patterns in your workflow. I had a lot of fun turning Amp into my virtual assistant. Now it’s your turn to build yours.