Core Data with AI agents: stacks, contexts, migrations and audits
Install a dedicated Core Data skill so the agent builds an NSPersistentContainer stack, keeps NSManagedObjectContext work on the right queue, and plans lightweight or custom migrations — do not let it treat Core Data like SwiftData @Model/@Query, and add a data-model audit skill when relationships and migrations drift.
Last updated:
This page is about getting a coding agent to ship Core Data correctly: an NSPersistentContainer stack, queue-safe contexts, fetch and batch updates, model migration, and optional CloudKit sync. For @Model / @Query work, see SwiftData with AI agents. For Claude Code-only skill shopping lists, see Best Claude Code skills for SwiftUI.
What the agent has to get right
Core Data lets you "persist or cache data on a single device, or sync data to multiple devices with CloudKit." Agents that only know SwiftData will invent @Model types inside a Core Data project, share one context across queues, or rewrite the store on every launch.
Three layers show up in almost every PR:
Stack — set up the stack with
NSPersistentContaineras in Setting Up a Core Data Stack and Creating a Core Data Model.Contexts — keep
NSManagedObjectContextwork on the right queue; passNSManagedObjectIDbetween queues; use background contexts for imports (Loading and Displaying a Large Data Feed, Batch Processing).Migration and sync — version the model and prefer lightweight migration when possible; for iCloud use
NSPersistentCloudKitContainerand follow Synchronizing a Local Store to the Cloud / Consuming Relevant Store Changes.
Rules worth adding to AGENTS.md or CLAUDE.md:
Core Data: use NSPersistentContainer (or NSPersistentCloudKitContainer). Never pass NSManagedObject or a context across queues — pass NSManagedObjectID and use perform(_:). Prefer lightweight migration; write a mapping model only when needed. Do not invent SwiftData @Model APIs in a Core Data target.
Step 1: install a Core Data skill
Ask the agent to:
Install Core Data Expert (
npx skills add https://github.com/AvdLee/Core-Data-Agent-Skill) as the primary Core Data coach.Optionally install Swift and Apple platform skills (fal3) and select
swiftdata-core-data-migrationswhen a store upgrade dominates.Swift Skills Pro (
/plugin install core-data-pro@swift-skills-proornpx swift-skills-cli install) and Radar Suite (/plugin install radar-suite@radar-suite) add a focused core-data-pro skill and a cross-file data-model audit.
Honest limit: do not install every persistence pack at once. One dedicated Core Data skill plus fal3 when migrations dominate is enough for most PRs.
Step 2: stack and contexts, not SwiftData APIs
Point the agent at Apple's Setting Up a Core Data Stack and NSPersistentContainer pages. Require:
A real
.xcdatamodeld(or programmatic model) loaded by the container — not ad-hoc JSON files pretending to be Core Data.A view context for UI reads and background contexts for imports; no shared mutable context across queues.
Object IDs at queue boundaries;
perform/performAndWaitfor context work.Batch inserts/deletes for large feeds per Apple's batch processing guidance — not one
save()per row on the main queue.
Step 3: migrate before you sync
When the model changes:
Add a new model version; enable lightweight migration when the change is inferable.
Use a custom mapping / migration manager only when lightweight migration cannot express the transform.
For CloudKit, start from NSPersistentCloudKitContainer and Apple's synchronizing / consuming-store-changes articles — do not roll a private CloudKit schema by hand next to an incompatible model.
Step 4: audit models across files after merge
After Radar Suite merges, run its data-model-radar skill on SwiftData and Core Data definitions when relationships, serialization or migration safety look wrong across modules. It is an audit router, not a substitute for Core Data Expert during stack setup.
Tools compared (4)
| Tool | Best for | Agents (README) | Install (README) | License | Stars | Last push |
|---|---|---|---|---|---|---|
| Core Data Expert (AvdLee) | Dedicated Core Data skill: safe persistence, performance and schema migration | Claude Code, Cursor, Codex | npx skills add https://github.com/AvdLee/Core-Data-Agent-Skill | MIT | 318 | 14 Sep 2026 ⚠ |
| Swift and Apple platform skills (fal3) (fal3) | Collection including swiftdata-core-data-migrations for schema changes, store upgrades and persistence migrations | Claude Code, Codex | git clone https://github.com/fal3/claude-skills-collection.git then python3 scripts/install_skills.py --dest "$HOME/.agents/skills" | MIT | 19 | 28 Oct 2026 |
| Swift Skills Pro (laxrajpurohit) | core-data-pro: modeling, background contexts, fetch requests, batching and migration (plus 11 other Swift topics) | Claude Code, Cursor, Codex, Windsurf | /plugin marketplace add laxrajpurohit/swift-skills-pro then /plugin install core-data-pro@swift-skills-pro (or npx swift-skills-cli install) | MIT | 6 | 18 Oct 2026 |
| Radar Suite (Terryc21) | Claude Code audit plugin; data-model-radar covers SwiftData/Core Data field completeness, relationships, migration safety | Claude Code | /plugin marketplace add Terryc21/radar-suite then /plugin install radar-suite@radar-suite | Apache-2.0 | 20 | 20 Oct 2026 |
⚠ = no push for more than 4 weeks. fal3 was pushed on 28 Oct 2026. Core Data Expert (14 Sep) is older — verify API names against the current SDK before treating every tip as current.
Which one to pick:
Default Core Data coaching: Core Data Expert.
Store upgrade / migration-heavy PR: fal3
swiftdata-core-data-migrations.Background contexts + batching after merge: Swift Skills Pro
core-data-pro.Cross-file model audit after merge: Radar Suite
data-model-radar.
A prompt that keeps the agent honest
Setting up the agent itself: Claude Code for iOS development, Codex for iOS development or Cursor rules for SwiftUI.
Add an NSPersistentContainer stack with a view context and a background context for imports. Entities use NSManagedObject subclasses. Never pass managed objects across queues — pass object IDs. Add a new model version with lightweight migration for a renamed attribute. Do not introduce SwiftData @Model types in this target.
FAQ
- What is Core Data for AI coding agents?
- Core Data is Apple's framework to persist or cache data on a device and optionally sync with CloudKit. Agent skills teach Claude Code, Cursor or Codex to set up an NSPersistentContainer stack, keep NSManagedObjectContext work thread-safe, write fetch requests and batch updates, and migrate the model without corrupting the store.
- How does this differ from the SwiftData guide?
- The SwiftData with AI agents guide (queued) owns @Model, @Query, ModelActor and VersionedSchema. This page owns Core Data stacks, contexts, NSPersistentCloudKitContainer and Core Data migrations. Use a Core Data skill for NSManagedObject code; use a SwiftData skill when the project is already on SwiftData.
- Should the agent pass NSManagedObject instances across queues?
- No. Apple's Core Data stack and NSManagedObjectContext documentation treat contexts as queue-bound. Pass NSManagedObjectID values between queues, perform work with perform(_:) / performAndWait(_:), and keep UI reads on a view context. Skills that cover background contexts exist so the agent does not invent shared mutable contexts.
- Which tool should I install first for Core Data?
- Start with Core Data Expert (AvdLee) for safe persistence, performance and schema migration. Add fal3's swiftdata-core-data-migrations skill when a store upgrade dominates. Swift Skills Pro core-data-pro covers modeling, background contexts, fetch requests, batching and migration, and Radar Suite's data-model-radar audits SwiftData and Core Data models across files.
- Does Radar Suite replace a Core Data expert skill?
- No. Radar Suite is a Claude Code audit plugin that finds cross-file data-model bugs; it does not teach stack setup. Use Core Data Expert or core-data-pro to write the stack, then Radar Suite after merge when you want an audit of models, relationships and migration safety.