Working with command-line tools is a fundamental skill for any developer. When your CLI tool is an AI, you unlock powerful new ways to automate tasks, but only if you know how to manage its input and output effectively. This lesson demonstrates how to use standard shell features—pipes (|) and redirection (< and >)—to make any command-line AI tool a composable part of your workflow.
Direct Input with Flags
The simplest way to interact with the tool is by passing a string directly using a flag, such as --print or its shorthand -p. The tool processes the string and prints the response directly to the terminal.
Piping Input from Other Commands
Pipes (|) are used to send the standard output of one command to the standard input of another. This allows you to chain commands together. Here, the output of echo "Sup?" is "piped" into the claude tool.
Redirecting Input and Output with Files
Redirection allows you to change where standard input comes from and where standard output goes.
Input Redirection (<)
Instead of typing a prompt, you can write it in a file (e.g., prompt.txt) and use the < operator to feed its contents into the command. This is perfect for long, reusable prompts.
Output Redirection (>)
To save the AI's response, you can redirect its output to a file using the > operator. Instead of printing to the terminal, the response is written directly to the specified file (e.g., typescript.txt). This captures the result for later use.
This command runs silently, but a new file typescript.txt is created with the AI's full response, allowing you to integrate AI-generated content directly into your projects.
Prompts
Commands
Code Snippets
