---
title: "Pipe Mode"
source: https://docs.autohand.ai/working-with-autohand-code/pipe-mode
---

# Pipe Mode

Pipe Mode enables Unix-style composable workflows. Feed data into Autohand via stdin and receive structured JSON output on stdout for scripting and automation.

## Overview

Pipe Mode activates automatically when Autohand detects piped input (non-TTY stdin). It reads the entire stdin stream, processes it with the LLM, and outputs structured results to stdout.

This makes Autohand composable with other Unix tools:

``` bash
# Pipe a file for analysis
cat src/auth.ts | autohand -p "find bugs in this code"

# Chain with other tools
git diff HEAD~1 | autohand -p "summarize these changes" | jq '.response'
```

## I/O behavior

| Stream | Behavior |
|---|---|
| stdin | Piped input is read in full and included as context in the prompt |
| stdout | Structured JSON output (NDJSON format, one object per line) |
| stderr | Progress messages, errors, and debug output |

Because stdout contains only structured data, you can safely redirect or pipe it without capturing progress noise.

## NDJSON output

Output uses Newline-Delimited JSON (NDJSON) format. Each line is a valid JSON object:

``` json
{"type":"message","content":"The authentication module has..."}
{"type":"tool_use","tool":"read_file","args":{"path":"src/auth.ts"}}
{"type":"tool_result","tool":"read_file","output":"..."}
{"type":"message","content":"I found 3 potential issues..."}
```

Common message types:

-   `message` — Agent text responses
-   `tool_use` — Tool invocations with arguments
-   `tool_result` — Tool execution results
-   `error` — Error messages
-   `status` — Session status updates

## Usage examples

### Code review pipeline

``` bash
# Review staged changes
git diff --staged | autohand -p "review this diff for bugs"

# Review and extract just the response text
git diff --staged | autohand -p "review this diff" | \
  jq -r 'select(.type=="message") | .content'
```

### Batch file processing

``` bash
# Add type annotations to all TypeScript files
for f in src/**/*.ts; do
  cat "$f" | autohand -p "add missing type annotations" \
    --output "$f"
done
```

### CI integration

``` bash
# Generate PR description from commits
git log main..HEAD --oneline | \
  autohand -p "write a PR description for these commits" | \
  jq -r 'select(.type=="message") | .content' > pr-body.md
```

### Combining with flags

``` bash
# Use a specific model and generate a patch
cat buggy.ts | autohand -p "fix the bug" \
  --model anthropic/claude-4-sonnet \
  --patch --output fix.patch
```

## Tips

-   Use `jq` to filter NDJSON output by message type
-   Combine with `--model` to use faster models for batch tasks
-   Use `--dry-run` in pipe mode to preview what the agent would do
-   Pipe mode respects `--restricted` and `--unrestricted` flags
-   Set `--timeout` to prevent runaway executions in CI

**Tip:** Pipe mode is perfect for CI/CD pipelines. Use `--restricted` to ensure the agent can only read and analyze without modifying your codebase.