Create Global Agents
Global agents are AI assistants that can be executed from any directory on your system, like command-line tools. They provide instant access to specialized AI capabilities without navigating to specific projects.Overview
Global agents are:- Accessible anywhere - Run from any directory
- Self-contained - Include their own system prompts
- Context-aware - Auto-detect project types
- Shell-integrated - Work in scripts, npm tasks, CI/CD
Creating a Global Agent
Basic Creation
Create a global agent from any available agent:Examples
Installation Locations
Global agents install to: System Directory (preferred, immediately available):Using Global Agents
Basic Usage
Once created, invoke global agents from anywhere:Examples
Context Auto-Detection
Global agents automatically detect your project context:Project Type Detection
Agents detect project types based on:| Indicator | Project Type |
|---|---|
package.json with React | React |
package.json with Vue | Vue |
package.json with Next.js | Next.js |
package.json (generic) | JavaScript/Node.js |
requirements.txt or pyproject.toml | Python |
Cargo.toml | Rust |
go.mod | Go |
Relevant Files Auto-Selection
Based on project type, agents focus on: JavaScript/React/Vue/Next.js:src/lib/components/pages/api/routes/
*.pysrc/app/api/
src/Cargo.toml
*.gocmd/internal/pkg/
Advanced Usage
Explicit File Selection
Specify files or directories explicitly:Examples
Disable Auto-Detection
Disable project context auto-detection:Verbose Mode
Enable detailed debugging output:- User input
- Project context detection
- Final prompt length
- System prompt preview
- Claude command being executed
Help Command
View agent-specific help:- Usage syntax
- Context options
- Examples
Global Agent Options
The prompt to send to the agent
Include specific file in context (can be used multiple times)
Include specific directory in context (can be used multiple times)
Disable automatic project context detection
Enable verbose debugging output (alias: -v)
Display help information (alias: -h)
Managing Global Agents
List Installed Agents
View all installed global agents:- Agent name
- Installation location (system/user)
- Executable status
- Creation date
- Usage examples
Update an Agent
Update to the latest version:Remove an Agent
Delete a global agent:- Executable script from
/usr/local/bin/or user bin - Agent file from
~/.claude-code-templates/agents/
PATH Configuration
System Installation
If installed to/usr/local/bin/, agents are immediately available with no setup required.
User Installation
If installed to~/.claude-code-templates/bin/, add to PATH:
Bash (~/.bashrc or ~/.bash_profile):
~/.zshrc):
~/.config/fish/config.fish):
Apply Changes
Reload your shell configuration:Verify PATH
Check if PATH is configured correctly:Use Cases
1. Customer Support
2. Code Review Automation
3. Documentation Generation
4. npm Scripts Integration
Add topackage.json:
5. CI/CD Integration
GitHub Actions (.github/workflows/review.yml):
6. Shell Aliases
Create convenient aliases:Technical Details
Executable Script Structure
Global agents are Node.js executable scripts that:- Read agent system prompt from
~/.claude-code-templates/agents/<name>.md - Parse command-line arguments (prompt, files, options)
- Detect project context automatically
- Build final prompt combining user input and context
- Execute Claude CLI with agent’s system prompt
- Stream response to terminal
Claude CLI Requirements
Global agents require Claude CLI:Authentication
Global agents use your existing Claude authentication:- OAuth authentication from Claude Desktop
ANTHROPIC_API_KEYenvironment variable- API key in
~/.claude.json
System Prompt Handling
Agents use the--system-prompt flag to provide their specialized instructions:
Troubleshooting
Agent Not Found After Creation
Check PATH configuration:Claude CLI Not Found
Install Claude CLI:Permission Denied (macOS/Linux)
Make executable:Authentication Errors
Check Claude authentication:~/.claude.json:
Windows Issues
Use PowerShell or Command Prompt:- Open System Properties > Environment Variables
- Add
%USERPROFILE%\.claude-code-templates\binto PATH
Best Practices
- Use descriptive names:
customer-support, notcs - Create specialized agents: Focus on specific tasks
- Test with
--verbose: Understand how agents work - Document for teams: Share agent names and purposes
- Use in scripts: Automate repetitive tasks
- Update regularly: Keep agents current with
--update-agent - Leverage context: Let agents auto-detect project types
- Combine with hooks: Integrate into development workflow
Next Steps
- List and Manage Agents - Manage installed global agents
- Install Components - Install project-specific agents
- CLI Flags Reference - Complete flags documentation
- Environment Variables - Configure authentication