Working with Autohand
Pipe Mode
Pipe Mode enables Unix-style composable workflows. Feed data into Autohand via stdin and request 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, adds it to the prompt as context, runs the task, and exits.
This makes Autohand composable with other Unix tools:
# 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
With --output-format stream-json, output uses Newline-Delimited JSON (NDJSON). Each line is a valid JSON object:
{"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, inthoughttool_startandtool_end: tool calls and their resultsfile_modified: a file the agent created, changed, or deletedresult: the agent's response, incontenterror: an error, inmessage
Use --json local when you only need the final result or error object.
Usage examples
Code review pipeline
# 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
# 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
# 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
# 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
jqto read--json localoutput or to filter stream events bytype - Combine with
--modelto use faster models for batch tasks - Use
--dry-runin pipe mode to preview what the agent would do - Pipe mode respects
--restrictedand--unrestrictedflags - Set
--max-duration,--max-requests, or--max-tokensto stop runaway runs in CI
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.