MacRent › Guides

Run Claude Code with Xcode and the iOS Simulator 24/7

Cloud agent sandboxes run Linux, so Claude Code can write Swift but can't compile it. Here's how to give it a real build-and-test loop on a Mac, and keep it running while you sleep.

Updated 2026-11-27 · ~6 min read

Why Claude Code needs a Mac for iOS work

Xcode, xcodebuild and the iOS Simulator only run on macOS. In a Linux sandbox the agent edits Swift files and says "done" without ever compiling them, so you get code that doesn't build, tests that never ran and UI changes nobody looked at. On a Mac the agent can close that loop itself: build, run the tests, check the UI, fix, repeat.

1. Prepare the Mac

Install Xcode, then finish its setup without any interactive dialogs, so the agent never gets stuck on a window it can't see:

sudo xcodebuild -license accept
sudo xcodebuild -runFirstLaunch
xcodebuild -downloadPlatform iOS        # installs the iOS Simulator runtime
brew install tmux xcbeautify

Then install the agent. Claude Code: npm install -g @anthropic-ai/claude-code (or Anthropic's native installer). Codex CLI: npm install -g @openai/codex. Sign in with your own Claude or ChatGPT plan; no API key needed.

Get a dedicated Mac with Xcode, ready for your agent

MacRent gives you a whole Mac mini (Xcode, iOS Simulators, Claude Code and Codex preinstalled), always on. Use it from your browser, over SSH or from your phone.

Try it for $12 / 24 hours Early access · monthly from $105 · no charge until your Mac is live · all plans

2. Tell the agent how to build and test (CLAUDE.md)

The single biggest improvement is a clear definition of done. Put this in CLAUDE.md (or AGENTS.md for Codex) at the root of your repo:

## Build & test: always run before saying a task is done
- Build: xcodebuild -scheme App -destination 'platform=iOS Simulator,name=iPhone 17' build | xcbeautify
- Test:  xcodebuild test -scheme App -destination 'platform=iOS Simulator,name=iPhone 17' | xcbeautify
- A task is NOT done until the build succeeds and all tests pass.

## UI changes
- Boot the simulator, run the app and take screenshots:
  xcrun simctl io booted screenshot /tmp/after.png
- Check dark mode too: xcrun simctl ui booted appearance dark
- Attach before/after screenshots to the PR description.

## Don'ts
- Don't edit .pbxproj by hand; use the project generator and regenerate.
- Don't change the deployment target or Swift version without asking.

Use a simulator you actually have installed. List them with xcrun simctl list devices available. Piping through xcbeautify keeps build logs short, so they don't eat the agent's context.

3. Keep the agent alive overnight

Long tasks die when the Mac sleeps or your SSH connection drops. Three things fix that:

sudo pmset -a sleep 0 disksleep 0 displaysleep 0   # never sleep
sudo pmset -a autorestart 1                        # boot again after a power cut
tmux new -s agent                                  # run claude inside; detach with Ctrl-b d

Reattach any time with tmux attach -t agent, from your laptop or from an SSH app on your phone. Also turn off automatic macOS updates, so the Mac doesn't reboot mid-task.

4. Two gotchas that cost hours

The Simulator needs a logged-in session

Even if nobody looks at the screen, simctl and UI tests need a logged-in GUI user. Enable automatic login (System Settings → Users & Groups), which requires FileVault to be off. That's fine on a dedicated, wiped-between-users machine, but think twice on your personal Mac.

Code signing fails over SSH

In a non-interactive session the login keychain is locked, so codesign fails. Unlock it at the start of each session:

security unlock-keychain ~/Library/Keychains/login.keychain-db

5. A typical overnight loop

  1. Before bed: "Add dark mode to Settings and make the tests pass."
  2. The agent edits, builds, runs the test suite on the Simulator and fixes what breaks.
  3. It captures light and dark screenshots and opens a PR with them attached.
  4. In the morning you review a green PR instead of a pile of compile errors.

Get a dedicated Mac with Xcode, ready for your agent

MacRent gives you a whole Mac mini (Xcode, iOS Simulators, Claude Code and Codex preinstalled), always on. Use it from your browser, over SSH or from your phone.

Try it for $12 / 24 hours Early access · monthly from $105 · no charge until your Mac is live · all plans

FAQ

Can Claude Code build iOS apps without a Mac?

Not reliably. It can write Swift anywhere, but compiling, running tests and using the iOS Simulator require Xcode, which only runs on macOS.

Does this work with OpenAI Codex too?

Yes. Put the same build and test instructions in AGENTS.md instead of CLAUDE.md. The Mac setup is identical.

Do I need an API key?

No. Claude Code and Codex can sign in with your existing Claude or ChatGPT subscription on the Mac.

Related guides