Have Claude Code Create Commands for You

Article Highlights

  • Claude Code skills and commands both use a SKILL.md file; the key difference is whether Claude invokes the file automatically or you run it explicitly.
  • A reusable command can install Microsoft Dev Proxy, add MSAL authentication code, define invocation triggers, and provide start and stop instructions.
  • The most reliable way to build a complex command is to extend it through focused prompts, test it against a real application, and debug it iteratively.
  • Fixes discovered during testing should be applied to the command rather than to one application so every future project benefits.

Claude Code commands for reusable Dev Proxy and MSAL setup

Skills vs. Commands

If you ever use the same prompt twice when working with Claude Code, you should be creating a command. And, just like having Claude Code write your application code, you should have Claude Code write your command for you.

In this post, I’m going to walk through creating a command to do three things you need in every Azure project:

  • Add a mock version of Entra ID to your development computer

  • Add to your application the authentication/authorization code to work with Entra ID

  • Manage that mock version of Entra ID after it’s installed

I’ve thrown in that command at the end of this post. And, by the way, this process works just as well for creating Claude Code skills so it’s worth explaining why that is before I start.

As Learning Tree’s Leveraging Claude Code in Application Development course points out, Claude Code skills and commands are both implemented by creating a SKILL.md file. The only difference between a “skill” and “command” is how they are invoked, not how they are built: If your SKILL.md file is invoked automatically by Claude then it’s called a skill; If you invoke your SKILL.md from Claude’s CLI by typing a forward slash (e.g. /MySkill), then it’s a command.

SKILLS VS. COMMANDS

Same file. Different trigger.

A skill and a command are both a SKILL.md file. What changes is who pulls the trigger.

SKILL.md

SKILL

Claude decides.

Claude runs the file when your request matches its description.

you › set up mock authclaude › runs my-skill
---name: my-skilldescription: what it does, when to use it---

COMMAND

You decide.

You run the file yourself by typing a forward slash and its name.

you › /my-skillRuns only when you ask.
---name: my-skilldisable-model-invocation: true---

Delete one line, disable-model-invocation, and a command becomes a skill.

If you have a SKILL.md file that you intend to use exclusively as a command, then you can omit the description property in the SKILL.md file’s frontmatter and add disable-model-invocation: true to that frontmatter.

This would be a perfectly acceptable way to begin a “command only” SKILL.md file, for example:

---

name: my-skill

disable-model-invocation: true

---

Though, I have to say, omitting the description property means giving up an opportunity to make your command a little more self-documenting. Just because you can do something, doesn’t mean you should do something.

Mocking and Accessing Entra ID

I do a lot of Azure development (I’m currently building an application to run in Azure and support people taking certification exams, for example) but I don’t want to interact with Azure resources while I’m building my application. There are two reasons for that: First, it’s faster for me to build things if everything is executing on my own computer; Second, It’s cheaper (my primary reason).

But to avoid using Azure, I need to emulate Azure resources my development computer, including Entra ID so that I can test my application’s MSAL authorization and authentication code. Microsoft has an emulator that does that, called Microsoft Dev Proxy.

Dev Proxy gives any MSAL code that I add to my application something to interact with so that I can make sure that that my code works. I can’t create identities and roles with Dev Proxy (I have to wait until I move to Azure to do that) but Dev Proxy will check that my application is making valid authentication requests (including requests to services like Microsoft Graph and LLMs: see https://learn.microsoft.com/en-us/microsoft-cloud/dev/dev-proxy/how-to/overview for more information).

Adding Dev Proxy to your computer isn’t hard to do. This PowerShell command will do it in Windows:

iwr https://aka.ms -useb | iex

And this Bash command will do it in Linux or macOS:

sh -c "$(curl -sL https://aka.ms)"

On the other hand, writing the MSAL code to have your application authenticated and authorized isn’t trivial. Fortunately, that code is pretty much the same in every application: The only thing that changes from one application to another is the security information you pass to your MSAL code – and that information is best kept in environment variables in production or in User Secrets in development. If you want to see the ugly details of that code, I have a blog post on securing client-side frontends and another on securing server-side frontends.

Building a Command with Claude

You can certainly ask Claude Code to add your MSAL code for you. However, since the MSAL code is pretty much identical from one application to another, you’ll end up using the same prompt every time – which means this is a perfect opportunity to create a command. And, while you’re doing that, you can have your command both install Dev Proxy (if it isn’t already installed) and let you manage Dev Proxy once it’s installed.

BUILDING THE COMMAND

Four prompts. One command.

Claude Code wrote the command. Each prompt switched on one more capability in the same file.

01

Create a command that sets up Microsoft Dev Proxy v3 for a React + TypeScript SPA with MSAL authentication…

+ InstallMSAL codeTriggersStart / stop

02

Add to the skill all the necessary MSAL code to authorize my application…

Install+ MSAL codeTriggersStart / stop

03

The skill should run on any mention of “dev proxy”, “mock auth”, “mock Entra”…

InstallMSAL code+ TriggersStart / stop

04

Include commands for starting and stopping Dev Proxy from the CLI.

InstallMSAL codeTriggers+ Start / stop

✓ SKILL.md installs, wires up and manages Dev Proxy.

If you look at the end of this post, you’ll see that command. You may even be impressed with my coding abilities as you read it…except I didn’t write that command – Claude Code did. Claude Code can write the markdown for your skills and commands as easily as it will write the code for your application.

The initial prompt for my Dev Proxy/MSAL command for my client-side code looked like this:

Create a command that sets up Microsoft Dev Proxy v3 for a React + TypeScript SPA with MSAL authentication. Check for Dev Proxy version 3.0.0 or later in this computer and, if older, install the most recent version.

After that prompt, my next step was to have Claude Code extend the command to add MSAL authentication/authorization code to my application. This prompt barely refers to Dev Proxy: I want the command to add the code that my application will use in production – it just happens to interact with Dev Proxy while I’m in development:

Add to the skill all the necessary MSAL code to authorize my application. Use the application’s URL and create dummy tenant and client ids in a configuration file. Generate any Dev Proxy configuration files required for authentication in development.

Next, I specified when this command should be invoked so I didn’t have to use the forward slash to execute it:

The skill should run on any mention of "dev proxy", "devproxy", "mock auth", "mock Entra", "MSAL proxy", or any request to intercept Entra/Azure AD auth locally without a real tenant.

And, what the heck, as long as I was at, I had the command start and stop Dev Proxy for me:

Include commands for starting and stopping Dev Proxy from the CLI.

I then tried using my command. Did it work? Don’t be silly – no, of course it didn’t. Nothing works the first time.

Among other issues, there were some holes in Microsoft’s Dev Proxy documentation that Claude Code didn’t spot…the first time it wrote the command. But just like writing application code, I used Claude Code interactively to debug my command and tell me what went wrong. During this part of the process, my cycle was to tell Claude Code to:

  1. Back out any changes made to my application made while testing the command

  2. Apply any fixes to the command (not to my application code), based on what we discovered during testing

And then Claude Code and I repeated that process until we had a working command.

Using Commands

I’ll repeat what I said at the start of this post: If you find yourself using the same prompt twice in building with Claude Code then you should get Claude Code to create a command for you. And because commands are also skills, you don’t have to stop there. I built some more commands to add the other Azure emulators I use (e.g. the emulators functions and Azure Storage) and let me manage those emulators also. Eventually, I stripped out the “disable model” property to turn those commands into skills. That let me create plugin for setting up and managing my Azure development environment.

DEBUGGING THE COMMAND

Nothing works the first time.

So debug the command the way you debug code: in a loop.

while (!command.works) {

01

Run it

Try the command against a real application.

02

Ask why

Have Claude Code tell you what went wrong.

03

Back out

Undo everything the test run changed in your application.

04

Fix the command

Put the fix in the command, not in your application code.

} // ↻ back to 01

A fix in the application helps once. A fix in the command helps every project that uses it.

You should be getting Claude to do the same for you.

THE COMPLETE COMMAND

The Claude Command’s SKILL.md file

289 lines. Save it in your project as .claude/skills/dev-proxy/SKILL.md

SKILL.md · click to hide or show

Click inside the box, press Ctrl+A (⌘+A on a Mac) to select the whole file, then copy.

Or, you can download the complete SKILL.md file here.

 

As a bonus, here are four failures encountered in this process and how we fixed them:

BONUS: DEV PROXY FIXES

Four failures. Four fixes.

These surfaced while testing the command with Microsoft Dev Proxy. All four are built into the command, so you don’t have to rediscover them.

01

Use #, not ?, in the Location header

SYMPTOM

The sign-in button appears to do nothing.

WHY

MSAL reads the auth code from the URL hash. A ? puts the code in the query string, where MSAL never looks.

USE THIS

#code=MOCK_AUTH_CODE

02

End the token URL pattern with *

SYMPTOM

Login fails with 401 Unauthorized.

WHY

MSAL adds a query string to the token endpoint URL. Without a trailing wildcard, the mock never matches.

USE THIS

oauth2/v2.0/token*

03

Add a CORS header to the token response

SYMPTOM

A CORS error on the token request, even though Dev Proxy returned 200.

WHY

The token exchange is a cross-origin fetch, so the browser blocks a response that lacks the header.

USE THIS

Access-Control-Allow-Origin: APP_URL

04

Use a fixed nonce, not @dynamic

SYMPTOM

Login fails with a nonce mismatch.

WHY

Dynamic nonce substitution is unreliable inside the id_token. Put a fixed nonce in the token and pass the same value in the login call.

USE THIS

nonce: 'mocked-nonce'

✓ SKILL.md already includes all four.

Learning Tree International can offer Anthropic’s certification portfolio as a member of the Claude Partner Network.

Claude Partner Badge

 

Frequently Asked Questions (FAQs)

What is the difference between a Claude Code skill and a command?

Both are implemented with a SKILL.md file. A skill is selected automatically by Claude when a request matches its description, while a command is run explicitly from the Claude Code CLI with a forward slash and the command name.

Why create a command instead of reusing the same prompt?

A command captures repeatable instructions in one maintained file. When you improve that file, the fix becomes available to every project that uses the command instead of solving the same problem separately in each application.

What can the Dev Proxy and MSAL command automate?

The example command can check or install Microsoft Dev Proxy, create the required proxy and mock configuration files, install and wire MSAL packages into a React and TypeScript application, and provide instructions for starting and stopping Dev Proxy.

How should a Claude Code command be debugged?

Run the command against a real application, ask Claude Code to explain failures, back out test changes, and apply the discovered fix to the command itself. Repeat that loop until the command works reliably.