Usage Examples

Real-world examples of using ask in your daily workflow.

Quick Queries

Basic Questions

# Simple questions
ask "what's the difference between TCP and UDP?"

# Code explanations
ask "explain what this regex does: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"

# Best practices
ask "what's the best way to handle errors in bash scripts?"

With Piped Input

# Analyze logs
tail -100 /var/log/nginx/access.log | ask "summarize the traffic patterns"

# Debug errors
cat error.log | ask "what's causing these errors and how to fix?"

# Process data
ps aux | ask "what processes are using the most memory?"

With Custom System Prompts

# Security expert persona
ask --system "You are a security expert" "review this code for vulnerabilities" < auth.py

# Database performance expert
ask --system "You are a database performance expert" "optimize this SQL query"

# Technical writer
ask --system "You are a technical documentation writer" "document this API" < routes.js

Temperature Control

# Creative writing (higher temperature = more creative)
ask -t 1.5 "write a creative story about a developer"

# Deterministic output (lower temperature = more focused)
ask -t 0.1 "extract structured data from this JSON" < data.json

# Balanced (default is 1.0)
ask -t 1.0 "explain how async/await works"

JSON Output

# For programmatic use
ask --json --no-stream "list top 3 security practices" | jq -r '.content[0].text'

# Batch processing
for file in *.log; do
  errors=$(ask --json --no-stream "count error lines" < "$file" | jq -r '.count')
  echo "$file: $errors errors"
done

Multi-line Input

# Complex queries across multiple lines
ask --multiline <<'EOF'
Given this error stack trace, explain:
1. Root cause
2. How to fix
3. How to prevent

[paste stack trace here]
EOF

Shell & System Administration

File Operations

# Find files intelligently
ask "find all javascript files modified in the last week"

# Analyze disk usage
du -sh * | ask "which directories should I clean up first?"

# Permission issues
ask "why can't I write to this directory?" --context full

Process Management

# Debug hanging processes
ps aux | grep myapp | ask "is this process stuck?"

# Resource monitoring
top -bn1 | ask "diagnose performance issues"

# Kill processes safely
ask --agent "kill all zombie processes"

Networking

# Test connectivity
ping -c 5 google.com | ask "analyze the connection quality"

# Port debugging
netstat -tulpn | ask "which service is using port 8080?"

# SSL certificates
openssl s_client -connect example.com:443 | ask "when does this cert expire?"

Development Workflows

Git Workflows

# Smart commits (requires staged changes)
git add .
ask commit
# Generates: "feat(api): add user authentication endpoint"

# Review changes
git diff main..feature | ask "review this PR for issues"

# PR review command
git checkout feature-branch
ask pr-review
# Reviews current branch against main

# Find commits
git log --oneline | ask "find the commit that added authentication"

Code Review

# Review specific file
git diff main src/auth.js | ask "security review this authentication code"

# Find bugs
cat bug_report.txt | ask "what's the root cause?" --context full

# With security expert
ask --system "You are a security auditor" "find vulnerabilities" < app.py

Testing

# Generate tests
ask --fn test_user_login "create pytest tests for user login function"

# Debug test failures
pytest -v | ask "why are these tests failing?"

# Coverage analysis
coverage report | ask "what critical paths are missing tests?"

Debugging

# Diagnose last command failure
make build
# [build fails]
ask diagnose

# With full context
npm test
# [tests fail]
ask --context full diagnose

Agent Mode

Basic Agent Usage

# Simple task
ask --agent "create a backup directory with today's date"

# Auto-approve low/medium risk (recommended)
ask --agent "organize files by type"
# Type 'a' when prompted to auto-approve safe commands

# Dry run (show plan without executing)
ask --agent --dry-run "delete old log files"

File Management

ask --agent "organize these files by file type into subdirectories"
ask --agent "find and remove files larger than 100MB not modified in 30 days"
ask --agent "create timestamped backup of all .conf files"
ask --agent --dry-run "rename all JPEG files to lowercase"

Docker Operations

ask --agent "remove all stopped containers and unused images"
ask --agent "restart unhealthy containers"
ask --agent "find containers using more than 1GB RAM"
ask --agent --tools "docker" "cleanup unused volumes"

Restricted Agent Tools

# Only allow specific tools
ask --agent --tools "curl,jq" "fetch and parse this API endpoint"

# Git-only operations
ask --agent --tools "git" "create feature branch and initial commit"

# Safe read-only tools
ask --agent --tools "cat,grep,find" "analyze log patterns"

Function Generation

Basic Function Generation

# Generate a function
ask --fn parse_nginx "extract 500 errors from nginx access logs"

# ask will:
# 1. Generate the function
# 2. Validate syntax
# 3. Show preview
# 4. Ask: Save? (y/n/e to edit)

Log Parsing Functions

ask --fn parse_nginx_errors "extract all 500 errors with timestamp and URL"
ask --fn find_slow_queries "find SQL queries taking more than 1 second"
ask --fn tail_errors "tail system logs and highlight errors in red"
ask --fn parse_json_logs "parse and pretty-print JSON log entries"

Using Generated Functions

# Source the functions file
source ~/.config/ask/functions.sh

# Now use your functions
parse_nginx_errors /var/log/nginx/access.log
csv_unique data.csv email
git_clean_branches

# Add to .bashrc for permanent use
echo 'source ~/.config/ask/functions.sh' >> ~/.bashrc

Interactive Mode

Starting Interactive Mode

# Start interactive session
ask

# You'll see the banner and prompt
ask> your question here

Interactive Commands

ask> /clear     # Clear conversation history
ask> /save      # Save conversation
ask> /load      # Load previous conversation
ask> /models    # List available models
ask> /switch openai gpt-4o  # Switch provider/model
ask> /context full          # Change context level
ask> /help      # Show help
ask> /exit      # Exit

Data Analysis

CSV Files

cat sales.csv | ask "what are the top 5 products by revenue?"
cat metrics.csv | ask "detect any unusual patterns in this data"
cat data.csv | ask "create a summary report with key insights"

JSON Processing

cat api_response.json | ask "extract all user emails where status is active"
ask "is this valid JSON and what structure does it have?" < data.json
cat input.json | ask "convert this to CSV format"

Log Analysis

cat app.log | ask "group errors by type and show frequency"
cat access.log | ask "calculate average response time by endpoint"
cat auth.log | ask "find suspicious login attempts"

Security & Compliance

Security Checks

ask --agent "find files with world-writable permissions"
ask "check if these passwords meet security requirements" < passwords.txt
npm audit | ask "prioritize these vulnerabilities by severity"
ask --system "You are a security expert" "audit this code" < app.py

Compliance

ask "scan this code for GDPR compliance issues" < user_service.py
ask --agent "list all open source licenses in node_modules"
ask --agent "scan for exposed API keys or credentials"

DevOps & CI/CD

Kubernetes

kubectl get pods | ask "which pods are crashlooping?"
kubectl top nodes | ask "which node is overutilized?"
kubectl logs -f mypod | ask "alert me to errors in real-time"
kubectl get deployment myapp -o yaml | ask "check for security issues"

CI/CD Debugging

ask "why did this build fail?" < build.log
ask --context full "debug this deployment failure"
ask "compare these benchmark results" < benchmarks.txt
ask --json --no-stream "extract failure reason" < ci.log | jq -r '.reason'

Infrastructure

terraform plan | ask "explain these changes in plain English"
ask "convert this bash script to an Ansible playbook" < deploy.sh
ask "review this nginx config for security issues" < nginx.conf

Advanced Usage

Combining Multiple Features

# Expert persona + full context + agent mode
ask --system "You are a DevOps expert" \
    --context full \
    --agent \
    "set up monitoring for this service"

# JSON output + no streaming for scripting
ask --json --no-stream \
    --system "You are a data analyst" \
    "summarize key metrics" < metrics.csv | jq

Configuration & Environment

# Set default provider
export ASK_PROVIDER=openai
ask "your question"  # Uses OpenAI

# Set default model
export ASK_MODEL=gpt-4o

# Temporary override
ASK_MODEL=gpt-4o-mini ask "quick question"

Pro Tips

Context Awareness

ask --context min "quick question"     # Fast, minimal context
ask --context auto "debug this"        # Balanced (default)
ask --context full "complex analysis"  # Maximum context

Chaining Commands

git diff | ask "summarize changes" | ask "suggest commit message"
find . -name "*.js" | xargs cat | ask "find code smells"

Model Selection

ask -m gpt-4o-mini "quick question"        # Fast & cheap
ask -m claude-opus-4 "design architecture"  # Powerful
ask --list-models                            # List all

Learning & Documentation

Explain Commands

ask "explain: find . -type f -name '*.log' -mtime +30 -delete"
ask "how does parameter expansion work in bash?"
ask "explain grep options with examples"

Generate Documentation

cat myfunction.py | ask "generate docstring for this function"
ask "create a README for this project" --context full
ask "document this REST API" < api_routes.js

Daily Workflows

Morning Routine

ask --context full "daily system health check"
git status | ask "summarize what I was working on"
ask "based on my recent commits, what should I focus on today?"

Code Review Workflow

git diff main..feature > /tmp/pr.diff
ask --system "You are a senior code reviewer" "review this PR" < /tmp/pr.diff
ask --system "You are a security expert" "security review" < /tmp/pr.diff
ask "suggest test cases for this PR" < /tmp/pr.diff

Debugging Workflow

./myapp 2>&1 | tee error.log
ask "what's wrong?" < error.log
ask --context full "debug this error"
ask --agent --dry-run "fix this issue"
ask --agent "fix this issue"

Key Management

First Time Setup

ask keys set anthropic
ask keys set openai
ask keys set openrouter
ask keys list

Managing Multiple Keys

ask keys list
ask keys remove openai
ask keys path
ANTHROPIC_API_KEY='different-key' ask "test query"

Troubleshooting

Command Not Found

which ask
echo $PATH
export PATH="$HOME/.local/bin:$PATH"

API Key Issues

ask keys list
ask keys set anthropic
ask "test"

Streaming Issues

ask -n "your query"
export ASK_STREAM=false

Performance Issues

ask --context min "quick question"
ask -m gpt-4o-mini "simple task"
ask -n "query"

More Examples?

Share yours! Open a PR or discussion on GitHub.

Need help? Just ask:
ask "how do I use ask effectively?"

Repository: github.com/elias-ba/ask

don't grep. don't awk. just ask