DEV Community

printfapps
printfapps

Posted on

Let your AI agent save the scripts it writes in cmdbook

Your AI agent just wrote you a useful script. It ran, it worked, and now it's in the chat history.

How do you use it again?

Next week you scroll back through old chats to find it. Or you ask again and get a slightly different script, with different flags, and check it all over again. Or you copy it into a .sh file, and then you're back to finding the file and editing it, like every other part of this series.

The agent already knows how to run commands. So let it save the script too, somewhere you can run it without the agent.

With cmdbook, the agent saves the script as a command, runs it, and reads the output. You get the same command as a button with a form.

AI use CLI to create command

Here's how

1. Ask your agent. I used opencode, which can run terminal commands. The prompt, shortened:

Use the cmdbook CLI to save a command named "Recently changed files" under folder "Everyday" that lists the most recently changed files in a folder. Run it on my project, respecting .gitignore, and tell me the latest changed Markdown file.

2. It learns the CLI on its own. I didn't explain anything. It read cmdbook --help, listed my folders, read commands create --help, and looked at a similar command I already had.

3. It saves the command. One cmdbook commands create, and "Recently changed files" shows up in cmdbook's sidebar, with prompts for the folder, the count and .gitignore.

4. It runs it and reads the output.

cmdbook run "Everyday/Recently changed files" --var folder=… --var count=1000 --var gitignore=yes --non-interactive --wait
Enter fullscreen mode Exit fullscreen mode

Then it searched the output for Markdown files and answered:

Latest changed Markdown file: README.md — modified 11/16/2026 07:01 PM, 2.2 K
Enter fullscreen mode Exit fullscreen mode

5. The run shows up in cmdbook. Click the new command, and its output panel shows the run the agent started.

6. Run it yourself, without the agent. Click Run, and you get the form. Drag in the folder, press Enter. Same answer: README.md, 07:01 PM, 2.2 K.

The script didn't stay in the chat. It's now a command you can run with one click, from a terminal, or from your agent again next time.

This is the same command as part 2 of this series, written by the agent this time.

The CLI and the MCP server are part of cmdbook Pro.

Try cmdbook here: printf.app/cmdbook

Top comments (0)