Adding a custom slash command like /powershell is about transforming Claude from a general-purpose assistant into a specialized, context-aware co-pilot for your specific project. Here’s why it's powerful and how to set it up.
🎯 Why Create a Custom Slash Command?
Reason The Problem (Without Command) The Solution (With /powershell)
1. Save Time & Repetition You must repeatedly explain your project's structure, style rules, and common tools in every new chat. Encapsulates all project knowledge. Typing /powershell instantly gives Claude the context it needs.
2. Enforce Standards Claude might suggest solutions that don't follow your team's PowerShell best practices (e.g., unsafe execution policies). Embeds your rules (like "never suggest Bypass") directly into its workflow, ensuring consistent, high-quality output.
3. Reduce Errors Manual file context loading (@) is easy to forget, leading to suggestions based on incomplete information. Automates the "context-gathering" phase—Claude first reads key project files before acting.
4. Streamline Onboarding New team members spend days learning project quirks and setup. The command acts as an instant onboarding guide, giving anyone expert-level context.
5. Create a Shared Language Team discussions require long descriptions of tasks (e.g., "run the full test suite with detailed output"). Standardizes actions. /powershell can define exactly what "run tests" means (Invoke-Pester -Path ./tests -Output Detailed).
In essence, it inverts the workflow. Instead of you constantly guiding Claude, you teach Claude once how to guide itself within your project's world.
MD
1When this command is used, Claude should act as a PowerShell project expert. Follow these steps: 2 31. **Context Gathering & Analysis:** 4 * First, use the `@` mention to read the main project script file (like `@.\MyScript.ps1`). 5 * Check for a `RequiredModules.psd1`, `requirements.psd1`, or any `*.psd1/*.psm1` files to understand module dependencies. 6 * Look for a `tests/` directory and specifically for `*.Tests.ps1` files to understand the testing framework (likely Pester). 7 * Check for the presence of a `PSModulePath` configuration or a `.env` file with environment variables. 8 92. **Core Project Commands & Structure:** 10 * Assume the project follows common PowerShell conventions. If a module project (`*.psd1` exists), the build/test commands likely use `Invoke-Build` or `psake`. 11 * **Standard commands to reference:** 12 * `.\Build.ps1` or `Invoke-Build` - For task automation. 13 * `Invoke-Pester -Path ./tests -Output Detailed` - To run the full test suite. 14 * `Import-Module .\MyModule -Force` - For local development reloads. 15 * `Get-Module -ListAvailable` - To check installed dependencies. 16 173. **Best Practices & Safety Rules:** 18 * **NEVER** suggest running scripts with `-ExecutionPolicy Bypass` as a first solution. Prefer configuring the policy correctly. 19 * Always check for `#Requires` statements at the top of scripts and ensure Claude respects admin/module requirements. 20 * Prefer `-Confirm:$false` or `-Force` parameters only when explicitly safe and requested. Highlight their use if suggested. 21 * When editing functions, ensure `[CmdletBinding()]` and common parameters (`-Verbose`, `-ErrorAction`) are preserved if present. 22 * **Code Style:** Follow PowerShell's Verb-Noun naming for any new functions. Use PascalCase for variables in parameters, camelCase for local variables. Suggest `[ValidateSet()]` and `[Parameter(Mandatory)]` attributes to improve new functions. 23 244. **Common Tasks & Solutions:** 25 * For module dependency issues, suggest `Install-Module -Name <ModuleName> -Scope CurrentUser` or using `Save-Module`. 26 * For file path issues, always use `Join-Path` or `Resolve-Path` instead of string concatenation. 27 * For JSON/CSV manipulation, prefer `ConvertFrom-Json`, `ConvertTo-Json`, `Import-Csv`, and `Export-Csv` cmdlets. 28 * When suggesting error handling, include `Try/Catch` blocks with `$PSCmdlet.ThrowTerminatingError()` for advanced functions. 29 305. **Output & Next Steps:** 31 * After analysis, provide a concise summary of the project structure and identified dependencies. 32 * Tailor any following action plans (like adding a feature or fixing a bug) to the discovered project setup. 33 * Ask clarifying questions if the project structure is unusual or key files are missing.

slash command

/powershell

what would you like to do with this project?

add a test file for the module
POWERSHELL
1BeforeAll { 2 Import-Module "$PSScriptRoot/../Modules/GreetingHelpers/GreetingHelpers.psm1" -Force 3} 4 5Describe "Get-Greeting" { 6 Context "With required Prefix parameter" { 7 It "Returns greeting with username from environment" { 8 $result = Get-Greeting -Prefix "Hello" 9 $result | Should -Be "Hello, $env:USER!" 10 } 11 12 It "Returns greeting with different prefix" { 13 $result = Get-Greeting -Prefix "Welcome" 14 $result | Should -Be "Welcome, $env:USER!" 15 } 16 } 17 18 Context "With optional Username parameter" { 19 It "Returns greeting with custom username" { 20 $result = Get-Greeting -Prefix "Hello" -Username "TestUser" 21 $result | Should -Be "Hello, TestUser!" 22 } 23 24 It "Returns greeting with empty username" { 25 $result = Get-Greeting -Prefix "Hello" -Username "" 26 $result | Should -Be "Hello, !" 27 } 28 } 29 30 Context "Parameter validation" { 31 It "Has mandatory Prefix parameter" { 32 $command = Get-Command Get-Greeting 33 $command.Parameters['Prefix'].Attributes.Mandatory | Should -Contain $true 34 } 35 } 36} 37 38Describe "Show-Greeting" { 39 Context "With required Message parameter" { 40 It "Outputs message to host" { 41 $output = Show-Greeting -Message "Test Message" 6>&1 42 $output[0].ToString() | Should -Be "Test Message" 43 } 44 45 It "Outputs message 6 times by default" { 46 $output = Show-Greeting -Message "Test Message" 6>&1 47 $output.Count | Should -Be 6 48 } 49 } 50 51 Context "With optional RepeatCount parameter" { 52 It "Outputs message specified number of times" { 53 $output = Show-Greeting -Message "Test Message" -RepeatCount 3 6>&1 54 $output.Count | Should -Be 3 55 } 56 57 It "Outputs message once when RepeatCount is 1" { 58 $output = Show-Greeting -Message "Test Message" -RepeatCount 1 6>&1 59 $output.Count | Should -Be 1 60 } 61 62 It "Outputs nothing when RepeatCount is 0" { 63 $output = Show-Greeting -Message "Test Message" -RepeatCount 0 6>&1 64 $output | Should -BeNullOrEmpty 65 } 66 } 67 68 Context "Parameter validation" { 69 It "Has mandatory Message parameter" { 70 $command = Get-Command Show-Greeting 71 $command.Parameters['Message'].Attributes.Mandatory | Should -Contain $true 72 } 73 } 74}

All 11 tests pass