The user wants to save their previous message — the most recent user turn in this conversation before this invocation — as a reusable custom slash command, unchanged.
Raw arguments: $ARGUMENTS
Do this:
- Parse
$ARGUMENTSinto a name and an optional scope flag:--global/-g/ the wordglobal-> save system-wide.--project/-p/ the wordproject-> save to the current project.- Everything else is the command name.
- If no name is given, STOP and ask for one, e.g.
/slash-it:create-cmd fix-bug. A name is required. - Determine where to save (scope):
- If a scope flag was given, use it.
- Otherwise, ASK the user with AskUserQuestion: "Where should
/<name>be saved?" with options Global (all projects) and Project (this repo only). - Global path:
~/.claude/commands/(the user's home.claude/commandsdirectory) - Project path:
<current working directory>/.claude/commands/— create this folder if it doesn't exist. If there is no project / not in a repo, fall back to Global and say so.
- Normalize the name: lowercase, kebab-case, strip any leading
/and the.mdextension. - Find the user's previous prompt (the message right before this call). Use its text verbatim as the command body. Do NOT rewrite, optimise, or summarize it.
- Add YAML frontmatter with a one-line
descriptionderived from the prompt. - Write the file to
<chosen path>/<name>.md. - If that file already exists, show its current contents and ask before overwriting.
- Confirm: print the saved file path, the scope (global/project), and that
/<name>is now available (reopen the/menu for it to appear).