---
title: "Pipe Mode"
description: "Pipe Mode enables Unix-style composable workflows. Feed data into Autohand via stdin and request structured JSON output on stdout for scripting and automation."
seo:
  description: "Use Pipe Mode for Unix-style composable workflows. Pipe data into Autohand and get structured JSON output for scripting and automation."
---

## Overview

Pipe Mode activates automatically when Autohand detects piped input (non-TTY stdin). It reads the entire stdin stream, adds it to the prompt as context, runs the task, and exits.

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" --json local | jq -r '.content'
```

## I/O behavior

| Stream | Behavior |
| --- | --- |
| **stdin** | Piped input is read in full and included as context in the prompt |
| **stdout** | Human-readable text by default. With `--json local`, one final JSON object. With `--output-format stream-json` or `--json stream`, one JSON event per line |
| **stderr** | Progress messages, errors, and debug output when a JSON format is selected |

When you select a JSON format, stdout contains only JSON, so you can redirect or pipe it without capturing progress output.

## NDJSON output [#ndjson]

With `--output-format stream-json`, output uses Newline-Delimited JSON (NDJSON). Each line is a valid JSON object:

```json
{"type":"thinking","thought":"The user wants me to review src/auth.ts..."}
{"type":"result","content":"I found 3 potential issues..."}
```

Common event types:

- `thinking`: the agent's reasoning, in `thought`
- `tool_start` and `tool_end`: tool calls and their results
- `file_modified`: a file the agent created, changed, or deleted
- `result`: the agent's response, in `content`
- `error`: an error, in `message`

Use `--json local` when you only need the final `result` or `error` object.

## Usage examples [#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" --json local | \
  jq -r '.content'
```

### Batch file processing

```bash
# Add type annotations to each TypeScript file
for f in src/**/*.ts; do
  autohand -p "add missing type annotations to $f" --yes
done
```

### CI integration

```bash
# Generate PR description from commits
git log main..HEAD --oneline | \
  autohand -p "write a PR description for these commits" --json local | \
  jq -r '.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
```

`--output <file>` applies only with `--patch`.

## Tips

- Use `jq` to read `--json local` output or to filter stream events by `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 `--max-duration`, `--max-requests`, or `--max-tokens` to stop runaway runs in CI

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

<AcademyCta course="hooks-and-automation" title="Hooks and automation" blurb="React to agent events with hooks, run one-shot jobs, and wire the CLI into CI." />
