Skip to content
Documentation
Esc
↑↓navigate↵open⌘Jpreview
On this page

Disk snapshots

Reuse build state across Xcode instances with disk snapshots and branch fallbacks.

Use a disk snapshot to carry source files, dependencies, and Xcode’s DerivedData into your next instance. Snapshots belong to your organization. The CLI turns snapshots on for a new Xcode instance when it can derive a project key from Git origin.

Automatic project keys

The default key is the origin’s host and repository plus the project’s directory inside the repository. Building apps/ios in git@github.com:acme/monorepo.git uses github.com/acme/monorepo/apps/ios. HTTPS and SSH origins produce the same key. Branch names, commit hashes, and local checkout paths are not part of it, so every branch, clone, and worktree shares the key.

The CLI reads the repository’s own Git files and does not need the Git executable, so worktrees and submodules work too. It walks up from the project path to find .git. Pass an explicit --snapshot-key when the checkout has no Git metadata, or when its origin comes from config includes or global URL rewrites.

lim xcode build, test, and sync derive the key from the path you pass. lim xcode create and lim ios create --xcode use the current directory. lim run uses the detected or cloned project. The CLI prints the key it uses, and sets it as both the restore and the save key. Existing instances keep their original configuration.

Pass --snapshot-key to choose another key, or --no-snapshot to create without a snapshot. Explicit restore-only settings stay restore-only. SDK callers set spec.snapshot.key themselves.

When a build’s sandbox has no snapshot configuration, the build result ends with a tip to pass --snapshot-key. JSON output and --no-snapshot leave the tip out.

Keep the default for ordinary builds. If you switch Xcode versions or need a separate snapshot per branch, choose separate keys. Concurrent publications to one key replace each other; the last publication wins.

Save and reuse a disk snapshot

With the CLI or TypeScript SDK installed and LIM_API_KEY set, create an instance, build, and delete the instance from your project directory. Replace MyApp with your scheme:

XCODE_ID=$(lim xcode create --quiet)
lim xcode build . --id "$XCODE_ID" --scheme MyApp
lim xcode delete "$XCODE_ID" --wait-snapshot
import Limrun from '@limrun/api';

const lim = new Limrun({ apiKey: process.env['LIM_API_KEY'] });
const instance = await lim.xcodeInstances.create({
  wait: true,
  spec: { snapshot: { key: 'myapp-main' } },
});

try {
  const { snapshot, gone } = await lim.xcodeInstances.followSnapshot(instance.metadata.id);
  if (gone) throw new Error('Instance ended before the build could start');
  if (snapshot.restore.phase === 'failed') {
    console.warn(snapshot.restore.message ?? 'Snapshot unavailable; building with a cold workspace');
  }

  const xcode = await lim.xcodeInstances.createClient({ instance });
  await xcode.sync('./my-app');
  const result = await xcode.xcodebuild({ scheme: 'MyApp' });
  if (result.exitCode !== 0) throw new Error(`Build ${result.status}`);
} finally {
  await lim.xcodeInstances.delete(instance.metadata.id);
}

The CLI example uses the automatic project key. TypeScript only: the settings go in spec.snapshot, and the instance must finish its restore before you sync. followSnapshot(id) waits for it, as the example does.

The first run builds from scratch. After a successful build, deleting the instance saves its workspace under that key. Run the same sequence again to restore that snapshot before building. Each successful publication replaces the previous archive under that key.

--wait-snapshot waits for publication and prints its result. Without it, deletion returns while publication continues in the background. Wait for publication before starting a build that needs the new snapshot. In CI, put the delete command in a cleanup step that runs even if the build fails.

TypeScript only: deletion returns before publication finishes. To track progress, use getSnapshot(id) for the current state or followSnapshot(id, { side: 'save' }) for updates. Start the save watcher and wait for its onOpen callback before deleting, so it can observe publication before the instance disappears. A save phase of published confirms success; skipped means nothing was saved.

Leave --snapshot-paths unset to save the whole workspace. This keeps source files and their sync state alongside DerivedData so Xcode can reuse unchanged build outputs. --basis-cache-dir is a separate, local cache for source uploads; it does not preserve remote build state.

You can keep building on the same running instance without restoring again. The saved snapshot is for future instances and is only published when this instance terminates.

Use --snapshot-ttl to expire a snapshot a set time after publication, for example --snapshot-ttl 7d or 12h. Each save starts a new TTL, and restoring a snapshot leaves its deadline unchanged. The default is 30 days. Without --snapshot-key, the TTL applies to the Git-derived key, and the command fails if the CLI cannot derive one. In the TypeScript SDK, set spec.snapshot.ttlSeconds to the duration in seconds.

Restore from another branch

Use --snapshot-key for the destination and --snapshot-restore-keys for an ordered list of sources. For example, restore a pull request’s previous snapshot, falling back to main, then save under the pull request’s key:

XCODE_ID=$(lim xcode create \
  --snapshot-key myapp-pr51 \
  --snapshot-restore-keys "myapp-pr51,myapp-main" \
  --quiet)
lim xcode build . --id "$XCODE_ID" --scheme MyApp
lim xcode delete "$XCODE_ID" --wait-snapshot
const instance = await lim.xcodeInstances.create({
  wait: true,
  spec: {
    snapshot: {
      key: 'myapp-pr51',
      restoreKeys: ['myapp-pr51', 'myapp-main'],
    },
  },
});
// Then wait for the restore, build, and delete as in the first example.

For each restore key, Limrun tries an exact match, then the most recently published snapshot whose key starts with that prefix. It moves to the next restore key only if neither matches. Prefixes are literal; no * is needed. With no match, the instance starts cold and can save a new snapshot after building.

When --snapshot-restore-keys is omitted, --snapshot-key is also the restore key. When you supply a restore list, include the destination key yourself if you want to try it first.

To consume a snapshot without replacing it, create an instance with only restore keys:

lim xcode create --snapshot-restore-keys myapp-main
const instance = await lim.xcodeInstances.create({
  wait: true,
  spec: { snapshot: { restoreKeys: ['myapp-main'] } },
});

Build on that instance as usual and delete it when finished. It will not publish a snapshot unless you explicitly bind a destination key later.

For workflows that alternate Xcode versions, override the project default with keys that name the version, such as myapp-xcode27-main. Keep fallbacks within the same Xcode version. For concurrent CI jobs, use separate destination keys to avoid overwriting each other’s results.

Inspect and delete saved snapshots

Open Snapshots in the console to see keys, archive sizes, publication times, and Xcode versions. Select a key for details or select Delete to remove its saved workspace.

The CLI lists, inspects, and deletes snapshots by exact key:

lim xcode snapshot list --prefix myapp- --limit 25 --json
lim xcode snapshot get myapp-main
lim xcode snapshot delete myapp-main

flush is an alias for delete. Deletion removes the saved archive and its key from the snapshot list. It also cancels incomplete uploads under that exact key. Other keys are unaffected. Running instances keep their workspaces and can save the key again. To keep it empty, stop instances that save the key, wait for their publication to finish, then delete the snapshot.

Lists return snapshots and, when another page exists, nextOffset. Pass that value as --offset on the next list command. The CLI uses your login or API key’s organization by default; --organization selects another organization you can access.

The TypeScript SDK exposes the same operations. Set organizationId to your organization ID:

import Limrun from '@limrun/api';

const lim = new Limrun({ apiKey: process.env.LIM_API_KEY });
const organizationId = 'org_...';
const page = await lim.xcodeSnapshots.list(organizationId, {
  prefix: 'myapp-', limit: 25,
});
const snapshot = await lim.xcodeSnapshots.get(organizationId, 'myapp-main');
await lim.xcodeSnapshots.delete(organizationId, snapshot.key);

Pass page.nextOffset as offset to read another page when it is defined. Listing and inspecting require Xcode read access; deletion requires Xcode control. An unavailable snapshot returns 404. If storage cleanup fails, deletion reports an error and keeps the key available for another attempt.

Configure disk snapshots before the build

Set snapshot options on lim xcode create for predictable behavior. Restore keys and snapshot paths are fixed when the instance is created. --reuse-if-exists keeps the reused instance’s original configuration.

lim xcode build --snapshot-key ... also works when the command creates a new instance. On an existing instance, it only binds a save destination to a workspace already prepared for snapshots. It does not restore a snapshot or enable snapshots on an instance created without snapshots. Once a destination key is set, it cannot be changed for that instance.

Existing --cache-* flags, --wait-cache, spec.cache, and cache-named SDK methods remain supported for compatibility. Use the snapshot names in new integrations.

Understand a cold build or skipped save

A snapshot is optional build state. If its checksum does not match or its download fails, the instance remains usable with a cold workspace. The CLI reports the failure and continues. It also continues if snapshot-status updates become unavailable. An instance that has terminated still cannot run a build.

In SDK integrations, treat a terminal restore.phase === 'failed' as a cold fallback, as in the example above. Sync the project and build normally. A successful build can publish a replacement snapshot when the instance terminates.

  • Keep the synced project folder’s name the same between runs. A different folder name puts the source at a different remote path, so Xcode cannot reuse the previous build state.
  • Changing Xcode versions clears incompatible cached build state. Use a separate snapshot key for each version.
  • A restore must use the same snapshot path set as the saved archive. Use a new key if you change that set.
  • A failed compile or cancelled build does not produce a new snapshot. A test build can still save its snapshot if compilation succeeds but tests fail. Syncing changes after a successful build prevents saving until another build succeeds. Running commands with lim xcode run alone does not qualify a workspace for publication.
  • A concurrent instance using the same restored workspace on the same host can cause a cold fallback with saving disabled. The CLI reports the restore outcome; check the --wait-snapshot output for the save outcome.

Last updated on