Agent skill

Swift Mlx

by kellyvv in kellyvv/PhoneClaw

MLX Swift - High-performance ML framework for Apple Silicon with lazy evaluation, automatic differentiation, and unified memory

Apache-2.0Auto-check passedMobile

Install Swift Mlx

skills CLI
$ npx skills add kellyvv/PhoneClaw --skill swift-mlx -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install kellyvv/PhoneClaw swift-mlx --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/kellyvv/PhoneClaw.git skills-src && mkdir -p .claude/skills && cp -r skills-src/Packages/mlx-swift/skills/mlx-swift .claude/skills/swift-mlx && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
swift-mlx
GitHub stars
1.3k
Token cost
~2.8k tokens
SKILL.md length
483 words
Files
11 (incl. references)
Skills in repo
2
Repo updated
First seen
Licence
Apache-2.0

At a glance

MLX Swift - High-performance ML framework for Apple Silicon with lazy evaluation, automatic differentiation, and unified memory

  • Tasks that involve iOS development
  • SKILL.md covers When to Use This Skill, Architecture Overview, Key File Reference and Quick Start, plus 8 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Tasks that involve Deep learning

What it does

Swift Mlx is an agent skill from kellyvv/PhoneClaw. MLX Swift - High-performance ML framework for Apple Silicon with lazy evaluation, automatic differentiation, and unified memory

Its SKILL.md is about 2.8k tokens, which your agent loads only when the skill is triggered. The skill folder holds 11 other files, including reference files (for example `references/arrays.md`, `references/concurrency.md` and `references/custom-kernels.md`).

It sits in Mobile, covering iOS development and Deep learning. It works with Ollama and iOS. The repository describes itself as: PhoneClaw turns phones into local AI agent runtimes with on-device models, native mobile Skills, LiveLand, and optional Mac Gateway inference. The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve iOS development
  • Tasks that involve Deep learning

Example prompts

  • “/swift-mlx”

What it can do on your machine

Read from SKILL.md and the folder at commit 31bf61d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are swift).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Swift Mlx loads about 2.8k tokens when it runs, and up to ~20k if it reads all its reference files. Until then it costs about 34 tokens; SKILL.md has 483 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~34
When it runs · the whole SKILL.md, loaded when a task matches
~2.8k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~20k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from kellyvv/PhoneClaw at commit 31bf61d, republished under its Apache-2.0 licence (© kellyvv). 483 words, ~2,828 tokens.

Download SKILL.mdSave it as .claude/skills/swift-mlx/SKILL.md (or your agent's skills folder). This skill also uses 10 other files; get the full folder from GitHub.
name
swift-mlx
description
MLX Swift - High-performance ML framework for Apple Silicon with lazy evaluation, automatic differentiation, and unified memory
triggers
mlx, mlx-swift, mlx array, apple silicon ml, neural network swift, automatic differentiation swift, metal compute swift

MLX Swift Framework

MLX Swift is Apple's high-performance machine learning framework designed specifically for Apple Silicon. It provides NumPy-like array operations with lazy evaluation, automatic differentiation, and unified CPU/GPU memory.

When to Use This Skill

  • Array operations on Apple Silicon (MLXArray)
  • Building neural networks (MLXNN)
  • Training models with automatic differentiation
  • Custom Metal kernels via MLXFast
  • Performance optimization with JIT compilation

Architecture Overview

MLXOptimizers (Adam, AdamW, SGD, etc.)
       ↓
MLXNN (Layers, Modules, Losses)
       ↓
MLX (Arrays, Ops, Transforms, FFT, Linalg, Random)
       ↓
Cmlx (C/C++ bindings, Metal GPU)

Key File Reference

PurposeFile Path
Core arraySource/MLX/MLXArray.swift
OperationsSource/MLX/Ops.swift
TransformsSource/MLX/Transforms.swift
Factory methodsSource/MLX/Factory.swift
Neural layersSource/MLXNN/*.swift
OptimizersSource/MLXOptimizers/Optimizers.swift
Fast opsSource/MLX/MLXFast.swift
Custom kernelsSource/MLX/MLXFastKernel.swift
Wired memory coordinatorSource/MLX/WiredMemory.swift
GPU working-set helperSource/MLX/GPU+Metal.swift

Quick Start

Basic Array Creation
swift
import MLX

// Create arrays
let a = MLXArray([1, 2, 3, 4])
let b = MLXArray(0 ..< 12, [3, 4])  // Shape [3, 4]
let c = MLXArray.zeros([2, 3])
let d = MLXArray.ones([4, 4], dtype: .float32)

// Random arrays (use MLXRandom namespace or free functions)
let uniform = MLXRandom.uniform(0.0 ..< 1.0, [3, 3])
let normal = MLXRandom.normal([100])
Array Properties
swift
let array = MLXArray(0 ..< 12, [3, 4])
array.shape    // [3, 4]
array.ndim     // 2
array.size     // 12
array.dtype    // .int64
array.count    // 3 (first dimension)
Basic Operations
swift
let a = MLXArray([1.0, 2.0, 3.0])
let b = MLXArray([4.0, 5.0, 6.0])

// Arithmetic (lazy - not computed until eval)
let sum = a + b
let product = a * b
let matmul = a.matmul(b.T)

// Force evaluation
eval(sum, product)
// or
sum.eval()
Building a Neural Network
swift
import MLX
import MLXNN

class MLP: Module, UnaryLayer {
    @ModuleInfo var fc1: Linear
    @ModuleInfo var fc2: Linear

    init(inputDim: Int, hiddenDim: Int, outputDim: Int) {
        self.fc1 = Linear(inputDim, hiddenDim)
        self.fc2 = Linear(hiddenDim, outputDim)
        super.init()
    }

    func callAsFunction(_ x: MLXArray) -> MLXArray {
        var x = fc1(x)
        x = relu(x)
        return fc2(x)
    }
}

let model = MLP(inputDim: 784, hiddenDim: 256, outputDim: 10)
eval(model)  // Initialize parameters
Training Loop
swift
import MLXOptimizers

let model = MLP(inputDim: 784, hiddenDim: 256, outputDim: 10)
let optimizer = Adam(learningRate: 0.001)

func loss(model: MLP, x: MLXArray, y: MLXArray) -> MLXArray {
    let logits = model(x)
    return crossEntropy(logits: logits, targets: y, reduction: .mean)
}

// Compute loss and gradients - valueAndGrad returns a function
let lossAndGrad = valueAndGrad(model: model, loss)
let (lossValue, grads) = lossAndGrad(model, x, y)

// Update model
optimizer.update(model: model, gradients: grads)
eval(model, optimizer)

Primary Workflow: Array Operations

See arrays.md for detailed array creation and indexing.

Creation Functions
swift
// Zeros and ones
MLXArray.zeros([3, 4])
MLXArray.ones([2, 2], dtype: .float16)

// Ranges
arange(0, 10, 2)           // [0, 2, 4, 6, 8]
linspace(0.0, 1.0, 5)      // [0.0, 0.25, 0.5, 0.75, 1.0]

// Identity and diagonal
MLXArray.identity(3)
diagonal(array, offset: 0)

// Full
MLXArray.full([2, 3], values: 7.0)
Indexing
swift
let a = MLXArray(0 ..< 12, [3, 4])

// Single element
a[0, 1]

// Slicing
a[0...]           // All rows
a[..<2]           // First 2 rows
a[1..., 2...]     // From row 1, column 2 onwards

// Advanced indexing
a[.ellipsis, 0]       // First column of all dimensions
a[.newAxis, .ellipsis]  // Add dimension at front
Shape Manipulation
swift
let a = MLXArray(0 ..< 12, [3, 4])

a.reshaped([4, 3])
a.reshaped(-1, 6)     // Infer first dimension
a.T                    // Transpose
a.transposed(1, 0)     // Explicit transpose
a.squeezed()           // Remove size-1 dimensions
a.expandedDimensions(axis: 0)

Secondary Workflow: Neural Networks

See neural-networks.md for complete layer reference.

Built-in Layers
swift
// Linear layers
Linear(inputDim, outputDim, bias: true)
Bilinear(in1, in2, out)

// Convolutions
Conv1d(inputChannels, outputChannels, kernelSize: 3)
Conv2d(inputChannels, outputChannels, kernelSize: 3, stride: 1, padding: 1)

// Normalization
LayerNorm(dimensions)
RMSNorm(dimensions)
BatchNorm(featureCount)
GroupNorm(groupCount, dimensions)

// Attention
MultiHeadAttention(dimensions: 512, numHeads: 8)

// Recurrent
RNN(inputSize, hiddenSize)
LSTM(inputSize, hiddenSize)
GRU(inputSize, hiddenSize)

// Regularization
Dropout(p: 0.1)
Module Property Wrappers
swift
class MyLayer: Module {
    @ModuleInfo var layer: Linear           // Tracked module
    @ModuleInfo(key: "w") var weights: Linear  // Custom key

    let constant: MLXArray  // NOT tracked (no wrapper)
}
Loss Functions
swift
crossEntropy(logits: logits, targets: targets, reduction: .mean)
binaryCrossEntropy(logits: logits, targets: targets)
l1Loss(predictions: predictions, targets: targets, reduction: .mean)
mseLoss(predictions: predictions, targets: targets, reduction: .mean)
smoothL1Loss(predictions: predictions, targets: targets, beta: 1.0)
klDivLoss(inputs: inputs, targets: targets, reduction: .mean)

Tertiary Workflow: Training

See transforms.md for automatic differentiation details.

Gradient Computation
swift
// Simple gradient
let gradFn = grad { x in
    sum(x * x)
}
let g = gradFn(MLXArray([1.0, 2.0, 3.0]))

// Value and gradient together
let (value, gradient) = valueAndGrad { x in
    sum(x * x)
}(MLXArray([1.0, 2.0, 3.0]))

// Model gradients - valueAndGrad returns a function, call it to get results
let lossAndGradFn = valueAndGrad(model: model) { model in
    model(input)
}
let (loss, grads) = lossAndGradFn(model)
Optimizers

See optimizers.md for all optimizers.

swift
// Common optimizers
let sgd = SGD(learningRate: 0.01, momentum: 0.9)
let adam = Adam(learningRate: 0.001, betas: (0.9, 0.999))
let adamw = AdamW(learningRate: 0.001, weightDecay: 0.01)

// Training step
optimizer.update(model: model, gradients: grads)
eval(model, optimizer)
Compilation for Performance
swift
// Compile a pure array function for faster execution
let compiledOp = compile { (a: MLXArray, b: MLXArray) -> MLXArray in
    let x = a + b
    return sum(x * x)
}

// Use compiled version
let output = compiledOp(arrayA, arrayB)

// Note: compile() works best with pure MLXArray functions.
// For models, call model methods directly (they can use internal compilation).

Quaternary Workflow: Wired Memory Coordination

See wired-memory.md for full policy, hysteresis, and admission guidance.

swift
import MLX

let policy = WiredSumPolicy()

// Reservation: participates in admission but does not keep the wired limit high while idle.
let weightsTicket = policy.ticket(size: weightsBytes, kind: .reservation)
_ = await weightsTicket.start()

// Active work: raises limit while inference runs.
let inferenceTicket = policy.ticket(size: kvCacheBytes, kind: .active)
try await inferenceTicket.withWiredLimit {
    // run model inference
}

_ = await weightsTicket.end()

Best Practices

DO
  • Use lazy evaluation: MLX arrays are computed lazily. Call eval() strategically to control memory and compute.
  • Batch eval calls: eval(a, b, c) is more efficient than separate calls.
  • Use @ModuleInfo for all module properties to enable quantization and updates.
  • Use actors for concurrent code: Encapsulate MLX state within actors for thread safety.
  • Use namespaced functions: MLXRandom.uniform(), FFT.fft(), Linalg.inv().
  • Use ticket-based wired memory coordination: Prefer WiredMemoryTicket.withWiredLimit and WiredMemoryManager.shared.
DON'T
  • Don't share MLXArrays across tasks: MLXArray is NOT Sendable by design.
  • Don't use deprecated module imports: Use import MLX not import MLXRandom.
  • Don't forget to eval(): Unevaluated arrays can accumulate large compute graphs.
  • Don't mutate arrays directly: Use operations that return new arrays.
  • Don't call deprecated wired-limit APIs: Avoid GPU.withWiredLimit(...) and Memory.withWiredLimit(...).
Show full SKILL.md (180 more words)Show less

Deprecated Patterns

If you see...Use instead...
import MLXRandomimport MLX then MLXRandom.uniform() or free function uniform()
import MLXFFTimport MLX then FFT.fft()
import MLXLinalgimport MLX then Linalg.inv()
GPU.activeMemoryMemory.activeMemory
GPU.withWiredLimit(...)WiredMemoryTicket(...).withWiredLimit { ... } via WiredMemoryManager
Memory.withWiredLimit(...)WiredMemoryTicket(...).withWiredLimit { ... }
repeat(_:count:)repeated(_:count:)
addmm()addMM()
LogSoftMaxLogSoftmax
SoftMaxSoftmax

See deprecated.md for the complete migration guide.

Swift Concurrency Notes

MLX has specific concurrency behavior:

  • MLXArray is NOT Sendable: This is intentional. Arrays contain references to compute graphs.
  • evalLock protects eval/stream creation: The global lock serializes evaluation and stream operations.
  • Lazy operations are NOT thread-safe: Don't share arrays across tasks without proper synchronization.
  • Use actors to encapsulate MLX state: Create and use MLXArrays within the same actor.
  • Use wired-memory tickets for concurrent inference: Coordinate active/reservation budgets through the shared manager.

See concurrency.md for thread safety details.

Reference Documentation

© kellyvv, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 10 other files (references) in Packages/mlx-swift/skills/mlx-swift of kellyvv/PhoneClaw.

  • SKILL.md
  • references/arrays.md
  • references/concurrency.md
  • references/custom-kernels.md
  • references/custom-layers.md
  • references/deprecated.md
  • references/neural-networks.md
  • references/operations.md
  • references/optimizers.md
  • references/transforms.md
  • references/wired-memory.md

Open the folder on GitHubat commit 31bf61d

Compare with similar skills

Swift Mlx next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Swift Mlx compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Swift Mlx this skillkellyvv/PhoneClaw1.3k—~2.8kAutomated safety check: PassApache-2.0
Orca iOS Simulator Controlstablyai/orca89k1 repos~584Automated safety check: PassApache-2.0
Apple Crash Log .NET Symbolicationdotnet/skills5.6k1 repos~2.4kAutomated safety check: PassMIT
Update Swiftui APIsAvdLee/SwiftUI-Agent-Skill3.7k—~1.2kAutomated safety check: PassMIT
Mobilerun Docs Referencedroidrun/mobilerun9.6k—~943Automated safety check: PassMIT
Swiftui Liquid Glassharperreed/dotfiles3348 repos~941Automated safety check: PassNone

Similar skills

  • iOS Simulator control from inside Orca, with the live device view in Orca's emulator pane. Use when driving a booted Apple Simulator on macOS: taps, gestures…

    89k GitHub starsUsed in 1 repo~584 tokens
    MobileAuto-check passed
  • Official

    Resolves .NET runtime frames in Apple .ips crash logs to function names, source files and line numbers using dSYM symbols, atos and the Microsoft symbol server.

    5.6k GitHub starsUsed in 1 repo~2.4k tokens
    MobileAuto-check passed
  • Update Swiftui APIs

    AvdLee/SwiftUI-Agent-Skill

    Scan Apple's SwiftUI documentation for deprecated APIs and update the SwiftUI Expert Skill with modern replacements.

    3.7k GitHub stars~1.2k tokensUpdated 4 days ago
    MobileAuto-check passed
  • Mobilerun Docs Reference

    droidrun/mobilerun

    Answers questions about Mobilerun, the LLM-agent framework for automating Android and iOS devices, by pointing the agent to the right page of its v5 documentation.

    9.6k GitHub stars~943 tokensUpdated today
    MobileAuto-check passed
  • Swiftui Liquid Glass

    harperreed/dotfiles

    Implement, review, or improve SwiftUI features using the iOS 26+ Liquid Glass API.

    334 GitHub starsUsed in 8 repos~941 tokens
    MobileAuto-check passed
  • Swiftui Expert Skill

    omarshahine/HomeClaw

    A skill your agent uses when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state management, view composition, performance, Liquid Glass adoption, or Instruments .trace…

    175 GitHub starsUsed in 4 repos~2.8k tokens
    MobileAuto-check passed

More from kellyvv/PhoneClaw

  • Swift Mlx Lm

    kellyvv/PhoneClaw

    MLX Swift LM - Run LLMs and VLMs on Apple Silicon using MLX.

    1.3k GitHub stars~3.7k tokensUpdated 2 mo ago
    Auto-check passed

Works with

Categories

Questions about Swift Mlx

What does Swift Mlx do?

MLX Swift - High-performance ML framework for Apple Silicon with lazy evaluation, automatic differentiation, and unified memory. Swift Mlx is an agent skill from kellyvv/PhoneClaw.

When should I use Swift Mlx?

Swift Mlx fits situations like: tasks that involve iOS development; tasks that involve Deep learning.

How do I install Swift Mlx in Claude Code?

Run `npx skills add kellyvv/PhoneClaw --skill swift-mlx -a claude-code`. Or copy the skill folder (Packages/mlx-swift/skills/mlx-swift in kellyvv/PhoneClaw) into .claude/skills/swift-mlx in your project. Claude Code loads it when a task matches its description.

How do I install Swift Mlx in Codex?

Run `npx skills add kellyvv/PhoneClaw --skill swift-mlx -a codex`. Or copy the skill folder (Packages/mlx-swift/skills/mlx-swift in kellyvv/PhoneClaw) into .agents/skills/swift-mlx in your project. Codex loads it when a task matches its description.

Can I use Swift Mlx in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add kellyvv/PhoneClaw --skill swift-mlx -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/swift-mlx, .gemini/skills/swift-mlx, .github/skills/swift-mlx and .opencode/skills/swift-mlx in your project.

What does Swift Mlx need to run?

SKILL.md names no scripts, command-line tools or credentials: Swift Mlx is instructions for the agent only.

Does Swift Mlx access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Swift Mlx safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Swift Mlx use?

Swift Mlx is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Swift Mlx use?

About 2.8k tokens (SKILL.md is roughly 11k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 18k tokens, read only when the agent opens those files.

What are the alternatives to Swift Mlx?

Skills that share tags, products or a category with Swift Mlx: Orca iOS Simulator Control (stablyai/orca, 89k stars), Apple Crash Log .NET Symbolication (dotnet/skills, 5.6k stars), Update Swiftui APIs (AvdLee/SwiftUI-Agent-Skill, 3.7k stars) and Mobilerun Docs Reference (droidrun/mobilerun, 9.6k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Swift Mlx?

kellyvv (a GitHub user) maintains it in kellyvv/PhoneClaw, which has 1,268 GitHub stars. The repository holds 2 skills in this directory. The repository was last updated on August 6, 2026.

Source: kellyvv/PhoneClaw on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.