Skip to main content

Advanced Workflow Mechanics

Master complex development workflows with Claude Code's advanced features for reasoning, context management, and automation.

UltraThink Reasoning Mode

Enhanced reasoning capabilities for complex problem solving.

Activation

# Enable UltraThink for current session
claude-code --ultra-think

# Enable for specific queries
claude-code --think-mode=ultra "Design a microservices architecture"

Reasoning Patterns

Multi-Perspective Analysis

You: How should we handle user authentication?

UltraThink: Analyzing authentication approaches...

Security Perspective:
- JWT tokens provide stateless auth
- OAuth2 for third-party integration
- MFA for sensitive operations

Performance Perspective:
- Token validation overhead
- Session storage considerations
- Caching strategies

Developer Experience Perspective:
- Simple integration APIs
- Clear error messages
- Debugging capabilities

Recommendation: JWT + OAuth2 hybrid approach

Step-by-Step Problem Solving

You: Our API is slow under load

UltraThink: Breaking down performance analysis...

Step 1: Identify bottlenecks
- Database query patterns
- Network latency
- CPU utilization

Step 2: Measure impact
- Response time metrics
- Throughput analysis
- Error rate tracking

Step 3: Optimization strategies
- Query optimization
- Caching layers
- Load balancing

Step 4: Implementation plan
- Priority-based rollout
- A/B testing approach
- Rollback procedures

Reasoning Modes

Deep Analysis Mode

claude-code --think-mode=deep "Analyze this codebase architecture"

Provides:

  • Comprehensive system analysis
  • Architecture pattern identification
  • Technical debt assessment
  • Improvement recommendations

Fast Decision Mode

claude-code --think-mode=fast "Choose between React and Vue"

Provides:

  • Quick comparative analysis
  • Pros/cons summary
  • Contextual recommendations

Context Window Optimization

Intelligent Context Management

Claude Code automatically optimizes context usage:

Session Context (8k tokens):
├── Current conversation (2k tokens)
├── Relevant file contents (3k tokens)
├── Project structure (1k tokens)
├── Recent changes (1k tokens)
└── Framework knowledge (1k tokens)

Context Strategies

Hierarchical Context

Level 1: Immediate context (current files, recent messages)
Level 2: Project context (structure, dependencies, configs)
Level 3: Domain context (frameworks, patterns, best practices)
Level 4: Historical context (previous sessions, learnings)

Context Compression

# Enable context compression
claude-code --compress-context

# Manual context reset
claude-code --reset-context

# Context usage stats
claude-code --context-stats

Memory Management Strategies

Selective Memory

{
"memory": {
"retain": [
"project-structure",
"coding-conventions",
"team-preferences"
],
"compress": [
"detailed-implementations",
"verbose-outputs"
],
"discard": [
"temporary-calculations",
"debug-information"
]
}
}

Session Continuity

# Save session state
claude-code --save-session my-project-work

# Resume session
claude-code --resume-session my-project-work

# List saved sessions
claude-code --list-sessions

Token Management Techniques

Efficient Tool Usage

Batch Operations

// Good: Batch file operations
const files = ['src/components/A.tsx', 'src/components/B.tsx'];
readMultipleFiles(files);

// Avoid: Individual operations
files.forEach(file => readFile(file));

Strategic Tool Selection

# For specific files: Use Read tool
claude-code read src/components/Button.tsx

# For pattern matching: Use Grep tool
claude-code grep "useState" --type=tsx

# For open-ended search: Use Task tool
claude-code task "Find all authentication-related code"

Context-Aware Responses

Abbreviated Responses

{
"response_style": {
"verbosity": "minimal",
"code_comments": false,
"explanations": "on_request",
"summaries": "brief"
}
}

Progressive Disclosure

Initial Response: Brief solution outline
User Follow-up: Detailed implementation
User Request: Complete code examples

Workflow Automation Patterns

CI/CD Integration

# .github/workflows/claude-integration.yml
name: Claude Code Integration

on: [push, pull_request]

jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Claude Code Review
run: |
claude-code review \
--agent=code-reviewer \
--format=github-comments \
--files=$(git diff --name-only)

Development Environment Setup

#!/bin/bash
# .claude/setup.sh

echo "🔧 Setting up development environment..."

# Install dependencies
npm install

# Setup database
docker-compose up -d postgres
npm run db:migrate

# Configure environment
cp .env.example .env
echo "DATABASE_URL=postgresql://localhost/myapp" >> .env

# Setup git hooks
npx husky install
npx husky add .husky/pre-commit "claude-code hooks run pre-commit"

echo "✅ Environment ready"

Automated Code Review

{
"workflows": {
"code-review": {
"trigger": "git-commit",
"agents": ["code-reviewer", "security-auditor"],
"checks": [
"style-consistency",
"security-vulnerabilities",
"performance-issues",
"test-coverage"
],
"reporting": {
"format": "markdown",
"destination": "review-comments.md"
}
}
}
}

Performance Optimization Workflows

Automated Performance Testing

#!/bin/bash
# scripts/performance-test.sh

echo "🏃 Running performance tests..."

# Start application
npm run start:test &
APP_PID=$!

# Wait for startup
sleep 10

# Run load tests
npx autocannon http://localhost:3000 \
--connections 100 \
--duration 60 \
--latency

# Performance regression check
npm run test:performance

# Cleanup
kill $APP_PID

Bundle Analysis

{
"hooks": {
"build-complete": [
"npm run analyze-bundle",
"check-bundle-size.sh",
"generate-performance-report.sh"
]
}
}

Complex Workflow Examples

Full Feature Development

# Multi-step feature development workflow
claude-code workflow run feature-development \
--feature="user-notifications" \
--agents="architect,test-engineer,reviewer" \
--stages="design,implement,test,review,deploy"

Automated steps:

  1. Design: Architecture agent creates system design
  2. Implement: Code generation with best practices
  3. Test: Test engineer creates comprehensive test suite
  4. Review: Code reviewer validates implementation
  5. Deploy: DevOps automator handles deployment

Microservice Development

#!/bin/bash
# workflows/microservice.sh

SERVICE_NAME="$1"
echo "🏗️ Creating microservice: $SERVICE_NAME"

# Generate service structure
claude-setup generate microservice \
--name="$SERVICE_NAME" \
--database=postgresql \
--api=graphql

# Setup testing
claude-testing init \
--framework=jest \
--coverage=90 \
--integration=true

# Configure deployment
claude-devops setup \
--container=docker \
--orchestration=kubernetes \
--monitoring=prometheus

# Initialize repository
git init
git add .
git commit -m "feat: initialize $SERVICE_NAME microservice

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>"

echo "✅ Microservice $SERVICE_NAME ready for development"

Workflow Debugging

Debug Commands

# Debug workflow execution
claude-code workflow debug feature-development

# Workflow performance profiling
claude-code workflow profile --session-id=abc123

# Step-by-step execution
claude-code workflow run --step-mode feature-development

Workflow Logs

# View workflow logs
claude-code workflow logs

# Filter by workflow type
claude-code workflow logs --type=deployment

# Real-time monitoring
claude-code workflow logs --follow --level=debug

Custom Workflow Creation

Workflow Definition

// workflows/custom-deployment.ts
export const customDeployment = {
name: 'custom-deployment',
description: 'Custom deployment workflow for our stack',

steps: [
{
name: 'pre-flight-checks',
agent: 'devops-automator',
task: 'Validate deployment readiness',
required: true
},
{
name: 'build-and-test',
parallel: [
{ task: 'npm run build', timeout: 300000 },
{ task: 'npm run test:ci', timeout: 600000 }
]
},
{
name: 'deploy',
agent: 'deployment-specialist',
task: 'Deploy to production environment',
approval_required: true
},
{
name: 'post-deployment',
tasks: [
'run smoke tests',
'update monitoring dashboards',
'notify stakeholders'
]
}
]
};

Workflow Registration

# Register custom workflow
claude-code workflow register ./workflows/custom-deployment.ts

# List available workflows
claude-code workflow list

# Run custom workflow
claude-code workflow run custom-deployment

Best Practices

1. Workflow Design

  • Clear Stages: Define distinct workflow phases
  • Error Handling: Plan for failure scenarios
  • Rollback Procedures: Enable quick recovery
  • Monitoring: Track workflow execution

2. Context Management

  • Minimize Context: Only include relevant information
  • Session Planning: Structure conversations efficiently
  • Memory Optimization: Use appropriate retention policies

3. Performance

  • Parallel Execution: Run independent tasks concurrently
  • Caching: Cache expensive operations
  • Early Termination: Stop on critical failures
  • Resource Limits: Set appropriate timeouts

4. Team Collaboration

  • Shared Workflows: Standardize team processes
  • Documentation: Document custom workflows
  • Version Control: Track workflow changes
  • Training: Ensure team understanding

Troubleshooting

Common Issues

  1. Context Overflow: Reduce conversation length or reset context
  2. Slow Workflows: Optimize expensive operations
  3. Hook Failures: Check script permissions and dependencies
  4. Memory Issues: Adjust retention policies

Performance Monitoring

# Workflow performance metrics
claude-code metrics workflows

# Context usage analysis
claude-code metrics context

# Hook execution times
claude-code metrics hooks

Next Steps