2. Claude Code CLI — Part 2: Advanced Techniques
2. Claude Code CLI — Part 2: Advanced Techniques
Continuation of 1ClaudeCLI.md. Covers pro-level features: slash commands, multi-agents, sub-agents, agent teams, hooks, plugins, and project structure.
Techniques Overview
Two approaches to working with Claude Code agents:
| Approach | Techniques | When to Use |
|---|---|---|
| Control (prioritize this) | Files, self-correcting loops, sandboxes, orchestration | Default — predictable, repeatable results |
| Chaos | YOLO mode, Ralph loops, GSD, swarms | When you need speed and can tolerate some messiness |
Start with control, and prioritize control. Only reach for chaos techniques when you have a good reason.
Pro Features
- Slash commands
- Multi-agents and sub-agents
- Agent teams
- Hooks
- Plugins
Slash Commands
Slash commands let you create reusable prompts you can invoke from inside Claude Code.
How to Create One
- Inside your project (or Claude installation folder), go into
.claude/and create a folder namedcommands/ - Add a markdown file — e.g.,
doc-review.md - Inside the markdown file, write whatever you want that command to do
How to Use It
claude
> /doc-review PLAN.md
Type / in the Claude Code terminal, select your command, and pass any arguments (like a file to review).
Skills as Slash Commands
Skills also work as slash commands. A skill gives you an instant, reusable slash command with frontmatter metadata (name, description, argument-hint).
Multi-Agents
You can run multiple Claude Code instances in separate terminals, each doing different work. However, they don't know they're working together, so it can get messy without coordination.
Built-in Agent Management
Type /agents inside Claude Code — it helps you create and manage agents.
Custom Agents via Files
Create an agents/ folder inside .claude/ in your project root. Each agent is a markdown file with frontmatter:
---
name: reviewer
description: Reviews code for quality, security, and best practices
---
Review the provided code. Check for:
- Security vulnerabilities
- Performance issues
- Code style consistency
- Missing error handling
Calling an Agent
Just reference it naturally in Claude Code:
> use the reviewer agent to carry out a review
Sub-Agents with External AI
You can tell Claude to use another AI inside your agent's .md file — for example, instructing it to call OpenAI's Codex for a specific subtask.
Project Structure
A recommended .claude/ folder structure for a project:
$ARGUMENTS/ # Your app's root directory
├── .claude/
│ ├── settings.json # For Specific Settings and Hooks
│ ├── agents/ # Agent definition files
│ ├── commands/ # Slash command files
│ └── skills/
│ └── skillname/
│ └── SKILL.md # Skill with frontmatter
├── planning/ # Plans, specs, architecture docs
└── CLAUDE.md # Project-level instructions for Claude
Agent Teams vs Sub-Agents
Sub-Agents
- Delegate one particular task to another Claude Code instance running with an isolated context
- The result goes back to the main Claude Code that called it
- There is always a parent-child relationship: main Claude Code delegates a task, the sub-agent executes it, and the result comes back
- Sub-agents can optionally have project-level memory via configuration settings
- Best for: focused, single-purpose delegation (e.g., "go write the tests for this module")
Agent Teams
- Assemble a group of Claude Code instances that all run collaboratively to solve a problem
- Multiple agents running at the same time (swarms and orchestration)
- The key difference: agents in a team can communicate with each other — they don't have to go through the main Claude Code
- Example: a tester agent gives test feedback directly to both the frontend agent and the backend agent
- Each agent has a long-running presence in the team
- They can interact, challenge each other, try different things, and test different hypotheses
| Feature | Sub-Agents | Agent Teams |
|---|---|---|
| Relationship | Parent-child (1:1) | Collaborative group (many:many) |
| Communication | Only with main Claude Code | With each other directly |
| Lifetime | Short — one task, then done | Long-running presence |
| Memory | Isolated (optional project memory) | Shared team context |
| Use case | Single focused task | Complex multi-part problems |
Hooks
Hooks are shell commands that Claude Code automatically runs in response to specific events. They let you add automated behaviors — like running a linter after every edit, or triggering a review after Claude finishes a task.
How to Set Up Hooks
Type /hooks inside Claude Code for an interactive setup, or manually add them to .claude/settings.json in your project root.
Available Hook Events
| Event | When It Fires |
|---|---|
| Stop | After Claude finishes responding / completes a task |
| PreToolUse | Before Claude calls a tool (e.g., before editing a file) |
| PostToolUse | After Claude calls a tool |
| Notification | When Claude sends a notification |
Example: Auto-Review on Stop
This hook runs after Claude finishes a task, calling another AI (Codex) to review the changes and write results to a file:
{
"hooks": {
"Stop": {
"hooks": [
{
"type": "command",
"command": "codex exec \"Review changes since last commit and write results to a file named planning/REVIEW.md\""
}
]
}
}
}
Where it goes:
.claude/settings.jsonin your project root.
Plugins
Plugins are self-contained packages that bundle skills, commands, agents, and hooks together. They can be shared with your team or published to a marketplace.
Plugin Structure
Create a folder in your project root for the plugin, with a .claude-plugin/ subfolder containing a plugin.json:
$ARGUMENTS/
├── independent-reviewer/ # Plugin folder (the plugin name)
│ ├── .claude-plugin/
│ │ └── plugin.json # Plugin metadata
│ ├── skills/ # Optional: skill files
│ ├── commands/ # Optional: slash command files
│ ├── agents/ # Optional: agent files
│ └── hooks/
│ └── hooks.json # Optional: hook definitions
└── .claude-plugin/
└── marketplace.json # Marketplace config (for sharing)
A plugin folder can contain any combination of 4 subdirectories: skills/, commands/, agents/, and hooks/.
plugin.json
Every plugin needs a plugin.json with basic metadata:
{
"name": "independent-reviewer",
"description": "Automatically reviews code changes for quality and security",
"version": "1.0.0"
}
Publishing to a Marketplace
To make your plugin available to others (team or public), add a marketplace config at the project root level:
.claude-plugin/
└── marketplace.json
{
"name": "your-marketplace-name",
"owner": {
"name": "Your Name",
"email": "your@email.com"
},
"plugins": [
{
"name": "independent-reviewer",
"source": "./independent-reviewer",
"description": "Carry out an independent review of all changes since last commit",
"version": "1.0.0",
"author": {
"name": "Your Name"
}
}
]
}
Installing a Plugin
- In the Claude Code terminal, run
/plugin - Go to the Marketplace tab
- Click "Add Marketplace"
- Type
./and press Enter (points to your local directory) - It will find the plugin you added — click it
- Go to Browse Plugins
- In Discover, find your plugin and press Enter
- Choose "Install for all collaborators on this repository" (project scope)
- Restart Claude Code to load the newly installed plugin
Full Project Structure
Everything covered in this guide combined into one unified tree:
$ARGUMENTS/ # Your app's root directory
├── .claude/
│ ├── settings.json # Settings and hooks configuration
│ ├── agents/ # Agent definition files
│ ├── commands/ # Slash command files
│ └── skills/
│ └── skillname/
│ └── SKILL.md # Skill with frontmatter
├── .claude-plugin/
│ └── marketplace.json # Marketplace config (for sharing plugins)
├── independent-reviewer/ # Plugin folder (example plugin)
│ ├── .claude-plugin/
│ │ └── plugin.json # Plugin metadata
│ ├── skills/ # Optional: skill files
│ ├── commands/ # Optional: slash command files
│ ├── agents/ # Optional: agent files
│ └── hooks/
│ └── hooks.json # Optional: hook definitions
├── planning/ # Plans, specs, architecture docs
└── CLAUDE.md # Project-level instructions for Claude