Using Claude Code Effectively: Subagents and Slash Commands for Developers

Claude Code is Anthropic’s agentic coding tool that lives in your terminal and helps you turn ideas into code faster than ever before. It acts as an AI coding assistant, allowing you to describe features or fixes in plain English and having the AI generate or modify code accordingly. In this blog post, we’ll explore two powerful ways to customize and get the most out of Claude Code: subagents and slash commands. We’ll cover how to create effective custom AI subagents for specialized tasks, highlight five of the most useful built-in slash commands, and show how to define your own custom slash commands. The goal is to help developers (and vibe coders alike) feel comfortable using Claude Code to streamline their workflow.

Claude Code Subagents: Creating Custom AI Assistants

What are Subagents? Claude Code subagents are pre-configured AI personalities that Claude can delegate tasks to. Each subagent has a specific purpose or domain of expertise (for example, code review, testing, or debugging), uses its own separate context window (so it won't mix up information with the main conversation), and can have its own set of tools and a custom system prompt guiding its behavior. In practice, when Claude Code encounters a task that matches a subagent’s purpose, it can hand off that task to the subagent, which then works independently and returns the result.

Why use subagents? Subagents bring several benefits: they preserve context (each works in isolation, preventing the main chat from getting cluttered) and provide specialized expertise for certain tasks. You can fine-tune a subagent with detailed instructions for its domain, leading to higher success rates on those tasks. Subagents are also reusable – once you create one (say, a “code-reviewer” agent), you can use it across projects or share it with your team for consistent workflows. Each subagent can be given limited tool permissions as needed (for safety, you might restrict powerful actions to only specific agents).

Creating a custom subagent. Claude Code makes it easy to set up a new subagent. The simplest way is to use the interactive /agents command:

  1. Open the subagents interface: In Claude’s terminal session, run the slash command /agents. This opens an interactive menu to manage subagents. From there, choose “Create New Agent”.
  2. Define the subagent: You’ll be prompted to fill in details. Claude Code can even auto-generate a draft subagent definition for you, which you can then customize. Provide a name (a unique identifier, lowercase with hyphens), a description of the subagent’s purpose (when should Claude delegate to it), and select which tools it can use (or leave that blank to let it inherit all available tools). The interface conveniently lists all tools so you can pick those relevant to the subagent’s job. You will also define the subagent’s system prompt – essentially instructions that dictate how it should approach tasks. This prompt can be multiple paragraphs describing the role, capabilities, best practices, and any constraints for the agent.
  3. Save and use: Once saved, your new subagent becomes active. Claude will automatically use it when a user request seems to fit that agent’s described purpose, or you can invoke it explicitly by name. For example, you might tell Claude: “Use the code-reviewer subagent to check my recent changes.” In this case, Claude will hand over the task to the code-reviewer agent and return its output.

Under the hood, each custom subagent is stored as a Markdown file with a YAML frontmatter. The file might look like this in your project (for a project-level agent) or your home directory (for a user-level agent):

---
name: your-sub-agent-name  
description: Description of when this subagent should be invoked  
tools: tool1, tool2, tool3  # Optional - inherits all tools if omitted  
---

< Subagent system prompt instructions go here... >

In the above snippet, we define the name of the agent, a short description of its purpose, and an optional list of tools it is allowed to use. If you omit the tools field, the subagent will inherit all tools available to the main Claude session by default. The body of the file (after the YAML --- markers) is the subagent’s system prompt – use this to clearly define the agent’s role, approach to solving problems, and any specific instructions or constraints it should follow.

Tips for effective subagents: To make your custom agents more effective, be very clear and specific in their description and prompt. For instance, if you want Claude to proactively use a certain subagent whenever possible, say so! The documentation suggests including phrases like “use PROACTIVELY” or “MUST BE USED” in the subagent’s description to nudge Claude into delegating to it more often. Also, choose a descriptive name and make sure the description covers the scenarios where the agent is useful. You can manage and tweak subagents either via the /agents menu (recommended for ease) or by directly editing the Markdown files (located under .claude/agents/ in your project for project-specific agents, or under ~/.claude/agents/ for user-wide agents). Project-level agents take precedence if there’s a name conflict with a user-level agent.

With well-crafted subagents, Claude Code can become a team of specialized helpers – e.g. a “test-runner” agent that runs and fixes tests, a “security-auditor” agent focusing on finding vulnerabilities, or a “doc-writer” agent that generates documentation. These agents will keep your main conversation focused and tackle their niche tasks with the guidelines you’ve given them.

Top 5 Useful Slash Commands in Claude Code

Claude Code provides many slash commands (commands you type with a leading / in the terminal session) to control its behavior or perform common actions. Below are five of the most useful built-in slash commands for developers, along with what they do:

  1. /init – Initialize a project: This command sets up a new project by creating a CLAUDE.md guide in your repository. It’s great for getting started with Claude Code on a fresh codebase. Running /init will generate a Markdown file with guidelines (like a project README for Claude) that helps the AI understand your project’s context and conventions.
  2. /agents – Manage AI subagents: Opens an interactive menu to create, edit, or view custom subagents. This is the command we discussed earlier; it allows you to configure specialized AI helpers. Using /agents is an easy way to tweak which tools a subagent can use, update its prompt, or add new agents without manually editing files. (When listed in the help menu, this command appears as “agents (project)” or “(user)” depending on scope).
  3. /review – Request a code review: When you want an AI perspective on your code changes, use /review. Claude will analyze your recent changes or a pull request and provide a code review with feedback. This can help catch issues or suggest improvements from an AI code reviewer’s perspective.
  4. /memory – Edit memory files: Claude Code maintains a memory of important context (in a file called CLAUDE.md). The /memory command opens or lets you edit these memory files. You might use this to update Claude’s knowledge of project-wide information or persistent instructions (for example, high-level design decisions or naming conventions) that you want it to remember across sessions.
  5. /clear – Clear the conversation: This command clears the conversation history in Claude Code. It’s essentially a reset – very useful when you want to start fresh without any prior context influencing the AI. For instance, if Claude has gone off track or you’re switching to a completely new task, /clear wipes the slate clean.
  6. --resume - Resume the conversation where you left off This command resume the conversation when you accidently stops or terminate the claude ocde cli. after running this command you can chat where you left of.

Creating Your Own Custom Slash Commands

In addition to the built-in commands, Claude Code allows you to define custom slash commands. This is a powerful feature for setting up shortcuts to instructions you often give the AI. Instead of retyping a prompt, you can create a command that encapsulates it. Here’s how to make a simple custom slash command:

  • File and naming: A custom command is defined by a Markdown file (with .md extension) whose filename becomes the command name. For example, a file named optimize.md would create a /optimize command. You can create project-specific commands (shared with your team in the repository) by placing the file under a .claude/commands/ folder in your project. Alternatively, for a command available in all your projects (personal command), place the file under ~/.claude/commands/ in your home directory. The scope is indicated in the /help list (project commands show “(project)” and user-level commands show “(user)” next to their descriptions).

  • Command content: The Markdown file’s content is the prompt or instructions that will run when you invoke the slash command. You can simply write the prompt text in the file. For example, suppose you frequently want Claude to analyze code for performance issues; you could create .claude/commands/optimize.md with content like: “Analyze this code for performance issues and suggest optimizations:”. Then, in your Claude session, just type /optimize and the AI will execute that prompt.

  • YAML metadata (optional): You can add a YAML frontmatter at the top of the command file to specify metadata. Useful fields include:

  • description – A short description of what the command does. This will show up in the /help menu next to your command name.

  • argument-hint – A hint for any arguments your command expects. For example, you might set argument-hint: "<issue-number>" if your command takes an issue number. This hint appears when you auto-complete the command in the terminal.
  • allowed-tools – If your command needs to run shell commands (more on that below), you must list which tools (commands) are permitted. For instance, allowed-tools: Bash(git status:*), Bash(git diff:*) would allow the command to run git status and git diff and include their output in context.

The YAML section is delimited by triple-dashes --- at the top and bottom, just like in subagent files. If you don’t need any special metadata or tools, you can omit it, but adding a description is recommended for clarity.

  • Using arguments: Custom commands can accept arguments. Inside your command file, use the placeholder $ARGUMENTS wherever you want to inject the user-provided arguments. For example, say you create a file .claude/commands/fix-issue.md with the content: “Fix issue #\$ARGUMENTS following our coding standards.” Then running /fix-issue 123 will have Claude read that as “Fix issue #123 following our coding standards.” This is a convenient way to pass dynamic values to your prompt.

  • Including live data (advanced): Claude Code lets you include output of shell commands or file contents in your custom command context, which can be powerful for context-rich commands. If you prefix a line in your command with !, it will execute that shell command and include its output when the command runs. For example, you could have your command run !`git diff HEAD` to include the latest git diff in the prompt. (Remember to list such commands under allowed-tools in the YAML for security.) Similarly, prefixing with @ allows referencing file contents directly (e.g., writing Compare @old.js with @new.js will pull in those files' contents when the command executes). These advanced features can make your slash commands context-aware and very powerful. For a simple custom command, you might not need them initially, but it's good to know they exist as you grow more comfortable.

Example: Imagine you want a quick command to run your project’s tests and then have Claude analyze any failures. You could create a project command .claude/commands/test-run.md with content like:

description: Run tests and diagnose failures
allowed-tools: Bash(npm run test)
---
Run the full test suite with `npm run test`, then examine any failing tests and suggest fixes.

Here, /test-run would execute npm run test (allowed by our allowed-tools entry) and then the prompt instructs Claude to look at the failures and propose solutions. The description will show in /help as “Run tests and diagnose failures (project)”.

Once your custom command file is in place, Claude Code will automatically pick it up. Simply type /your-command-name in the terminal session and it will execute your defined prompt. You can list all custom commands with /help to verify it appears. Organizing commands into subdirectories is possible too, which creates namespaced commands like /frontend:component if you put a file under a subfolder (e.g., .claude/commands/frontend/component.md). This helps keep things tidy when you have many commands.

Conclusion

Claude Code is a versatile AI coding assistant, and by leveraging subagents and custom slash commands, you can tailor it to your exact workflow. Subagents empower you to embed expert AI “personas” into your development process – whether it’s an agent that proactively handles code reviews or one that specializes in troubleshooting tests. Slash commands, on the other hand, give you quick shortcuts to trigger those AI behaviors or any repetitive prompt with a single command. By using clear definitions, proper syntax, and the tips provided (like using descriptive keywords in subagent configs and adding helpful metadata in commands), developers can make Claude Code an even more effective partner. We hope this guide helps you set up your own custom AI agents and commands in Claude Code. Happy coding, and enjoy the productivity boost from your new AI development buddy!

Sources:

  1. Anthropic Documentation – Claude Code: Subagents
  2. Anthropic Documentation – Claude Code: Slash commands

Need Help Implementing Using Claude Code Effectively?

I have extensive experience building multimodal RAG systems and can help you implement these solutions for your business.

Get Expert Consultation