Global Agents
Global agents are AI specialists that you can execute from anywhere on your system, just like any other terminal command. Instead of navigating to a project directory to use an agent, you can invoke it from any location.What are Global Agents?
Global agents transform Claude Code agents into standalone CLI commands:- Regular Agent: Only works in the directory where installed (
.claude/agents/) - Global Agent: Works from any directory, like
npm,git, ordocker
System-Wide Access
Run from any directory without navigating to project
Auto Context Detection
Automatically detects project type and includes relevant files
Standalone Execution
No need for Claude Code to be open
Script Integration
Use in npm scripts, CI/CD, and shell scripts
How Global Agents Work
~/.claude-code-templates/agents//usr/local/bin or ~/.claude-code-templates/bin)security-auditor "check this code"- Loads agent system prompt from
~/.claude-code-templates/agents/security-auditor.md - Detects project context (language, framework)
- Auto-includes relevant files
- Calls Claude CLI with agent context
Creating Global Agents
Basic Creation
With Category Path
If the agent name is ambiguous, use the full category path:Creating Multiple Global Agents
Create several agents at once:Using Global Agents
Basic Usage
Auto-Context Detection
Global agents automatically detect your project type and include relevant files:- Detects React project (from
package.json) - Includes
src/,components/,pages/directories - Understands React patterns and conventions
- Can read files using the Read tool
- JavaScript/Node: Detects from
package.json, includessrc/,lib/,components/ - Python: Detects from
requirements.txtorpyproject.toml, includes*.pyfiles - Go: Detects from
go.mod, includes*.go,cmd/,internal/,pkg/ - Rust: Detects from
Cargo.toml, includessrc/,Cargo.toml - React/Vue/Next.js: Framework detection from dependencies
Explicit File Selection
Override auto-detection by specifying files:Directory Targeting
Disable Auto-Detection
For general advice without project context:Verbose Mode
See what the agent is doing:Managing Global Agents
List Installed Agents
Remove an Agent
Update an Agent
Fetch the latest version from GitHub:Installation Locations
System Directory (Recommended)
If you have write access to/usr/local/bin, agents are installed there:
- Immediately available in PATH
- No shell configuration needed
- Works in all terminals and IDEs
User Directory (Fallback)
If system directory is not writable, uses user directory:~/.bashrc or ~/.zshrc
Advanced Usage
In npm Scripts
Add global agents to package.json:package.json
In Shell Scripts
Create automation scripts:pre-commit.sh
In CI/CD Pipelines
In Docker Containers
Custom Global Agents
You can create custom global agents by:- Creating a custom agent in
.claude/agents/ - Publishing to GitHub
- Installing as global agent
---
name: my-custom-agent
description: Custom agent for my specific needs
tools: Read, Write, Bash
model: sonnet
---
You are a custom agent that specializes in...
[Agent instructions here]
# Push to your repo
git add .claude/agents/my-custom-agent.md
git commit -m "Add custom agent"
git push
# 1. Copy agent to global location
mkdir -p ~/.claude-code-templates/agents
cp .claude/agents/my-custom-agent.md ~/.claude-code-templates/agents/
# 2. Create wrapper script
cat > ~/.claude-code-templates/bin/my-custom-agent << 'EOF'
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
const agentPath = path.join(os.homedir(), '.claude-code-templates/agents/my-custom-agent.md');
const systemPrompt = fs.readFileSync(agentPath, 'utf8').replace(/^---[\s\S]*?---\n/, '').trim();
const userInput = process.argv.slice(2).join(' ');
if (!userInput) {
console.error('Usage: my-custom-agent "your prompt"');
process.exit(1);
}
const cmd = `claude -p "${userInput}" --system-prompt "${systemPrompt}"`;
execSync(cmd, { stdio: 'inherit' });
EOF
# 3. Make executable
chmod +x ~/.claude-code-templates/bin/my-custom-agent
# 4. Use it
my-custom-agent "your prompt"
Troubleshooting
Command Not Found
If you getcommand not found after creating a global agent:
-
Check PATH:
-
Add to PATH manually:
-
Use absolute path:
Permission Denied
Claude CLI Not Found
Global agents require Claude CLI:Agent File Not Found
Context Detection Not Working
If the agent doesnβt detect your project:Best Practices
1. Name Agents Descriptively
β Good:2. Use for Specialized Tasks
Global agents work best for:- Security audits
- Code reviews
- Documentation generation
- Performance analysis
- Compliance checks
- General chatting
- Multi-step projects
- Interactive sessions
3. Combine with Shell Aliases
~/.bashrc
4. Create Agent Sets
Install related agents together:5. Document in Team README
README.md
Next Steps
Installing Components
Learn about regular component installation
Batch Installation
Install multiple components at once
Workflows
Create reusable installation workflows
Component Browser
Browse all available agents