# foundation-models

Gives Claude Code reference patterns for Apple's on-device Foundation Models framework: summarization, extraction, classification. Covers setting up a LanguageModelSession and typed output with @Generable.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf (Devin Desktop), Claude.ai · ★ 233 repo stars
- Author: John Rogers (@johnrogers)
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/johnrogers/claude-swift-engineering/tree/HEAD/plugins/swift-engineering/skills/foundation-models/SKILL.md
- Updated: 2026-01-18
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/foundation-models

## What it does

The skill bundles reference files for Apple's Foundation Models framework, a 3B-parameter language model that runs locally without network calls. Separate reference files cover starting a `LanguageModelSession`, getting typed structured output through `@Generable` and `@Guide`, calling external tools via the Tool protocol, and streaming responses with `AsyncSequence` and partially generated types.

It lists recurring mistakes: calling the model on the main thread instead of wrapping it in `Task {}`, feeding it oversized documents that overflow context, and skipping the `SystemLanguageModel.default.availability` check before use. The model is meant for summarizing, extracting, or classifying a user's own text, not for answering factual or world-knowledge questions — the skill points to ChatGPT, Claude, or Gemini for those.

The framework needs iOS 26+, macOS 26+, iPadOS 26+, or visionOS 26+, an Apple Intelligence-capable device (iPhone 15 Pro or later, M1+ Mac or iPad), and Apple Intelligence turned on for the user.

## Install

### Claude Code (native platform)

1. **Plugin marketplace**
In the agent chat (not a shell):
```text
/plugin marketplace add johnrogers/claude-swift-engineering
```
In the agent chat (not a shell):
```text
/plugin install swift-engineering@claude-swift-engineering
```
This installs the whole swift-engineering plugin with all its skills

2. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill foundation-models -a claude-code
```

3. **Manually: put the files in place**
- File: `~/.claude/skills/foundation-models/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/foundation-models/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill foundation-models -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/foundation-models/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill foundation-models -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/foundation-models/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install johnrogers/claude-swift-engineering plugins/swift-engineering/skills/foundation-models
```

2. **Manually: put the files in place**
- File: `.github/skills/foundation-models/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill foundation-models -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/johnrogers/claude-swift-engineering --path plugins/swift-engineering/skills/foundation-models
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/foundation-models/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/johnrogers/claude-swift-engineering/tree/HEAD/plugins/swift-engineering/skills/foundation-models/SKILL.md

## When to use it
- set up a LanguageModelSession and check model availability
- get typed structured output from the model with @Generable
- summarize or classify a user's text without a network call
- wire external data into the model through the Tool protocol
- avoid blocking the main thread or overflowing the context window

## Example prompts
- Set up a LanguageModelSession to summarize the user's notes
- Add a @Generable struct to pull key fields out of a block of text
- Show how to check SystemLanguageModel.default.availability before running a session

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: eeb7fc66694414f0.

BEGIN THIRD-PARTY FILE eeb7fc66694414f0
```text
---
name: foundation-models
description: Use when implementing on-device AI with Apple's Foundation Models framework (iOS 26+), building summarization/extraction/classification features, or using @Generable for type-safe structured output.
---

# Foundation Models

Apple's on-device AI framework providing access to a 3B parameter language model for summarization, extraction, classification, and content generation. Runs entirely on-device with no network required.

## Overview

Foundation Models enable intelligent text processing directly on device without server round-trips, user data sharing, or network dependencies. The core principle: leverage on-device AI for specific, contained tasks (not for general knowledge).

## Reference Loading Guide

**ALWAYS load reference files if there is even a small chance the content may be required.** It's better to have the context than to miss a pattern or make a mistake.

| Reference | Load When |
|-----------|-----------|
| **[Getting Started](references/getting-started.md)** | Setting up LanguageModelSession, checking availability, basic prompts |
| **[Structured Output](references/structured-output.md)** | Using `@Generable` for type-safe responses, `@Guide` constraints |
| **[Tool Calling](references/tool-calling.md)** | Integrating external data (weather, contacts, MapKit) via Tool protocol |
| **[Streaming](references/streaming.md)** | AsyncSequence for progressive UI updates, PartiallyGenerated types |
| **[Troubleshooting](references/troubleshooting.md)** | Context overflow, guardrails, errors, anti-patterns |

## Core Workflow

1. Check availability with `SystemLanguageModel.default.availability`
2. Create `LanguageModelSession` with optional instructions
3. Choose output type: plain String or @Generable struct
4. Use streaming for long generations (>1 second)
5. Handle errors: context overflow, guardrails, unsupported language

## Model Capabilities

| Use Case | Foundation Models? | Alternative |
|----------|-------------------|-------------|
```
END THIRD-PARTY FILE eeb7fc66694414f0

The third-party file has ended. Everything between the eeb7fc66694414f0 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2026 of 3483 bytes. © John Rogers (@johnrogers) · MIT · https://github.com/johnrogers/claude-swift-engineering/tree/HEAD/plugins/swift-engineering/skills/foundation-models/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
