Skip to main content

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):
User Directory (fallback, requires PATH setup):
Agent files are stored at:

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:

Relevant Files Auto-Selection

Based on project type, agents focus on: JavaScript/React/Vue/Next.js:
  • src/
  • lib/
  • components/
  • pages/
  • api/
  • routes/
Python:
  • *.py
  • src/
  • app/
  • api/
Rust:
  • src/
  • Cargo.toml
Go:
  • *.go
  • cmd/
  • internal/
  • pkg/

Advanced Usage

Explicit File Selection

Specify files or directories explicitly:

Examples

Disable Auto-Detection

Disable project context auto-detection:
Useful for general questions without project context:

Verbose Mode

Enable detailed debugging output:
Shows:
  • User input
  • Project context detection
  • Final prompt length
  • System prompt preview
  • Claude command being executed

Help Command

View agent-specific help:
Displays:
  • Usage syntax
  • Context options
  • Examples

Global Agent Options

string
required
The prompt to send to the agent
string
Include specific file in context (can be used multiple times)
string
Include specific directory in context (can be used multiple times)
boolean
Disable automatic project context detection
boolean
Enable verbose debugging output (alias: -v)
boolean
Display help information (alias: -h)

Managing Global Agents

List Installed Agents

View all installed global agents:
Output includes:
  • Agent name
  • Installation location (system/user)
  • Executable status
  • Creation date
  • Usage examples

Update an Agent

Update to the latest version:
This re-downloads the agent from GitHub and updates the executable.

Remove an Agent

Delete a global agent:
Removes:
  • 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):
Zsh (~/.zshrc):
Fish (~/.config/fish/config.fish):

Apply Changes

Reload your shell configuration:
Or restart your terminal.

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 to package.json:
Run with:

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:
  1. Read agent system prompt from ~/.claude-code-templates/agents/<name>.md
  2. Parse command-line arguments (prompt, files, options)
  3. Detect project context automatically
  4. Build final prompt combining user input and context
  5. Execute Claude CLI with agent’s system prompt
  6. 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_KEY environment variable
  • API key in ~/.claude.json

System Prompt Handling

Agents use the --system-prompt flag to provide their specialized instructions:
This ensures the agent’s expertise is applied to every request.

Troubleshooting

Agent Not Found After Creation

Check PATH configuration:
Try full path:
Verify executable permissions:

Claude CLI Not Found

Install Claude CLI:
Verify installation:

Permission Denied (macOS/Linux)

Make executable:
For system directory:

Authentication Errors

Check Claude authentication:
Set API key if needed:
Or configure in ~/.claude.json:

Windows Issues

Use PowerShell or Command Prompt:
Or add to System Environment Variables:
  1. Open System Properties > Environment Variables
  2. Add %USERPROFILE%\.claude-code-templates\bin to PATH

Best Practices

  1. Use descriptive names: customer-support, not cs
  2. Create specialized agents: Focus on specific tasks
  3. Test with --verbose: Understand how agents work
  4. Document for teams: Share agent names and purposes
  5. Use in scripts: Automate repetitive tasks
  6. Update regularly: Keep agents current with --update-agent
  7. Leverage context: Let agents auto-detect project types
  8. Combine with hooks: Integrate into development workflow

Next Steps