---
title: "Recipe: a second window"
description: "A link with a named target opens that route in its own Mac window or browser tab."
modificationDate: "2026-11-30"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a second window

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/second-window: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

A `link` with a named `target` opens that route in its own Mac window or
browser tab. Other hosts navigate in place. On macOS it opens the route alone,
without a sidebar. A second press brings the same window to the link's route (LLP 1030.004).

```prompt Open a screen in a second window
Make the Exact app in this folder open one of its screens in a second window. Use https://github.com/expo/exact/blob/main/docs/recipes/second-window.md as the source for each step. The Exact checkout has the same page at docs/recipes/second-window.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say which screen opens in its own window, and the window's name, propose them and ask me before you write code. A second window is the Mac's and the web's: on the web it is the browser window or tab of that name, and other hosts navigate in place.
3. In app.contract, give the screen a route in `routes`, and open it with a `link` whose `href` is the route and whose `target` names the window. The next press brings that window forward. For a new window on each press, use `_blank`. `_self`, `_parent` and `_top` navigate in place. Any other literal name that starts with `_`, and `window-<n>`, is refused.
4. On the Mac the window is a session of its own, rooted at the route: that screen alone, with no sidebar. Put all that the window needs in that screen.
5. Give the state that the windows share `persist`: a `persist` state or a store write in one window reaches the readers in the others. On the web, two tabs cannot open one SQLite database at once.
6. Every window runs the root's `task`s. Read `exactPage()` as a resource, as the recipe shows, and gate work that the app does once: `task sync when page.name == "main"`. The name is `main` in the app's first window, the `target` in a window that a link opened, and empty in a `_blank` one.
7. Add a test in app.test.contract that starts at the window's route (`at "/<path>"`), changes the shared state there, and expects the new value with `expect state`.
8. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. On the Mac, also run `bun exact.mjs agent macos "tap <testId>" state` with the link's `testId`, and confirm that it lists the window with its `name` and `location`. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me the window's name and route, what the link does on each target platform, what the tests and checks reported, and what stays untested if this machine is not a Mac.
```

```contract
routes nav
  inbox "/"
    compose "/compose"

shape Page
  name: string

component App
  state draft = "" persist
  resource page = exactPage() as shape Page
  action follow(url: string)
    nav = go(nav, url)
  action edit(v: string)
    draft = v
  view
    main navigationKey=`${top(nav).id}` navigate=follow width="100%" height="100%"
      for e in stack(nav) key=e.id
        if e.name == "inbox"
          column navigationKey=`${e.id}` position="absolute" inset=0
            header display="flex" align-items="center"
              text "Inbox" role="heading" aria-level=1 flex=1
              link href="/compose" target="compose" aria-label="New Message" testId="new-message"
                image "symbol:compose"
            text (draft == "" ? "No draft" : `Draft: ${draft}`) testId="draft-line"
        if e.name == "compose"
          column navigationKey=`${e.id}` position="absolute" inset=0 padding=16 gap=12
            header display="flex" align-items="center"
              text "New Message" role="heading" aria-level=1 flex=1
            textarea value=draft input=edit aria-label="Message" flex=1 testId="draft"
            text `This window is ${page.name}` testId="window-name"
```

`bun exact.mjs agent macos "tap new-message" state` lists each window’s `name`, `location` and whether it is rooted; `"session compose"` sends the ops after it there.

What to know:

- **Names.** Empty, `_self`, `_parent` and `_top`, in any case, navigate in
  place. `_blank` opens a new window each press, with no name. A literal name
  that starts with `_` and is no keyword, or is `window-<n>` (the agent's label
  for a window with no name), is refused; a bound one that starts with `_` acts
  as `_blank`.
- **HUD.** Add `windowKind="panel"` to the opening link to float above
  full-screen Mac apps without activating. Other hosts report `panel`
  unsupported. Escape closes the HUD when it receives the key.
- **Which window.** `exactPage().name` is `main` in the app's first window on
  every host, the `target` in a window a link opened, and empty in a `_blank`
  one. Every window runs the root's `task`s, so gate work the app does once:
  `task sync when page.name == "main"`.
- **One store.** Persisted state, store and `app:/` writes reach each window’s readers.
  A SQLite statement refreshes readers only if rows or schema change. A no-op
  `DELETE` or `CREATE TABLE IF NOT EXISTS` leaves readers alone.
  On the web, two tabs cannot open the same SQLite database at once.
- **Closing.** Closing a window ends its session. `main` holds the app: under
  `keepRunning` or with a status item placed, closing it hides it, and a Dock
  click shows it again.
- For the Mac's Settings window, see [a Settings window](https://exact.expo.dev/recipes/settings-window.md).
