# How to Create a Custom Command in Claude Code with Runtime Parameters

**URL:** <https://sorumatik.co/t/how-to-create-a-custom-command-in-claude-code-with-runtime-parameters/665598>\
**Category:** Homework Help\
**Created:** [Haziran 5, 2026, 9:24ös UTC](https://sorumatik.co/t/how-to-create-a-custom-command-in-claude-code-with-runtime-parameters/665598 "2026-06-05T21:24:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dersnotu](https://sorumatik.co/user_avatar/sorumatik.co/dersnotu/32/3037_2.png) [@Dersnotu](https://sorumatik.co/u/Dersnotu)\
**Post date:** [Haziran 5, 2026, 9:24ös UTC](https://sorumatik.co/t/how-to-create-a-custom-command-in-claude-code-with-runtime-parameters/665598/1 "2026-06-05T21:24:30Z")

</div>

how do you create a custom command in claude code that accepts runtime parameters?

---

<div class="post-metadata">

**Author:** ![Egitim\_Danismani](https://sorumatik.co/user_avatar/sorumatik.co/egitim_danismani/32/86791_2.png) [@Egitim\_Danismani](https://sorumatik.co/u/Egitim_Danismani)\
**Post date:** [Haziran 5, 2026, 9:24ös UTC](https://sorumatik.co/t/how-to-create-a-custom-command-in-claude-code-with-runtime-parameters/665598/2 "2026-06-05T21:24:37Z")

</div>

## How to Create a Custom Command in Claude Code with Runtime Parameters

### Key Takeaways

- Custom commands in **Claude Code** are defined within the `.claudecode.json` configuration file.
- To accept runtime parameters, you use **positional arguments** or **environment variables** within the configuration schema.
- These commands allow you to automate repetitive developer workflows like linting, testing, or specific build scripts.

To create a custom command that accepts runtime parameters in **Claude Code** , you must define a new entry in your project’s `.claudecode.json` file. By using placeholder syntax or shell-scripting logic within the `command` string, you can pass arguments dynamically when executing the command from the Claude Code interface.

* * *

### Table of Contents

1. [Defining Commands in .claudecode.json](#defining-commands)
2. [Passing Runtime Parameters](#passing-parameters)
3. [Comparison of Command Types](#command-comparison)
4. [Summary Table](#summary-table)
5. [Frequently Asked Questions](#faq)

* * *

### Defining Commands in .claudecode.json

Claude Code looks for a configuration file in your project root to understand project-specific capabilities. You define custom commands under the `commands` key. Each command requires a name, a description (so Claude knows when to use it), and the actual shell command to execute.

> 💡 **Pro Tip:** Always provide a detailed description. Claude uses this description to map your natural language requests to the specific custom command.

* * *

### Passing Runtime Parameters

There are two primary ways to handle dynamic input in your custom commands:

#### 1. Shell Argument Passing

Since Claude Code executes these commands in your local shell environment, you can write scripts that expect arguments.

**Example `.claudecode.json`:**

```json
{
  "commands": {
    "analyze-file": {
      "description": "Analyzes a specific file for security vulnerabilities. Requires a file path.",
      "command": "python3 scripts/analyze.py $1"
    }
  }
}

```

When you tell Claude: _“Analyze the file src/auth.py”_, Claude interprets the file path as the first argument (`$1`) and executes: `python3 scripts/analyze.py src/auth.py`.

#### 2. Environment Variables

You can also structure commands to use environment variables if your runtime parameters are meant to configure the behavior of a tool (like setting a `NODE_ENV`).

* * *

### Comparison of Command Types

| **Feature** | **Static Command** | **Parameterized Command** |
| --- | --- | --- |
| **Complexity** | Low | Moderate |
| **Flexibility** | Fixed output (e.g., `npm test`) | Dynamic (e.g., `npm test -- [file]`) |
| **Use Case** | General CI/CD tasks | Targeted debugging or specific builds |
| **Claude’s Role** | Triggering execution | Mapping intent to arguments |

* * *

### Summary Table

| **Component** | **Description** |
| --- | --- |
| **Config File** | `.claudecode.json` located in the root directory. |
| **Key Syntax** | `"command": "your-script.sh $1 $2"` for positional params. |
| **Description** | Vital for Claude’s “agentic” ability to choose the command. |
| **Execution** | Triggered via natural language within the Claude Code CLI. |

* * *

### Frequently Asked Questions

**1. Can I use multiple parameters in one command?**  
Yes. You can define commands like `gcc $1 -o $2`. Claude will attempt to extract both the source file and the output name from your natural language prompt.

**2. What happens if I don’t provide a required parameter?**  
Claude will typically realize the command is missing information based on the shell requirement and ask you: _“Which file should I use for this command?”_ before executing.

**3. Does this work with global Claude Code config?**  
Currently, custom commands are most effective when defined per-project in the local root, ensuring the environment and paths are correct.

* * *

## Next Steps

Shall I help you draft a specific `.claudecode.json` configuration for a particular tool or language you are currently using?
