affaan-m/everything-claude-code/foundation-models-on-device
- community
Checking that the SKILL.md file is still in the repository.
Apple FoundationModels framework for on-device LLM — text generation, guided generation with @Generable, tool calling, and snapshot streaming in iOS 26+. Use when adding on-device LLM features with Apple FoundationModels on iOS 26+.
Install
npx vskill@latest install affaan-m/everything-claude-code/foundation-models-on-deviceSKILL.md
FoundationModels: On-Device LLM (iOS 26)
Patterns for integrating Apple's on-device language model into apps using the FoundationModels framework. Covers text generation, structured output with @Generable, custom tool calling, and snapshot streaming — all running on-device for privacy and offline support.
When to Activate
- Building AI-powered features using Apple Intelligence on-device
- Generating or summarizing text without cloud dependency
- Extracting structured data from natural language input
- Implementing custom tool calling for domain-specific AI actions
- Streaming structured responses for real-time UI updates
- Need privacy-preserving AI (no data leaves the device)
Core Pattern — Availability Check
Always check model availability before creating a session:
Core Pattern — Basic Session
Key points for instructions:
- Define the model's role ("You are a mentor")
- Specify what to do ("Help extract calendar events")
- Set style preferences ("Respond as briefly as possible")
- Add safety measures ("Respond with 'I can't help with that' for dangerous requests")
Core Pattern — Guided Generation with @Generable
Generate structured Swift types instead of raw strings:
1. Define a Generable Type
2. Request Structured Output
Supported @Guide Constraints
.range(0...20)— numeric range.count(3)— array element countdescription:— semantic guidance for generation
Core Pattern — Tool Calling
Let the model invoke custom code for domain-specific tasks:
1. Define a Tool
2. Create Session with Tools
3. Handle Tool Errors
Core Pattern — Snapshot Streaming
Stream structured responses for real-time UI with PartiallyGenerated types:
SwiftUI Integration
Key Design Decisions
| Decision | Rationale | |
|---|---|---|
| On-device execution | Privacy — no data leaves the device; works offline | |
| 4,096 token limit | On-device model constraint; chunk large data across sessions | |
| Snapshot streaming (not deltas) | Structured output friendly; each snapshot is a complete partial state | |
@Generable macro | Compile-time safety for structured generation; auto-generates PartiallyGenerated type | |
| Single request per session | isResponding prevents concurrent requests; create multiple sessions if needed | |
response.content (not .output) | Correct API — always access results via .content property |
Best Practices
- Always check `model.availability` before creating a session — handle all unavailability cases
- Use `instructions` to guide model behavior — they take priority over prompts
- Check `isResponding` before sending a new request — sessions handle one request at a time
- Access `response.content` for results — not
.output - Break large inputs into chunks — 4,096 token limit applies to instructions + prompt + output combined
- Use `@Generable` for structured output — stronger guarantees than parsing raw strings
- Use `GenerationOptions(temperature:)` to tune creativity (higher = more creative)
- Monitor with Instruments — use Xcode Instruments to profile request performance
Anti-Patterns to Avoid
- Creating sessions without checking
model.availabilityfirst - Sending inputs exceeding the 4,096 token context window
- Attempting concurrent requests on a single session
- Using
.outputinstead of.contentto access response data - Parsing raw string responses when
@Generablestructured output would work - Building complex multi-step logic in a single prompt — break into multiple focused prompts
- Assuming the model is always available — device eligibility and settings vary
When to Use
- On-device text generation for privacy-sensitive apps
- Structured data extraction from user input (forms, natural language commands)
- AI-assisted features that must work offline
- Streaming UI that progressively shows generated content
- Domain-specific AI actions via tool calling (search, compute, lookup)
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/foundation-models-on-device/SKILL.md
Popularity
- Repository stars
- 109,581
- Repository forks
- 14,296
- Repository npm downloads, 7 days
- 702
- 7-day trend score
- 75
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 22 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/affaan-m/everything-claude-code/foundation-models-on-device)