# Compresto CLI: instructions for coding agents

## Compressing media with Compresto

Use the `compresto` command-line tool to compress or convert videos, images, GIFs and PDFs. It runs locally on macOS and nothing is uploaded.

### Before the first use

1. Check that it is installed: `compresto --version`. If the command is missing, install it with `brew install dqhieu/tap/compresto`.
2. Check the license: `compresto auth status --json`. If `loggedIn` or `valid` is false (exit code 3), stop and ask the user to run `compresto auth login` themselves. Never ask for, read or type the license key.
3. If a command exits with code 4, a required tool is missing. Run `compresto doctor`; it prints the `brew install` command that fixes it.

### Usage

```bash
compresto <files or folders> [options] --json
```

- Always pass `--json`. Each file produces one JSON line on stdout with `input`, `output`, `status` (`compressed`, `skipped` or `failed`), `inputBytes`, `outputBytes`, `savedPercent`, and `error` or `reason` when relevant. The last line is a summary with `"type":"summary"`. Only rely on `output` when `status` is `compressed`.
- Preview first when unsure: `--dry-run` reports each file as `planned` with the commands that would run, and changes nothing. It works without a license.
- Quote paths that contain spaces.

| Goal | Options |
| --- | --- |
| Compress, keeping the format | no extra options |
| Convert a video | `--to mp4`, `mov`, `webm`, `gif` or `mp3` |
| Convert an image | `--to jpg`, `png`, `webp` or `avif` |
| Quality | `--quality highest`, `high`, `good`, `medium` or `acceptable` |
| PDF quality | `--pdf-quality best`, `high`, `balance` or `low` |
| Hit a file size (video, JPEG) | `--target-size 8MB` |
| Resize a video | `--resolution 1080`, `--max-width N`, `--max-height N` |
| Resize an image or GIF | `--resize 50%`, `--max-width N`, `--max-long-edge N` |
| Trim a video | `--start 0:10 --end 0:25` |
| Remove audio | `--no-audio` |
| GIF from video | `--to gif --gif-width 640 --gif-fps 15` |
| A folder and its subfolders | `--recursive` |
| Several files at once | `--jobs 4` |
| Choose where output goes | `--output out/` for a folder, `--output name.ext` for one file |

### Where the output goes

- Same format: next to the original as `name_compressed.ext`.
- Converted with `--to`: next to the original with the new extension, for example `photo.png` becomes `photo.webp`.
- With `--output out/`: in that folder, under the original name. End the folder path with a slash; with a single input, a path without one is treated as a file name.
- Originals are never changed or deleted unless `--replace` is passed.

### Rules

- Do not pass `--replace` or `--force` unless the user asked for it. `--replace` puts the result in place of the original and moves the original to the Trash. `--force` overwrites an output file that already exists.
- A `skipped` file is not an error: it could not be made smaller, so the original was kept.
- If a file fails with "already exists", an earlier run already wrote that output. Use the existing file, or ask the user before overwriting it with `--force`.
- After converting to a new format, update references to the old file name in the project.
- Supported inputs are video (MP4, MOV, M4V, MKV, WebM, AVI and more), images (JPEG, PNG, WebP, AVIF, HEIC, TIFF, BMP), GIF and PDF. EPUB and SVG are not supported.
- Transparency is kept in PNG, WebP and AVIF. JPEG cannot store it and fills it with white.

### Exit codes

| Code | Meaning |
| --- | --- |
| 0 | Success |
| 1 | At least one file failed; check each result's `error` |
| 2 | Invalid arguments |
| 3 | Not signed in, or the license is not valid |
| 4 | A required tool is missing |

Run `compresto --help` for every option. Full documentation: https://compresto.app/docs/cli/introduction
