# zag plan
Generate an implementation plan.
## Synopsis
zag [flags] plan [options] <goal>
## Description
Generates a structured implementation plan for a given goal or task. The agent analyzes the codebase and produces a Markdown plan covering affected files, implementation steps, testing approach, and risks.
By default, the plan streams to stdout (pipe-friendly). Use `--output` to write to a file or directory instead.
When running in server mode (user logged in), the output path must be within the user's home directory.
## Flags
-o, --output <PATH> Write plan to a file or directory (generates plan-{timestamp}.md in directories)
--instructions <TEXT> Additional planning instructions
Global flags that apply: `-p`, `--model`, `--system-prompt`, `--root`, `--auto-approve`, `--add-dir`, `--file`, `--env`, `--mcp-config`, `--max-turns`, `--debug`, `--quiet`.
## Using Plans
Plans generated by `zag plan` can be fed back into `run`, `exec`, or `spawn` via the `--plan` flag:
zag plan "Add authentication" -o auth-plan.md
zag exec --plan auth-plan.md "Implement the plan"
zag run --plan auth-plan.md
The `--plan` flag reads the plan file and prepends its content as context to the prompt.
## Notes
- The `-p` flag selects the provider (e.g., `-p claude`, `-p codex`, `-p gemini`)
- The `--model` flag selects the model for the chosen provider
- Status messages go to stderr so stdout output can be piped
- When `--output` is a directory, a timestamped filename is generated (e.g., `plan-20260406-143022.md`)
- When `--output` has an extension, it is treated as a file path
## Examples
zag plan "Add user authentication" Plan to stdout
zag plan "Add auth" -o plans/ Write to plans/plan-{timestamp}.md
zag plan "Add auth" -o plans/auth.md Write to specific file
zag plan "Refactor API" -p claude --model large Use Claude with large model
zag plan "Add caching" --instructions "Use Redis" Plan with extra instructions
zag plan "Add auth" -o plan.md && zag exec --plan plan.md "Do it" Plan then execute
## See Also
zag man exec Non-interactive execution
zag man run Interactive sessions
zag man review Code review