Reverse Engineering macOS Spaces with an AI Agent

August 14, 2026

I live in macOS Spaces. Calendar on one, comms on another, a Space per project, and a few more for whatever rabbit hole I'm in that week. Somewhere around Space six it stops being a workflow and starts being a guessing game. Desktop 3... no, 4... where did my email go? Apple gives you numbers, and numbers are not a memory system.

There's an app called SpaceJump that fixes this. It's $9.99, it's nice, and it lets you name your Spaces. Its big claim is that it's the only app that shows your custom names inside Mission Control on Apple Silicon without disabling SIP.

I could have just bought it. Instead I pointed Claude Code at the SpaceJump website and typed:

lets look at https://www.getspacejump.com/ and then lets come up with a plan to build a clone. osx native, probably swift?, spaces renaming

Two days later I had Spacewalker, a native Swift menu-bar app that does what I wanted, including the Mission Control trick. I didn't write a line of it. But the interesting part isn't that an agent wrote a Mac app. It's how it got there, because there's no API for any of this.

There is no Spaces API

Apple has never shipped a public API for Spaces. Not in 15+ years. Everything that touches Spaces rides on private SkyLight/CoreGraphics symbols that aren't documented and can change in any point release.

So the agent didn't start by writing an app. It started with a spike: a throwaway Swift package whose only job was to answer the scary questions on my actual machine (M-series, macOS 15, SIP on) before anything got built on top of them:

  1. Can we load the private CGS… symbols at all? (Yes, loaded at runtime with dlsym, so nothing breaks at link time.)
  2. Can we read the real Space layout? (Yes. CGSCopyManagedDisplaySpaces gives you every display, every Space, and a UUID for each.)
  3. Can we actually switch Spaces?

The UUIDs turned out to be the foundation. Names are keyed on the OS's own Space UUIDs, not on "Desktop 3", so they don't get scrambled when Spaces shift around. I named everything, rebooted, and the names came right back on the right Spaces. That's the exact case that breaks index-based tools.

Question three is where things got fun.

The agent lied to itself (and I caught it)

The obvious approach to switching is faking the keyboard shortcut: send Ctrl+→ and let macOS do its thing. The spike tried it, and these showed up in my terminal:

^[[1;5C

That's the literal escape code for Ctrl+→. The keystrokes were landing in my terminal as raw keys instead of switching anything. It turns out Sequoia ignores synthetic keystrokes for Space switching. The events go through, but the WindowServer won't act on them.

So the agent pivoted to a private API, CGSManagedDisplaySetCurrentSpace, ran it, re-read the Space topology, and reported back with a big green checkmark: switching works, no Accessibility permission needed, fully de-risked. 🎉

Except when I ran it, my screen didn't move. It just pulled Ghostty forward on the Space I was already on.

What happened is that the private call updates the WindowServer's internal idea of the current Space, so when the spike read that state back, it saw exactly what it had just written. The screen never changed. The agent had checked its work by asking the same system it had just changed. It agreed with itself.

To its credit, when I told it, it named the mistake right away: it had validated against the API's self-reported state instead of ground truth. That lesson ended up in the design doc in bold: do not validate a switch by re-reading this API — it self-confirms a lie.

I've been thinking about this one a lot since. It's not an AI problem exactly. People do this too. But an agent will do it very confidently, with a table of green checkmarks, and the only thing that caught it was a human looking at the actual screen.

What actually works

After a bit more digging, the answer was a little boring: AppleScript.

tell application "System Events" to key code 124 using control down

That one performed a real, animated Space switch. System Events sends keystrokes through the Accessibility path instead of the raw input path, and it sends the Control key as its own event before the arrow, which seems to be what the WindowServer's hotkey handler wants. Same keystroke, different door.

That gave us adjacent moves, but jumping from Space 1 to Space 6 meant five animated hops in a row. I said that was odd UX, and the fix was to turn on macOS's own "Switch to Desktop N" shortcuts (Ctrl+1 through Ctrl+9) by writing to com.apple.symbolichotkeys from code. They took effect live, no logout, and now a jump is one keystroke.

A few other macOS quirks we hit along the way:

Spacewalker's Quick Switcher listing named Spaces

The Mission Control trick

This is the feature SpaceJump charges for, and the one I honestly didn't think we'd get. So I asked for a spike just to see if it was even possible.

Mission Control is drawn by the WindowServer at a very high window level. The trick turned out to be three pieces:

  1. Draw above it. A window at CGShieldingWindowLevel() set to join all Spaces renders on top of Mission Control. The spike put a big ugly marker up there, I opened Mission Control, and there it was.
  2. Know when it's open. The Dock process exposes Mission Control through the Accessibility tree, but only while it's open. So you poll the Dock's AX tree and watch for it to appear.
  3. Find each Space. Under Mission Control there's a "Spaces Bar" with an AXButton for each Desktop N, along with its exact on-screen rect, in order.

Map Desktop N to your Space name, paint a little pill at that rect on the overlay window, and your names float right onto the Mission Control thumbnails. As the Spaces bar expands, the pills ride along with it. All of it with SIP on.

The part I liked here was the back and forth. The agent built a probe to dump the Dock's AX tree, but you can't exactly run a command while Mission Control has taken over your screen. It wired the dump to a hotkey, I opened Mission Control, hit the key, and handed it the output. It had real data to build against instead of guesses.

The polish took longer than the hard part

Once everything worked, most of my time went into the stuff you'd expect: a dark theme with purple and lime green ("more rounded and osx like"), and a little heads-up display that flashes the Space name when you switch, like the volume HUD.

The Spacewalker switch HUD showing a Space name

That HUD took more back and forth than the Mission Control overlay. Hammer Ctrl+→ a few times and it would show a trail of old names. The agent tried clearing it on macOS's Space-change notification, which made it worse. That notification fires after the new name is already showing, so it was erasing the right answer. The fix that stuck was blanking the HUD on the keypress itself, before the switch even happens, then filling in the name once the switch lands.

What I took away from it

The whole thing is on GitHub. The README says up front that Claude wrote all of it, and the design diary in PLAN.md keeps the dead ends in. It's free, and I've been using it every day since. My Spaces finally have names.

← All posts