# Addresses and the Sites button

## What's open is in the address

The path says what you're looking at. Copy it, bookmark it or reload, and you land in the same place.

| Address | Opens |
| --- | --- |
| `/Projects/Cabin` | A note (`Projects/Cabin.md`) |
| `/Projects/Cabin#open-questions` | A heading in that note |
| `/Reading/Red-Rising` | `Reading/Red Rising.md`: spaces read as dashes |
| `/Projects/Cabin-board.canvas` | A canvas. Other files keep their extension |
| `/board/Candidates` | A folder shown as a board |
| `/settings/appearance` | A settings page |
| `/search?q=cabin` | Search, with the words filled in |
| `/sessions/board` | Sessions (desktop) |
| `/Projects/Cabin?panel=outline` | The note with the outline open (`outline:outline`) |
| `/Projects/Cabin?panel=site` | One word for each built-in panel: `chat`, `site`, `git-history`. Another plugin's panel is `plugin:panel` unless both are the same word |
| `/Projects/Cabin?chat=c1x2` | The note with a saved chat open |

- Notes leave off `.md` and show spaces as dashes. That readable form is only used when it leads back to the same file: if `Red-Rising.md` exists too, `Red Rising.md` is written exactly, as `/Reading/Red%20Rising`. A link typed in any case still opens the note, and Hatch tidies the address.
- A first part that's one of the app's own words (`settings`, `search`, `board`, `sessions`, `assets`...) goes after `/-/`, so a folder called "settings" is `/-/settings/...`. Boards and Sessions are kept apart from notes inside the app too, so a note called `board:x` is always a note.
- A heading uses the same id as on a published site: the heading's text in lowercase with dashes. A repeated heading gets `-1`, `-2`.
- The vault is not in the address. A link opens in the vault you have open. If the note isn't there, Hatch says so and leaves the vault ready to browse or search. If it turns up (sync, the disk still being read), it opens.
- Renamed and moved notes keep their links. Every rename or move made in Hatch (by you or an agent through MCP) is remembered in `.hatch/moves.jsonl`, and an address for a file that isn't there follows it to where the file is now. The address then shows the new place. A file that has the old name again wins. Notes are never changed for this, so the vault stays plain Markdown. Sync joins the log from every device, and it keeps the newest 2,000 moves. See `docs/plans/rename-proof-urls.md` for why Hatch does this rather than put ids in addresses.
- Old links (`#/note/Projects/Cabin.md`, `?panel=ai:chat`) still work. Hatch opens what they name and swaps in the new address.
- Flags like `?e2e` and `?nosw` stay in the address as you move around. A feature's own state in the query (see `docs/url-state.md`) stays with its page.

### Where the address lives

| Shell | Address | Links from outside |
| --- | --- | --- |
| Web | The real path. The server answers every path with the app (`deploy/Caddyfile`, and `apps/web/public/sw.js` offline) | Any link to the app |
| Desktop | The hash of `hatch://app/index.html` | `hatch://open/Projects/Cabin` from a browser, another app or the terminal (`apps/desktop/main/links.ts`) |
| Mobile | The hash | `hatch://open/...`, and the web app's own links when `VITE_HATCH_APP_URL` is set and the app is set up to take them (iOS associated domains, an Android intent filter) |

The phone projects aren't in the repo, so after `cap add` the scheme has to be listed by hand: `CFBundleURLTypes` with `hatch` in the iOS `Info.plist`, and an intent filter for `hatch://open` in the Android manifest. https links also need an associated domain (iOS) and a verified app link (Android).

Desktop takes `hatch://` links only when installed. A development run leaves them to the installed app (set `HATCH_DEV_LINKS=1` to try them). A Hatch started with `HATCH_VAULT` runs on its own window, as before; any other second launch hands its link to the running one.

Deep links only ever show something. They can't write to the vault.

Copy link (the note's menu) gives the link that opens what's on screen from anywhere it can: the page's address on the web, and `hatch://open/...` in the desktop and phone apps (the web app's address on a phone app built with `VITE_HATCH_APP_URL`). It keeps the open panel and leaves out test flags.

Published sites follow moves too: a published note's old address answers with a `301` to its new one on Hatch hosting, and a redirect page (with `rel="canonical"`) on any other host.

## Back and Forward

- The app's history is the browser's history. The browser's buttons, the app's buttons, the hotkeys and a mouse's side buttons all walk the same list.
- Opening a note adds one entry. Typing, scrolling, moving to a heading and changing settings pages never add one.
- Settings and search borrow the current entry. Closing them puts the note's address back.
- A reload keeps the open note and the history behind it.
- Renaming or moving a note updates its entries. So does renaming or moving a folder it is in, here or on another device before a reload. Back steps over a note that has been deleted.

## For people changing the code

- `packages/app/src/routeAddress.ts` has `parseRoute` and `formatRoute` (pure, unit tested). Pass the vault's names to get readable addresses. Without them they're exact.
- `packages/app/src/route.ts` has the `Router`. It writes through the shell's address adapter (`Platform.address`, from `@hatch/url-state`).
- Features keep their own state in the query with `store.url` or the `useQueryState` hook (`docs/url-state.md`). Their history entries go through the router, so Back and Forward know them.
- The store calls `router.sync()` whenever the open note or settings change, so new code only needs `store.open(path)`. Pass `{ heading }` to land on a heading and `{ push: false }` to replace the current entry.
- `store.router.url()` gives the link to share (`Platform.shareLink` can change it for a shell). The move log is `vault.moveLog` (`packages/vault/src/moveLog.ts`): `moveWithLinks` records every move, `follow(path)` says where a path is now, and the MCP server and site builds use it too. `store.router.heading(id)` moves the address to a heading without adding an entry.
- `state.back` and `state.forward` are kept by the router. Don't write to them.
- `scripts/e2e-routes.py` checks all of the above in a browser.

## The Sites button

The grid button at the top left of the sidebar lists your sites. While the sidebar is hidden it sits in the top bar, next to the sidebar button.

- Each row shows the site's name, its kind and its address.
- The site published from the open vault opens its settings (Settings, Publish). Rows under it go straight to its applications board or its subscribers.
- A site published from another vault opens in the browser. To change it, open the vault it came from.
- "New site" starts a site for the open vault. A vault publishes one site, so once it has one the list says how to start another.
- Signed out, the list explains what a site is and offers to sign in. A site you set up without an account (to download) is still listed.

Limits to know about:

- The server doesn't store a site's kind. It lives in the vault's `.hatch/site.json`. Each device remembers the kinds of sites it has opened or published, and shows "Site" for the rest.
- There is no page for managing a site on its own yet. Settings, Publish is that page for the open vault's site.
