[FEATURE] Support features such as loops, conditionals, variable assignments, etc. in custom slash command files
Resolved 💬 3 comments Opened Sep 30, 2025 by behrangsa Closed Jan 9, 2026
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
I sometimes wish I could use something similar to a Mustache template in my custom slash command Markdown files:
---
description: Simplified example
---
Perform these tasks:
{{#ARGUMENTS}}
- {{.}}
{{/ARGUMENTS}}
So /my-slash-command Foo Bar Baz would expand to the following document before getting passed to the API as a prompt, etc.:
---
description: Simplified example
---
Perform these tasks:
- Foo
- Bar
- Baz
Proposed Solution
Solution 1:
- Adopt a popular and universal templating language such as mustache.js and let us use it in our custom slash command .md files
Solution 2:
- Let us write custom slash commands in TypeScript (a quick and dirty sketch):
// saved as .claude/commands/brainstorm.ts
interface SlashCommandInput {
description: string;
allowedTools?: string[] | undefined | null;
arguments: Record<string, unknown>;
}
function slashCommand(input: SlashCommandInput): string {
const { description, allowedTools, arguments: args } = input;
// Hard-coded task template
const taskTemplate: string = 'Brainstorm $3 solutions for problem $2 in $1';
// Process allowed tools - handle empty, undefined, or null cases
const toolsList: string = allowedTools && allowedTools.length > 0
? allowedTools.join(', ')
: '';
// Generate argument hint from the keys of the arguments object
const argKeys: string[] = Object.keys(args);
const argumentHint: string = argKeys
.map((key: string) => `[${key}]`)
.join(' ');
// Construct and return the formatted string
return `---
description: ${description}
allowed-tools: ${toolsList}
argument-hint: ${argumentHint}
---
_Task:_
${taskTemplate}`;
}
export { slashCommand };
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
Interactive mode (TUI)
Use Case Example
_No response_
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗