# Automate Edith from shell scripts

> Automate Edith from shell scripts with ed: the --json contract, stdout and stderr, exit codes, previews, and a script that gates work on usage limits.

- Canonical URL: https://getedith.pro/docs/tutorials/automate-edith-from-scripts
- Updated: 2026-12-03

When you finish, you will have a shell script that reads Edith's data with `ed`, reacts to every exit code correctly, and runs on a schedule inside Edith. Everything you do here by script, you can also do by hand in the Edith window; this tutorial is for the jobs you want to run unattended. You need Edith installed with `ed` on your `PATH` (see [Set up a new Mac](https://getedith.pro/docs/tutorials/set-up-a-new-mac)) and `jq` for reading JSON. The script in this tutorial uses the [Usage](https://getedith.pro/docs/extensions/claude-code-usage) extension, but the rules apply to every command.

## Find the command you need

Most things you can click in Edith also have an `ed` command. Find it by describing the task:

```terminal
$ ed docs ask "keep the mac awake with the lid closed"
$ ed help config
$ ed config --help
```

The [Docs](https://getedith.pro/docs/extensions/command-reference) extension does the same inside the app: describe a task, or browse every command with its arguments and options.

![The Docs page in Edith with the search "free up docker space" and the reference page for ed machines docker prune, listing its arguments and options](shot:ext-docs)

For a script or an agent, `ed guide --json` prints every command, alias, flag, default and help text as one JSON catalog.

## Ask for JSON

Add `--json` to a command and it prints exactly one JSON document on stdout:

```terminal
$ ed version --json
{
  "appRunning": true,
  "version": "1.0.0"
}
```

The shape is the same on every run:

- Object keys are sorted.
- A missing value is `null`, never a dropped key.
- Dates are ISO 8601, such as `2026-08-06T22:57:22Z`.
- Lists are top-level arrays. `ed usage limits`, `ed clipboard ls`, `ed machines ls` and `ed extensions ls` all print an array.

So you can pipe straight into `jq`:

```terminal
$ ed extensions ls --json | jq '.[] | select(.enabled) | .id'
```

## Keep stdout and stderr apart

stdout carries the answer and nothing else. Errors, hints, progress and notes go to stderr. A failure prints an `error:` line and often a `hint:` line with the next step:

```terminal
$ ed clipboard get 9999
error: there is no clipboard entry 9999
hint: the history holds 1217 entries, numbered from 1
```

On a non-zero exit, stdout is empty. A command never leaves half a document behind, so `ed usage summary --json > usage.json` writes a whole document or nothing. Progress spinners turn off with `--json`, and when stderr is not a terminal, so logs stay clean.

## Read the exit code

Every command exits with one of five codes:

| Code | Meaning                                            | Example                                                  |
| ---- | -------------------------------------------------- | -------------------------------------------------------- |
| 0    | Success, including a preview that changed nothing  | `ed cleaner clean` without `--yes`                       |
| 1    | Understood, but refused or failed                  | A setting value outside its allowed list                 |
| 2    | The command line was wrong                         | An unknown flag                                          |
| 3    | The thing you named does not exist or is ambiguous | An unknown machine or setting key                        |
| 4    | It exists but is unavailable right now             | An extension is off, a machine is down, a store is empty |

Code 4 also means an empty store: no clipboard history yet, or no limit readings yet. Treat it as "nothing to act on", not as a crash. When `ed` cannot reach Edith at all, it also exits 4.

Extension marketplace commands and `ed invoke`, which talk to the running app, use their own table, listed in [the command line guide](https://getedith.pro/docs/command-line). `ed machines exec` and the `ed <machine> ...` shorthand pass the remote program's own exit code through instead. For a machine named `devbox`:

```terminal
$ ed devbox sh -c 'exit 42'
$ echo $?
42
```

## Preview before you change anything

Commands that remove or restart something preview by default and act only with `--yes`. A missing `--yes` is not an error: the command reports what it would do and exits 0. Run the preview in your terminal first, then put the `--yes` form in the script:

```terminal
$ ed cleaner clean --category npm --json
$ ed cleaner clean --category npm --yes
```

## Write the script

This script stops a long job from starting when the Claude 5-hour window is nearly used up. Save it as `~/bin/claude-gate.sh`:

```sh
#!/bin/sh
threshold=80

limits=$(ed usage limits --json)
status=$?

case $status in
  0) ;;
  4) echo "no limit history yet, skipping the check" >&2; exit 0 ;;
  *) exit "$status" ;;
esac

percent=$(printf '%s\n' "$limits" | jq -r '.[] | select(.provider == "claude") | .session.percent')
percent=${percent%.*}
percent=${percent:-0}

if [ "$percent" -ge "$threshold" ]; then
  echo "Claude 5-hour window at ${percent}%, holding off" >&2
  exit 1
fi

echo "Claude 5-hour window at ${percent}%, go ahead"
```

What it relies on:

- `ed usage limits --json` reads the last saved reading, so it answers fast and does not poll your provider.
- Exit 4 means Edith has not saved a reading yet, so the script lets the job run.
- Any other failure keeps its own exit code, so a caller can tell a wrong command line (2) from a real failure (1).
- `.session` is the 5-hour window. `jq` prints `null` when the window is missing, which the script turns into 0.

Make it executable and put it in front of a job:

```terminal
$ chmod +x ~/bin/claude-gate.sh
$ ~/bin/claude-gate.sh && make build
```

## Let `ed` start Edith for you

You do not need to open Edith first. When a command needs the app and it is not running, `ed` opens it in the background, without a window, and waits up to about 20 seconds. If Edith still cannot be reached, the command exits 4. A few commands, such as `ed version`, `ed status` and `ed guide`, never need the app.

To check whether Edith is running without starting it:

```terminal
$ ed version --json | jq -e '.appRunning'
```

`jq -e` exits non-zero when the value is `false`, so this works in an `if`. [What needs Edith running](https://getedith.pro/docs/cli/conventions#what-needs-edith-running) has the full list.

## Run it on a schedule

`ed agent schedule` runs a command inside Edith on an interval or a cron rule, with no terminal open. Schedules survive restarts and reboots:

```terminal
$ ed agent schedule add claude-gate --every 15m -- /bin/sh /Users/you/bin/claude-gate.sh
$ ed agent schedule ls
$ ed agent schedule run claude-gate
```

Put `--` before an absolute path to the program. Each run is a task, so read its output with `ed agent tasks ls` and `ed agent tasks inspect <id>`. In the app, **Settings > About** lists background jobs and tasks; see [Background jobs](https://getedith.pro/docs/background-jobs).

> **Warning:** Schedules run as you, unattended, and the command line is stored without encryption. Keep secrets out of the arguments.

## Next steps

- [The `ed` command line](https://getedith.pro/docs/command-line) for completion and the machine shorthand.
- [Conventions](https://getedith.pro/docs/cli/conventions): the full `--json` and exit code contract.
- [Background jobs](https://getedith.pro/docs/background-jobs) for tasks, schedules and `ed run`.
- [Connect Claude Code over MCP](https://getedith.pro/docs/tutorials/connect-claude-code-over-mcp): the same commands as tools for an agent.

## Get Edith

Edith is a native Mac app for macOS 14 or later on Apple silicon with 100+ extensions, the `ed` command line and an MCP server. $35 once for one Mac, plus $7 for each additional Mac, with no subscription and a 30-day refund.

- [Buy Edith](https://getedith.pro/pricing): $35 once for one Mac, plus $7 for each additional Mac
- [Download Edith](https://getedith.pro/download): the installer, or Homebrew
