Skip to main content
Run Gammacode programmatically without interactive UI

Overview

The headless mode allows you to run Gammacode programmatically from command line scripts and automation tools without any interactive UI.

Basic usage

The primary command-line interface to Gammacode is the gammacode run command:
gammacode run "Stage my changes and write a set of commits for them"

Configuration Options

Headless mode leverages all the CLI options available in Gammacode. Here are the key ones for automation and scripting:
FlagDescriptionExample
message..Message to send (positional arguments)gammacode run "analyze this code"
--commandThe command to run, use message for argsgammacode run --command "analyze" "this code"
-c, --continueContinue the last sessiongammacode run --continue "now optimize it"
-s, --sessionSession id to continuegammacode run --session abc123 "update tests"
-m, --modelModel to use in the format of provider/modelgammacode run --model "anthropic/claude-3-sonnet" "review code"
--agentAgent to usegammacode run --agent security-analyzer "check for vulnerabilities"
--formatFormat: default (formatted) or json (raw JSON events)gammacode run --format json "analyze performance"
-v, --versionShow version numbergammacode run --version
--helpShow helpgammacode run --help

Multi-turn conversations

For multi-turn conversations, you can resume conversations or continue from the most recent session:
# Continue the most recent conversation
gammacode run --continue "Now refactor this for better performance"

# Resume a specific conversation by session ID
gammacode run --session 550e8400-e29b-41d4-a716-446655440000 "Update the tests"

# Use a specific model for the conversation
gammacode run --model "anthropic/claude-3-opus" "Perform detailed code analysis"

Output Formats

Default Output

gammacode run "Explain file src/components/Header.tsx"
# Output: This is a React component showing...

JSON Output

Returns structured data including metadata:
gammacode run --format json "How does the data layer work?"
Response format includes raw JSON events from the conversation.

Agent Integration Examples

SRE Incident Response Bot

#!/bin/bash
# Automated incident response agent

investigate_incident() {
    local incident_description="$1"
    local severity="${2:-medium}"
    
    gammacode run --agent sre-incident-responder \
      --format json \
      "Incident: $incident_description (Severity: $severity). Diagnose the issue, assess impact, and provide immediate action items."
}

# Usage
investigate_incident "Payment API returning 500 errors" "high"

Automated Security Review

# Security audit agent for pull requests
audit_pr() {
    local pr_number="$1"
    
    gh pr diff "$pr_number" | gammacode run --agent security-reviewer \
      --format json \
      "Review this PR for vulnerabilities, insecure patterns, and compliance issues."
}

# Usage and save to file
audit_pr 123 > security-report.json
# Legal document review with session persistence

# Start initial review and capture session ID
session_output=$(gammacode run --format json "Start legal review session for contract.pdf")
session_id=$(echo "$session_output" | jq -r '.session_id')

# Review contract in multiple steps
gammacode run --session "$session_id" "Review contract.pdf for liability clauses"
gammacode run --session "$session_id" "Check compliance with GDPR requirements"  
gammacode run --session "$session_id" "Generate executive summary of risks"

Specialized Agent Usage

Using specific agents for tasks

# Use a code reviewer agent
gammacode run --agent code-reviewer "Review my recent changes for security issues"

# Use a data analysis agent  
gammacode run --agent data-scientist "Analyze user engagement trends from analytics.csv"

# Use a debugging agent
gammacode run --agent debugger "Investigate why the login function is failing"

Best Practices

  • Use JSON output format for programmatic parsing of responses:
    # Parse JSON response with jq
    result=$(gammacode run --format json "Generate code")
    # Process the JSON events as needed
    
  • Handle errors gracefully - check exit codes and stderr:
    if ! gammacode run "$prompt" 2>error.log; then
        echo "Error occurred:" >&2
        cat error.log >&2
        exit 1
    fi
    
  • Use session management for maintaining context in multi-turn conversations
  • Leverage specialized agents for domain-specific tasks to get better results
  • Consider timeouts for long-running operations:
    timeout 300 gammacode run "$complex_prompt" || echo "Timed out after 5 minutes"
    
  • Respect rate limits when making multiple requests by adding delays between calls

Command Examples

Basic Analysis

# Analyze a specific file
gammacode run "Analyze the performance of src/utils/database.js"

# Review recent git changes
gammacode run "Review my staged changes for any issues"

Using Different Models

# Use a specific model for complex analysis
gammacode run --model "anthropic/claude-3-opus" "Perform comprehensive security audit"

# Use a faster model for simple tasks
gammacode run --model "anthropic/claude-3-haiku" "Fix syntax errors in this file"

Session Management

# Start a new conversation and continue it
gammacode run "Let's work on optimizing our API"
gammacode run --continue "Now let's add caching to the database queries"
gammacode run --continue "Finally, let's update the documentation"

Integration with Development Workflows

Pre-commit Hooks

#!/bin/sh
# .git/hooks/pre-commit
gammacode run --agent security-reviewer "Review staged changes for security issues"

CI/CD Pipeline Integration

# In your CI pipeline
gammacode run --format json "Analyze test coverage and suggest improvements" > coverage-analysis.json

Automated Code Review

# Review pull request changes
git diff main...HEAD | gammacode run --agent code-reviewer "Review these changes for quality and best practices"

Next steps

I