---
title: "Space Herder: a sidebar that sorts itself"
canonical: "https://mrbogomips.github.io/herdr-tools/space-herder/"
author: "MrBogomips"
published: "2026-11-28T11:42:34.000Z"
modified: "2026-11-28T11:42:34.000Z"
lang: "en"
license: "CC-BY-4.0"
code-license: "MIT"
---

Plugin · v0.1.1 · Herdr 0.9.5 or newer · macOS and Linux

Space Herder keeps Herdr's spaces sidebar sorted into groups, gives every space for a customer the
same colour, and replaces Herdr's new-space and rename prompts with dialogs that preview the result
as you type. [Set it up](https://mrbogomips.github.io/herdr-tools/space-herder/#set-it-up-in-five-steps), or
[try the colours in your browser](https://mrbogomips.github.io/herdr-tools/#try-it-in-your-browser).

```sh
herdr plugin install MrBogomips/herdr-tools/space-herder
```

![Herdr with Space Herder: a sidebar where each customer has its own colour, with ACME spaces grouped in blue, Initech in mauve, LUMON pinned at the top, SYS kept at the bottom, and agents working and waiting below](https://mrbogomips.github.io/herdr-tools/_astro/hero.BQhuuIlU_1cJuzE.png "Herdr with Space Herder and auto-tab-name, using fictional customer names.")

## A sidebar that sorts itself

A suffix on the space name determines its group. Groups appear in this order, and within each group
spaces are sorted by name with the suffix removed, ignoring case. Worktree children stay directly
below their parent.

| Group   | Naming convention         | Example           |
| ------- | ------------------------- | ----------------- |
| home    | The name `~`              | `~`, always first |
| head    | Ends with a space and `+` | `LUMON +`         |
| default | No suffix                 | `ACME - api`      |
| bottom  | Ends with a space and `-` | `SYS -`           |

The space before the suffix is required, so `C++` stays in the default group. Trigger a sort with a
key binding, or enable automatic sorting so the sidebar re-sorts whenever you create or rename a
space:

| `auto_sort`       | When it sorts                                     |
| ----------------- | ------------------------------------------------- |
| `"off"` (default) | Manual only (via the sort key binding)            |
| `"created"`       | A space is created, including new worktree spaces |
| `"renamed"`       | A space is renamed                                |
| `"both"`          | A space is created or renamed                     |

Sorting preserves the focused space, does nothing if the sidebar is already in order, and updates
space numbers and next/previous-space navigation to match the new order.

## A colour per customer

By default, spaces share a colour when they share the same key: the part of the name before the
first ` -`. For example, `ACME - api`, `ACME - web` and `ACME +` all share `ACME`, so they get the
same colour. The colour is chosen in this order:

1. **Rules.** A regular expression is matched against the space name; the first match sets the
   colour.
2. **Dialog choice.** A colour chosen for that key in a dialog.
3. **Automatic assignment**, controlled by `assign`:
   - `"hash"` (default): derives the colour from a stable SHA-256 hash of the key. The same
     customer gets the same colour on every machine without storing state.
   - `"sticky"`: starts from the hash colour, but takes the least-used colour if that one is
     already taken and keeps it. No two customers share a colour until you have more customers than
     colours.
4. **Worktree children** inherit their parent's colour, so a repository's checkouts match it.

:::note
With hashing alone and 15 colours, the chance that two of six customers share a colour is about 2
in 3. Use `"assign": "sticky"`, or pin a customer to a colour with a rule.
:::

### 9 preset palettes

Each preset uses the accent colours of a popular theme, with the most distinct colours first, up to
the 15 a sidebar row can hold. You can also provide your own list of hex colours.

- **catppuccin** 15 colours

- **dracula** 14 colours

- **github-dark** 15 colours

- **gruvbox** 15 colours

- **kanagawa** 15 colours

- **nord** 9 colours

- **one-dark** 8 colours

- **solarized** 8 colours

- **tokyo-night** 15 colours

## Dialogs that show the result

Herdr's own prompts ask only for a name. Space Herder's dialogs open in a popup and preview how the
sidebar will look: the name with its group suffix, the space in its sorted position and its
assigned colour.

![The new-space dialog over a Herdr layout: folder \~/git/initech-crm, name Initech - billing becoming Initech - billing + in the head group, mauve selected in the colour row, and a sidebar preview showing Initech - billing + at the top with both Initech spaces in mauve](https://mrbogomips.github.io/herdr-tools/_astro/new-space.BeKW3ojH_caH8j.png "New space: folder, name, group and colour, with the sidebar preview on the right.")

| Field              | Keys                       | What it does                                                                                  |
| ------------------ | -------------------------- | --------------------------------------------------------------------------------------------- |
| Folder (new space) | Type, Tab to complete, ↑ ↓ | Starting folder: recent folders, open panes' folders and, with zoxide, its top-ranked folders |
| Name               | Type, Ctrl+W, Ctrl+U       | Ending the name with ` +` or ` -` selects the group                                           |
| Group              | ← →, + - =                 | Selects head, default or bottom                                                               |
| Colour             | ← →, a for auto            | A palette colour for every space sharing the key, or auto                                     |

![The rename dialog for ACME - api: blue is selected in the colour row, and the sidebar preview shows ACME - api, its feature-checkout worktree and ACME - web all in blue](https://mrbogomips.github.io/herdr-tools/_astro/rename.j7uKmxI3_Z2fNRMV.png "Renaming ACME - api: selecting blue recolours every ACME space at once.")

## Set it up in five steps

1. Install the plugin:

   ```sh
   herdr plugin install MrBogomips/herdr-tools/space-herder
   ```

2. Optionally create `config.json` in the directory returned by
   `herdr plugin config-dir mrbogomips.space-herder`. This example sorts the sidebar whenever you
   create or rename a space and keeps customer colours distinct:

   ```json
   {
     "auto_sort": "both",
     "assign": "sticky"
   }
   ```

3. Generate the sidebar rows; a toast displays the path to the generated file:

   ```sh
   herdr plugin action invoke mrbogomips.space-herder.snippet
   ```

4. In `~/.config/herdr/config.toml`, set `rows` under `[ui.sidebar.spaces]` to the value from that
   file, and add key bindings for sorting and the dialogs:

   ```toml
   [keys]
   new_workspace = "prefix+ctrl+n"    # Herdr's own prompts, still reachable
   rename_workspace = "prefix+ctrl+w"

   [[keys.command]]
   key = "prefix+shift+s"
   type = "plugin_action"
   command = "mrbogomips.space-herder.sort"

   [[keys.command]]
   key = "prefix+shift+n"
   type = "plugin_action"
   command = "mrbogomips.space-herder.new-space"

   [[keys.command]]
   key = "prefix+shift+w"
   type = "plugin_action"
   command = "mrbogomips.space-herder.rename-space"
   ```

5. Validate the configuration, then reload it:

   ```sh
   herdr config check && herdr server reload-config
   ```

:::warning\[Never paste a second `[ui.sidebar.spaces]` table]
A duplicate table makes the entire configuration invalid, causing Herdr to fall back to its
defaults, including key bindings.
:::

## Configuration

Every key in `config.json` is optional. Space Herder reads the file on every run, so changes to
`auto_sort` apply immediately.

:::note\[Changed `palette`, `palette_size` or a rule's colour?]
Colours are stored in `config.toml`. After changing any of these, run the `snippet` action again,
copy the new rows into `config.toml`, run `herdr server reload-config`, and then run the `recolor`
action. The first comment line of the generated rows includes a fingerprint of the colours, so you
can tell whether your copy is up to date.
:::

| Key            | Default        | Meaning                                                                 |
| -------------- | -------------- | ----------------------------------------------------------------------- |
| `auto_sort`    | `"off"`        | `"off"`, `"created"`, `"renamed"` or `"both"`                           |
| `palette`      | `"catppuccin"` | A preset name, or a custom list of hex colours                          |
| `palette_size` | all            | Uses only the first N colours, leaving slots for rule colours           |
| `assign`       | `"hash"`       | `"hash"` or `"sticky"`                                                  |
| `key`          | `"prefix"`     | `"prefix"`, `"suffix"` or `"whole"`                                     |
| `separator`    | `" -"`         | Splits the prefix from the suffix                                       |
| `marker`       | `"▌"`          | Drawn before the space name in the same colour                          |
| `rules`        | `[]`           | `{"match": "<regex>", "color": ...}`, evaluated before the key's colour |

The [README](https://github.com/MrBogomips/herdr-tools/tree/main/space-herder#configuration)
documents every key, the colour slots and the sticky assignments file.

## Good to know

- Herdr styles only a token's foreground, not its background, so the marker before the name acts as
  a colour swatch.
- You can use at most 15 colours, which is the number of tokens a sidebar row can hold alongside
  the agent-state dot.
- Both the sidebar colours and the dialog swatches are 24-bit, so they require a terminal with
  truecolor support (iTerm2, Ghostty, WezTerm and kitty all support it).
- Colours appear only in the expanded sidebar; the collapsed rail and mobile layout keep Herdr's
  default rendering.
- `ACME-api` does not split on ` -`; keep the space before the dash, or change `separator`.
- A space dragged manually returns to its group on the next sort.

[Install](https://mrbogomips.github.io/herdr-tools/install/) · [Full README on GitHub](https://github.com/MrBogomips/herdr-tools/tree/main/space-herder)
