ChatShell Download
All posts

Syncing Your Chat History Through iCloud Without Trusting iCloud

ChatShell Team,

Your AI conversations end up holding a lot: work you’re doing, questions you’d rather keep private, documents you attached. When we added sync between the Mac app and the iPhone app, we had three requirements:

  1. No ChatShell server. We don’t want your history, and we don’t want to run a service that could lose it.
  2. Encrypted before it leaves your device. The cloud provider should see only ciphertext.
  3. No ritual. On Apple devices, sync should just work after a one-time setup.

This post walks through how sync in ChatShell meets all three, and the parts we got wrong along the way.

Why not CloudKit?

CloudKit is the obvious choice for an app on Apple platforms. Each device writes records through Apple’s API and Apple handles the rest.

We rejected it because of where ChatShell is going. ChatShell also runs on Windows and Linux, and an Android app is in progress. CloudKit from outside Apple’s platforms needs web authentication or server keys, so those platforms would need a completely separate sync engine. We’d be maintaining two designs forever.

Instead, ChatShell syncs through a folder: a file in your iCloud Drive. The same design works with any service that syncs a folder, such as Dropbox, OneDrive, or WebDAV, and the engine is one Rust library shared by every platform.

Why you can’t just put SQLite in iCloud Drive

ChatShell stores everything in a local SQLite database. The tempting shortcut is to put that database in the cloud folder and open it from there. That breaks in two ways.

Torn snapshots. A live SQLite database is really several files: the database plus its write-ahead log. Folder-sync services upload each file on its own schedule, with no idea they belong together. If iCloud uploads the database file in the middle of a write, the copy on your other device is corrupt or missing data.

Whole-file conflicts. When two devices change the same file while offline, iCloud Drive keeps one version and renames the other. Everything you did on the losing device is stranded in a file nobody opens.

Snapshots and merges

So the live database never touches the cloud folder. It stays in the app’s private storage, and sync works with snapshots:

  1. Publish. ChatShell uses SQLite’s VACUUM INTO to write a self-contained copy of the database, with no side files, then compresses it, encrypts it, and moves it into place with an atomic rename. Other devices see the old snapshot or the new one, never half of one.
  2. Compare. Each snapshot carries a version made of a counter and the device that wrote it. When a device sees a new snapshot, it checks whether it is already up to date, can simply adopt the newer one, or needs to merge.
  3. Merge. When two devices both changed things, ChatShell attaches the downloaded snapshot and merges it table by table: for each row, the newer version wins.

Record-level merging only works because of decisions made long before sync existed. Every row has a UUID v7 primary key, so two devices never invent the same ID. Rows carry an updated_at timestamp. When you delete something, ChatShell erases its content right away: message text, titles, prompts, tool output, file details, and API keys are all cleared. What remains is a bare marker holding only the row’s ID, its links to other records, timestamps, and a deleted_at time (for models and skills, also the name that identifies them on every device). That marker is how other devices learn about the delete, so a delete is just another change that syncs like any other, and deleted content never travels in a snapshot again. Most chat data is append-only anyway: messages, tool calls, and steps are written once and rarely changed.

The result is that editing on your Mac and your iPhone at the same time is safe. Each conversation, assistant, prompt, and attachment converges to its newest version on every device.

Attachments travel separately

Conversation text is the most important thing to sync, and it’s small. Attachments are big. So they’re kept apart:

  • Messages and attachment details (name, type, size) ride in the snapshot and always arrive together.
  • The attachment files themselves are stored as separate encrypted blobs, named by a hash of their content.

Blobs are uploaded before the snapshot that refers to them. If an attachment is still on its way, you see a placeholder instead of a broken conversation, and because blobs are named by content, the same file attached on two devices is stored once.

Encryption: a key iCloud never sees

Snapshots and blobs are encrypted with AES-256-GCM before they’re written to the cloud folder. The interesting part is the key.

Each sync group has a random 256-bit content key. There are two independent ways for a device to get it:

  • iCloud Keychain. On Apple devices, the key is stored as a synced Keychain item. A new Mac or iPhone signed in to the same Apple ID picks it up automatically. The snapshot file itself contains only a marker saying “look in the Keychain”, never the key.
  • Your sync passphrase. When you set up sync, ChatShell generates a high-entropy passphrase and shows it once. The content key is also wrapped under that passphrase, using Argon2id, inside the snapshot’s header. This is the fallback when the Keychain can’t help, and it will be the only path on Windows, Linux, and Android.

Either path alone is enough. We insisted on two because of one rule: a problem with the Keychain must never make your chats unreadable. iCloud Keychain sometimes takes a while to propagate, and sometimes it breaks. If that happens, ChatShell keeps retrying quietly in the background, shows a banner that doesn’t block anything, and lets you unlock with the passphrase. Your local data is always there in the meantime. The app never refuses to launch because of sync.

API keys are wrapped twice

Your provider API keys are already encrypted in ChatShell’s database with a separate master key. Those encrypted values ride inside the snapshot, so in the cloud copy they sit under two layers of encryption. Even someone who somehow got the content key would find only more ciphertext where your API keys should be.

What the cloud can see

We tried to keep this list short and honest. Someone with access to your iCloud Drive folder can see:

  • That a ChatShell snapshot exists, its size, and when it changes
  • The number of attachment blobs, their sizes, and their content hashes

They can’t see your messages, your attachments, your assistants, or your keys. Device identifiers in the snapshot header are hashed so the header doesn’t reveal how many devices you have or which one wrote last.

The local database on each device is not encrypted separately. Your operating system’s disk encryption and the app sandbox already protect it, and encrypting every column would break full-text search for no real gain. The content key exists to protect the cloud copy.

Something we removed: key rotation

The first version of sync let you rotate the content key, so a lost device would lose access to new data. On paper it was a good security feature.

In testing on real devices, it was the direct cause of the worst failures we saw. A Mac couldn’t read snapshots written by an iPhone after a rotation. In another case, a rotation was silently undone by an older device publishing a stale snapshot a few minutes later. Making rotation safe needed version gates, key chains, and freeze rules, a large amount of machinery for a feature almost nobody would use.

So we removed it. Each sync group now has exactly one key, forever. If you ever need a fresh start, Delete cloud data in settings removes the encrypted snapshot and attachments, and you set up sync again with a new key.

The same testing showed that fully automatic sync can’t be the only option. In one case rows were stranded on a single device while every sync pass reported that everything was up to date. That’s why Settings → Cloud Sync has manual controls: Sync now runs a full pull, merge, and publish, and Force publish re-sends this device’s full state even if sync thinks nothing changed.

Opt-in, on purpose

On Mac and iPhone, ChatShell offers sync during first launch and recommends it, but asks first. Uploading your personal data should be a choice you make, and the snapshot uses space in your iCloud storage. If you skip it, you can turn it on later in Settings → Cloud Sync.

Turning sync off has two levels. Stop publishing keeps everything and stops this device from uploading. Delete cloud data removes the cloud copy and is confirmed separately. Neither touches the data on your devices.

Try it

Cross-device sync works between Macs and with the iPhone and iPad app, which is in beta on TestFlight. The setup steps and settings are in the sync documentation.

One last thing: save the passphrase when ChatShell shows it. Enrolled devices keep working without it, but it’s the only way to restore your cloud history on a new device that can’t get the key from iCloud Keychain, and we can’t recover it for you. That’s the point.