Automate Tasks in Claude Code with Slash Commands

John Lindquist
InstructorJohn Lindquist

Social Share Links

Tweet

Automating Claude Code tasks starts with reusable commands. Use repomix to bundle big context, then wrap it in a slash command so the workflow runs with a single trigger.

Ad-hoc: run repomix from chat

! repomix --include "src" --stdout --output-show-line-numbers

Follow with a prompt:

Given the bundled code above, outline the module boundaries and list obvious seams for refactoring.

Make it reusable: a custom slash command

Create .claude/commands/repomix.md:

---
allowed-tools: Bash(repomix:*)
argument-hint: [glob pattern] [user prompt]
---

!`repomix --include "$1" --stdout --output-show-line-numbers`

Use it:

/repomix src "Summarize the codebase and propose a dependency graph."

Why this pattern works

  • Abstraction: Hide flags and syntax you’ll forget.
  • Speed: One command, big context.
  • Consistency: Teammates can reuse your command, too.

[00:00] So I can't show how to run a bash command without immediately following it up by showing how to write a custom command. So I'm going to create a file in a .clod slash commands directory and call it repomix.md. So we'll create this file and close the other windows. And commands allow you to add a syntax with the exclamation point followed by backticks where you can insert a command that you want to run. So cursor recognizes the command which we talked about earlier which is repo mix include and then I'm going to extract this so that this becomes the first argument passed in.

[00:37] Then I'm going to add some front matter, so dash dash dash dash dash dash, and we're going to add two things, an allowed tools and an argument hint. I will cover this in more detail in future lessons, but essentially this allows us to run RepoMix with a command without having to allow it in any other settings. And then in argument hints we get to add a glob pattern, which becomes the $1 down here. And I'm going to include this in quotes actually. And then the user prompt would be $2 if we want to include that, but we don't actually need that inside this command, since the AI will just essentially run it.

[01:14] So now instead of remembering this entire syntax for whatever command I want to run, I can open a new Clod session, run Clod, and now I can say slash repo mix, hit tab, I'll type src for the source directory, and then in quotes, just because I kind of treat this like invoking a command, and this is essentially going to be this argument here. I'll just say, please summarize all of these files. You'll see once I hit enter that it's allowed to run one tool, and that this command gets run before this starts working. So we've brought in the entire context of the source directory and tossed it against this prompt here. So you'll see that nowhere in here did it ever call a read or try and parse out files 100 lines at a time or anything, it's just walking through and executing my prompt with the entire context to the best of its abilities.

[02:09] So if I clear this out and do the same thing with, I'll press up, instead of source I'll say source slash lib. This time it's going to summarize all the files in the lib directory and save us from remembering these flags, command name, or anything, and simply tuck it away behind that slash command where it also runs much much faster because It avoids any sort of reads, any sort of round trips. We just dump everything in there in the first pass, and the AI can respond with a single response.