Code review

Autohand can review pull requests, staged changes, or individual files. It catches bugs, highlights security concerns, and suggests improvements. You can run reviews interactively in your terminal or pipe diffs directly for quick feedback.

Autohand reviewing a pull request and highlighting issues in the diff

Review a pull request

Pipe the diff from your current branch into Autohand for a full review:

# Review all changes between your branch and main
git diff main...HEAD | autohand --prompt "Review this diff for bugs, performance issues, and security concerns"

Review staged changes before committing

Catch problems before they land in your commit history:

# Review only what you're about to commit
git diff --staged | autohand --prompt "Review these staged changes. Flag anything that looks wrong."

Review a specific file

Focus the review on one file when you need targeted feedback:

# Review a single file in depth
autohand "Review src/auth/middleware.ts for security issues and edge cases"

Interactive review session

Start Autohand without a prompt to have a back-and-forth conversation about your code:

# Open an interactive session and ask follow-up questions
autohand
> Review the authentication flow in src/auth/ and explain any weaknesses
> What would happen if the token expires mid-request?
> Show me how to fix that

Structured review output

Get your review results in a format that is easy to parse or post as a PR comment:

# Output as structured markdown
git diff main...HEAD | autohand --prompt "Review this diff. Format output as:
## Summary
## Issues Found (with severity: critical/high/medium/low)
## Suggestions"

Bug fixing

When something breaks, Autohand can trace the issue, analyze error output, and suggest fixes. Feed it test failures, stack traces, or error logs, and it will walk you through the root cause.

Autohand debugging a failing test and tracing the error to its source

Debug a failing test

Pipe your test output directly into Autohand to get an analysis:

# Run tests and pipe failures for analysis
npm test 2>&1 | autohand --prompt "Analyze these test failures. Identify the root cause and suggest a fix."

Trace an error from a stack trace

Paste or pipe an error message and let Autohand trace it through your codebase:

# Investigate a production error
autohand "I'm seeing this error in production:
TypeError: Cannot read properties of undefined (reading 'userId')
  at processOrder (src/orders/handler.ts:45:23)
  at async handleCheckout (src/checkout/flow.ts:112:5)
Trace this through the code and tell me what's happening."

Fix a regression

When a feature that used to work stops working, compare the current state with a known good commit:

# Compare current code against last working version
git diff v2.3.1..HEAD -- src/payments/ | autohand --prompt "Something broke in the payments module since v2.3.1. Identify what changed and what likely caused the regression."

Fix and apply in one step

Let Autohand both find and fix the bug:

# Auto-fix with confirmation
autohand --yes "The login form throws a 500 error when the email field is empty. Find the bug and fix it."

Feature development

Autohand helps you move from idea to implementation faster. It can scaffold components, build from a spec document, and fill in boilerplate so you can focus on the logic that matters.

Autohand scaffolding a new React component with tests and stories

Scaffold a new component

Generate a component with the structure your project already uses:

# Scaffold following existing patterns
autohand "Create a new React component called UserProfile in src/components/. Include TypeScript types, a CSS module, and a test file. Follow the same patterns as the existing components in that directory."
Autohand building a component from a specification document

Build from a spec

Point Autohand at a specification file and let it implement the feature:

# Implement from a spec document
autohand "Read the spec in docs/specs/notification-system.md and implement the notification service described there. Create all necessary files."

Implement a user story

Describe what you need in plain language:

# Natural language feature description
autohand "As a user, I want to filter the product list by price range. Add a price range slider to the ProductList page that filters products between a min and max price. Use the existing Filter component pattern."

Add an API endpoint

Generate a new endpoint that follows your existing route conventions:

# Create a REST endpoint following existing patterns
autohand "Add a PATCH /api/users/:id/preferences endpoint. It should accept a JSON body with notification settings, validate with zod, and persist to the database. Follow the patterns in src/api/routes/"

Testing

Writing tests is one of the tasks where Autohand saves the most time. It reads your source code, understands the logic, and generates tests that cover the important paths.

Autohand generating unit tests for a service module

Generate unit tests

Create tests for a specific module:

# Generate tests for a file
autohand "Write unit tests for src/utils/validation.ts. Cover all exported functions, including edge cases for empty inputs, invalid types, and boundary values. Use vitest."

Add integration tests

Test how multiple parts of your system work together:

# Integration test for an API flow
autohand "Write an integration test for the checkout flow. It should:
1. Create a user
2. Add items to cart
3. Apply a discount code
4. Complete checkout
5. Verify the order was created
Use supertest and the test database."

Improve test coverage

Find the gaps in your existing tests and fill them:

# Analyze and improve coverage
autohand "Look at src/services/billing.ts and its test file src/services/__tests__/billing.test.ts. Identify untested code paths and add tests to cover them."

Convert test frameworks

Move tests from one framework to another:

# Migrate from Jest to Vitest
autohand "Convert src/__tests__/auth.test.ts from Jest to Vitest. Update imports, matchers, and any Jest-specific APIs."

Refactoring

Autohand handles the tedious parts of refactoring, from extracting functions to renaming symbols across your whole codebase. It tracks references, respects scope boundaries, and keeps your code consistent.

Autohand extracting a function and updating all call sites

Extract a function

Pull repeated logic into a reusable function:

# Extract duplicated logic
autohand "The validation logic on lines 45-60 of src/forms/checkout.ts is duplicated in src/forms/registration.ts. Extract it into a shared function in src/utils/validation.ts and update both files."

Rename across files

Rename a symbol everywhere it appears:

# Rename with dry-run preview first
autohand "Rename the function fetchUserData to getUserProfile across the entire codebase. Show me what will change before applying."

Reorganize modules

Move code between files while keeping imports correct:

# Split a large file into smaller modules
autohand "src/services/api.ts is over 800 lines. Split it into separate files: src/services/api/users.ts, src/services/api/orders.ts, and src/services/api/products.ts. Create an index.ts barrel file that re-exports everything."

Modernize syntax

Update old patterns to modern equivalents:

# Convert callbacks to async/await
autohand "Convert all callback-based functions in src/legacy/ to use async/await. Keep the same behavior and update the error handling."

Documentation

Autohand reads your code and generates documentation that stays accurate because it is based on the actual implementation, not guesswork.

Autohand generating a README.md from project source code

Generate a README

Create a project README from scratch based on your code:

# Generate README from project contents
autohand "Generate a README.md for this project. Include: project description, installation instructions, usage examples, configuration options, and contributing guidelines. Base everything on the actual code."

Add JSDoc comments

Document all exported functions in a file:

# Add JSDoc to all exports
autohand "Add JSDoc comments to all exported functions and types in src/api/handlers.ts. Include parameter descriptions, return types, and usage examples."

Create API documentation

Generate API docs from your route definitions:

# Document all API endpoints
autohand "Read all files in src/api/routes/ and generate API documentation in Markdown format. For each endpoint, include: method, path, request body schema, response schema, and example curl commands. Save to docs/api.md"

Update existing docs

Keep documentation in sync with code changes:

# Sync docs with code changes
autohand "Compare the code in src/config/ with the documentation in docs/configuration.md. Update the docs to reflect any new options, changed defaults, or removed settings."

Git workflows

Autohand understands git and can write commit messages, create pull request descriptions, and review diffs with context.

Autohand generating a commit message from staged changes

Auto-commit with a descriptive message

Let Autohand write the commit message based on your staged changes:

# Generate a commit message from staged changes
git add -p
git diff --staged | autohand --prompt "Write a conventional commit message for these changes. Use the format: type(scope): description" | git commit -F -

Create a pull request description

Generate a PR description from your branch commits:

# Generate PR description from branch diff
git log main..HEAD --oneline | autohand --prompt "Write a pull request description for these commits. Include a summary, list of changes, and testing notes."

Review a diff before merging

Get a second opinion on what is about to be merged:

# Review the merge diff
git diff main...feature/new-auth | autohand --prompt "Review this feature branch diff. Would you approve this for merge? Explain any concerns."

Write a changelog entry

Generate a human-friendly changelog from your recent commits:

# Generate changelog since last release
git log v2.3.0..HEAD --pretty=format:"%s (%h)" | autohand --prompt "Write a changelog entry grouped by: Added, Changed, Fixed, Removed. Use clear, user-facing language."

CI/CD recipes

Autohand's headless and pipe modes make it a natural fit for CI/CD pipelines. These recipes show how to run automated reviews, generate changelogs, and catch issues before they reach production.

Pipe mode in GitHub Actions

Add an automated review step to every pull request:

# .github/workflows/autohand-review.yml
name: Autohand PR Review
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Autohand
        run: npm i -g autohand-cli

      - name: Review PR
        env:
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
        run: |
          git diff origin/main...HEAD | autohand --headless --restricted \
            --prompt "Review for bugs, security issues, and code quality. Output as markdown."

Automated code review in CI

Post review comments back to the pull request:

# Post Autohand review as PR comment
- name: Review and comment
  env:
    AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    REVIEW=$(git diff origin/main...HEAD | autohand --headless --restricted \
      --prompt "Review this diff. Output as a markdown PR comment.")
    gh pr comment ${{ github.event.pull_request.number }} --body "$REVIEW"

Generate changelogs in CI

Automatically create release notes when tagging a new version:

# Generate changelog on release
- name: Generate release notes
  env:
    AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
  run: |
    PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^)
    git log ${PREVIOUS_TAG}..HEAD --pretty=format:"%s (%h)" | \
      autohand --headless --restricted \
      --prompt "Generate release notes. Group by: Features, Bug Fixes, Breaking Changes." \
      > release-notes.md

Pre-merge security scan

Block merges that introduce security issues:

# Security-focused CI check
git diff origin/main...HEAD | autohand --headless --restricted \
  --prompt "Scan for security vulnerabilities: SQL injection, XSS, hardcoded secrets, insecure dependencies. Exit with code 1 if critical issues found."

Batch operations

When you need to make the same kind of change across many files, Autohand can process them in bulk. This is useful for migrations, mass updates, and codebase-wide improvements.

Process multiple files

Apply the same transformation to every file matching a pattern:

# Add error handling to all route handlers
autohand "Find all files in src/api/routes/ that export route handlers. Add try/catch blocks with proper error responses to any handler that doesn't have them."

Bulk refactor

Apply a consistent change across your entire codebase:

# Replace deprecated API calls
autohand "Find all uses of the deprecated fetch() wrapper from src/utils/http.ts and replace them with the new httpClient from src/lib/httpClient.ts. Update imports in every affected file."

Mass update imports

Move a module and update every import that references it:

# Update imports after moving a file
autohand "I moved src/helpers/format.ts to src/utils/format.ts. Find every file that imports from the old path and update it to the new path."

Add types across a project

Gradually add TypeScript types to a JavaScript project:

# Add TypeScript annotations to JS files
autohand "Add TypeScript type annotations to all functions in src/services/. Create type definitions for any complex objects. Don't change the runtime behavior."

One-liners

Quick commands you can copy and run right now. Each one solves a common task in a single line.

# Explain what a file does
autohand "Explain what src/middleware/rateLimit.ts does in plain language"

# Find dead code
autohand "Find exported functions in src/utils/ that are never imported anywhere else"

# Generate a .env.example from a .env file
autohand "Read .env and create .env.example with the same keys but placeholder values"

# Summarize recent changes
git log --oneline -20 | autohand --prompt "Summarize what happened in the last 20 commits"

# Check for TODO comments
autohand "Find all TODO and FIXME comments in the project and list them with file paths"

# Optimize a slow function
autohand "Profile src/search/index.ts and suggest performance improvements for the search function"

# Create a migration script
autohand "Generate a database migration that adds an email_verified column to the users table"

# Translate error messages
autohand "Find all user-facing error messages in src/api/ and create a translations file for Spanish"

# Audit npm dependencies
autohand "Check package.json for outdated, deprecated, or vulnerable dependencies"

# Generate mock data
autohand "Create a mock data file with 50 realistic user records for testing. Include name, email, and address fields."

# Fix lint errors automatically
npm run lint 2>&1 | autohand --yes --prompt "Fix these lint errors"

# Compare two implementations
autohand "Compare src/v1/auth.ts and src/v2/auth.ts. What changed and why might those changes have been made?"

Next steps