Skip to content

task tool examples

hbt edited this page Jul 3, 2025 · 1 revision

Claude Code Task Tool Examples

The Task tool launches specialized agents for complex search and research operations. Here are practical examples of how to use it effectively.

Basic Search Examples

Finding Configuration Files

Description: Find config files
Prompt: Search for all configuration files in this codebase. Look for files with names like config, settings, env, or similar. Include files with extensions like .json, .yaml, .toml, .ini, .env. Return the file paths and describe what type of configuration each file handles.

Locating Authentication Logic

Description: Find auth implementation
Prompt: Find all files related to user authentication and authorization in this codebase. Search for keywords like 'auth', 'login', 'token', 'session', 'jwt', 'oauth', 'permission', 'role'. Return file paths with brief descriptions of what authentication/authorization functionality each file implements.

Database Integration Discovery

Description: Find database code
Prompt: Locate all database-related code and configuration. Search for database connections, models, migrations, and queries. Look for keywords like 'db', 'database', 'sql', 'mongo', 'redis', 'connection', 'model', 'schema', 'migration'. Return organized results showing database setup, models, and query logic.

Advanced Research Examples

Framework Analysis

Description: Analyze framework usage  
Prompt: Analyze what frameworks and libraries this codebase uses. Examine package.json, requirements.txt, Cargo.toml, or similar dependency files. Also look at import statements in source files. Provide a comprehensive overview of:
1. Main frameworks (React, Express, Django, etc.)
2. Key libraries and their purposes
3. Development vs production dependencies
4. Any custom or unusual dependencies
Return this as a structured analysis with categories.

Error Handling Patterns

Description: Find error handling
Prompt: Research how errors are handled throughout this codebase. Look for:
1. Try-catch blocks and error handling patterns
2. Custom error classes or types
3. Logging and error reporting
4. Validation and input sanitization
5. API error responses
Analyze the consistency of error handling approaches and identify the main patterns used. Return examples of each pattern found.

API Endpoint Discovery

Description: Map API endpoints
Prompt: Find and catalog all API endpoints in this codebase. Look for route definitions, controller methods, and API handlers. Search for patterns like app.get, router.post, @app.route, or similar routing syntax. For each endpoint found, provide:
1. HTTP method and path
2. File location (file:line)
3. Brief description of functionality
4. Required parameters or body structure if apparent
Organize results by HTTP method and functionality area.

Concurrent Agent Examples

Multi-Aspect Codebase Analysis

Launch multiple agents simultaneously for comprehensive analysis:

Agent 1 - Architecture Overview:

Description: Analyze architecture
Prompt: Analyze the overall architecture and structure of this codebase. Examine directory structure, main entry points, and how different modules connect. Identify if it follows MVC, microservices, or other architectural patterns. Provide a high-level overview of the system design.

Agent 2 - Testing Strategy:

Description: Find test patterns
Prompt: Research the testing approach used in this codebase. Find test files, test configuration, and testing frameworks. Look for unit tests, integration tests, and end-to-end tests. Analyze test coverage and testing patterns. Identify the main testing tools and strategies employed.

Agent 3 - Security Implementation:

Description: Security analysis
Prompt: Examine security implementations in this codebase. Look for authentication, authorization, input validation, CSRF protection, encryption, and other security measures. Find security-related middleware, validators, and protective mechanisms. Identify potential security patterns and configurations.

Complex Investigation Examples

Performance Bottleneck Research

Description: Find performance issues
Prompt: Investigate potential performance bottlenecks in this codebase. Look for:
1. Database queries that might be inefficient (N+1 problems, missing indexes)
2. Large data processing operations
3. Synchronous operations that could be asynchronous
4. Memory-intensive operations
5. API calls without proper caching
6. Heavy computational logic in request handlers
Search through the codebase and identify files/functions that might impact performance. Provide specific examples with file:line references.

Dependency Analysis

Description: Analyze dependencies
Prompt: Perform a comprehensive dependency analysis. Research:
1. Direct vs transitive dependencies
2. Outdated packages and security vulnerabilities
3. Heavy dependencies that might bloat the application
4. Duplicate functionality across different packages
5. Development-only dependencies in production builds
Examine package files and usage patterns throughout the codebase. Identify optimization opportunities and potential issues.

Migration Preparation

Description: Prepare for migration
Prompt: Analyze this codebase for migration to [target framework/version]. Identify:
1. Deprecated APIs and methods that need updating
2. Breaking changes that will affect the code
3. Third-party packages that need updates
4. Custom code that relies on old patterns
5. Configuration changes required
Provide a detailed migration assessment with specific file locations and recommended changes for each issue found.

Best Practices

Effective Prompt Writing

  1. Be Specific: Include exact keywords and file types to search for
  2. Provide Context: Explain what you're trying to accomplish
  3. Request Structure: Ask for organized results with file paths and line numbers
  4. Include Examples: Mention specific patterns to look for
  5. Set Scope: Define boundaries for the search

When to Use Multiple Agents

  • Large Codebases: Break analysis into logical areas
  • Time Constraints: Parallel research for faster results
  • Different Perspectives: Architecture, security, performance, etc.
  • Comprehensive Audits: Full codebase analysis from multiple angles

Agent Communication

Remember that agents are stateless and cannot communicate with each other. Design prompts to be completely self-contained with all necessary context.

Common Anti-Patterns

❌ Don't Use Task Tool For:

  • Reading specific known file paths (use Read tool)
  • Simple grep operations (use Grep tool)
  • Writing or modifying code
  • Single-file analysis
  • Interactive workflows requiring follow-up questions

✅ Do Use Task Tool For:

  • Open-ended codebase exploration
  • Multi-file research requiring judgment
  • Pattern discovery across unknown file structures
  • Complex analysis requiring multiple search strategies
  • Initial codebase understanding before making changes

Integration with Other Tools

The Task tool works best as the first step in a workflow:

  1. Task Tool: Research and discover relevant files
  2. Read Tool: Examine specific files identified by agents
  3. Edit/Write Tools: Make informed changes based on research
  4. Grep/Glob Tools: Follow up with targeted searches

This approach maximizes efficiency by using each tool for its optimal purpose.

Clone this wiki locally