Shipping a Custom Rive Mascot in a SwiftUI App with Claude Code and MCP
By the Charmotion team · Updated · How we write guides

Claude Code can write most of the code for a custom Rive mascot in a SwiftUI iOS app, provided you supply a finished .riv file with clear state inputs and the RiveRuntime Swift package. It cannot judge how the mascot reads on a real screen, so you still test each mood on a device before release.
Key takeaways
- Claude Code handles the repetitive wiring well: package references, the SwiftUI view and mood bindings.
- Install RiveRuntime with Swift Package Manager at 6.24.0 or newer, since the official guide says CocoaPods is in maintenance mode.
- Put the MCP server in .mcp.json so the whole team gets the same connection without a shared secret.
- Avoid the DataBind and bindViewModelInstance APIs that rive-ios 6.28.0 deprecated, and say so in your project rules.
- Test every mood on a physical device, because an assistant cannot judge motion quality.
Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.
What can Claude Code do for a custom Rive mascot in SwiftUI?
This guide covers how to add a custom Rive mascot to a SwiftUI iOS app using Claude Code, from connecting the assistant to a character server to shipping a build you have tested. It is written for a developer who already has an Xcode project and wants the mascot to react to app state rather than play one loop. For the wider background on adding animation to iOS, see how to add animation to an iOS app.
Claude Code is useful for the mechanical parts. It can edit Swift files, add a package reference to the project, write a view that wraps the Rive view and map app states to animation inputs. It cannot decide whether a mascot looks right, and it cannot repair a character that was drawn badly. Those checks stay with you.
The work splits into four parts:
- A finished .riv file with a state machine and clear inputs.
- The RiveRuntime package in the Xcode project.
- A SwiftUI view that loads the file and binds app state to it.
- A project rules file that tells Claude Code which APIs to use.
Get the first part right and the rest is routine. A file with no state machine forces the assistant to work around the gap for the whole session.
What should you set up in Xcode first?
Start with the platform floor. The official Apple runtime guide lists minimum targets of iOS 14.0, visionOS 1.0, tvOS 16.0, macOS 13.1 and Mac Catalyst 14.0. Set your deployment target at or above the lowest version you support, and test on that version.
Install the runtime with Swift Package Manager. The official guide gives a dependency on the rive-ios repository with a minimum version of 6.24.0 and names the product RiveRuntime. In Xcode, choose File, then Add Package Dependencies, paste https://github.com/rive-app/rive-ios, set the rule to 6.24.0 or newer and add RiveRuntime to your app target. The guide also says CocoaPods is in maintenance mode, so do not start a new project on it.
The samples in this guide follow the 6.28.0 release line, which changed how view models are bound. Check the 6.28.0 release notes before you copy older samples from blog posts, and check the releases page for newer tags.
Add the .riv file to the project and confirm it appears under your app target's membership. A file that sits in the folder but is not in the target will fail to load at runtime. For the runtime basics beyond this guide, see how to use Rive in SwiftUI.
How do you connect an MCP server to Claude Code?
Claude Code reads MCP servers from JSON. The official MCP docs list .mcp.json as one place to define them, alongside ~/.claude.json and the claude mcp add-json command. Third-party guides describe three scopes: local (the default, stored in ~/.claude.json under the current project), project (stored in .mcp.json at the repo root and shared through version control) and user. Confirm the scope flags against the official docs before you write them into a team README.
For a single machine, add the server from the terminal. This example uses Charmotion's remote MCP server, which uses Streamable HTTP and OAuth sign-in rather than an API key:
claude mcp add-json charmotion '{"type":"http","url":"https://charmotion.app/mcp"}'For a team, put the same server in .mcp.json at the repo root so everyone gets it on checkout:
{
"mcpServers": {
"charmotion": {
"type": "http",
"url": "https://charmotion.app/mcp"
}
}
}Three rules from the official docs matter here. The type field accepts streamable-http as an alias for http. An entry with a url but no type is treated as a stdio server and is a configuration error. Claude Code also expands environment variables inside .mcp.json, so a team can share the file while keeping any secret on each machine. The Charmotion server needs no secret, so the file is safe to commit.
Charmotion's server offers animated previews and guide search without an account. Designing a character or building an animation uses your plan. The MCP server page lists the tools, including create_character_set, get_character_set with download links and AI_README integration notes, and export_videos. For the same setup across other assistants, see how to animate a logo or character from Claude, Cursor or VS Code with MCP.
How do you show the .riv file in a SwiftUI view?
RiveViewModel loads a .riv file by its bundled name, and calling .view() returns the view you place in body. This is the pattern the official iOS and macOS guide shows. Keep the view small and let the view model own the file.
import SwiftUI
import RiveRuntime
struct MascotView: View {
@StateObject private var mascot = RiveViewModel(fileName: "mascot")
var body: some View {
mascot.view()
.frame(width: 180, height: 180)
}
}The same guide shows that RiveViewModel can load a file from a web URL through a webURL argument. For a mascot on the first screen, the bundled file is the safer choice, because the app does not wait on the network to show the character. Use a remote URL only for content that changes after release.
Set the size in the view rather than leaving it to the parent layout. That way each screen shows the mascot at the same size, and a designer can change one number when the layout changes.
How do you switch the mascot's mood from app state?
Mood switching is where most integrations go wrong. A Charmotion file has a CharacterViewModelMachine with a number property named mood, and a CharacterStateMachine with a number input named mood. The numbers are fixed: idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8 and attention 9. Moods blend into each other, so a change from loading to happy looks like a transition rather than a cut.
Characters have no one-shot triggers, so there is no success or error trigger. Show a success with happy and an error with sad. Map your app states to those numbers in one place, such as a small enum, so the mapping is easy to review.
The binding follows Rive's data binding model. The official data binding guide shows creating a view model instance, binding it with artboard.createStateMachine(binding:), and passing the state machine to Rive(file:artboard:stateMachine:). It also covers blank, default and indexed instances, and replacing the main instance later with an async throwing binding call. For the concepts behind this, see Rive data binding in SwiftUI.
Release 6.28.0 changes what you should write. It added global view model support to the Swift Concurrency API through Artboard.createStateMachine(binding:globals:). It made views redraw automatically after changes to bound main and global instances, including nested and list-item instances. It also deprecated DataBind, the Rive initializer that accepts dataBind:, Rive.viewModelInstance and the singular bindViewModelInstance method. Tell the assistant to use the newer path, because older tutorials still show the deprecated names.
What should you ask Claude Code to do?
A good prompt names the files, the version and the banned APIs. Use one like this:
Read AI_README.md and README.md in the character folder. Add the RiveRuntime product from rive-ios at 6.24.0 or newer with Swift Package Manager. Create MascotView with RiveViewModel(fileName: "mascot") and .view(). Map AppState.loading to mood 5, AppState.success to mood 1, AppState.error to mood 4 and AppState.idle to mood 0. Bind mood through the view model instance using the current API. Do not use DataBind, Rive.viewModelInstance or bindViewModelInstance. Build for iOS 14 and list every warning.
Put the stable rules in CLAUDE.md, which Claude Code loads at the start of each session. Include the minimum iOS version, the package name, the mood table and the list of deprecated APIs. The prompt can then stay short, and the rules apply to every later session. Keep the file in the repo, not in one developer's chat history.
Review the diff before you build. Check that the .riv file is referenced, that no second Rive package was added beside RiveRuntime, and that the mood mapping matches your table. Assistants sometimes add a fallback case that hides a missing state, so read the mapping line by line.
How do you test the mascot before release?
- Build for a simulator and a physical device at your deployment target, not only the newest iOS.
- Step through every app state and confirm the mood changes and blends, with no frozen frame.
- Check the mascot in light and dark appearance, and at the smallest size it appears in your layout.
- Confirm the mascot does not cover buttons or block taps on small phones.
- Watch CPU and energy use in Instruments on a loading screen that stays up for several seconds.
Rive does not document a file size limit or performance cap for this runtime, so measure the file on your target device rather than assuming it fits. Keep the .riv in the bundle only if it loads quickly on the oldest device you support.
Commit the .mcp.json, the Swift files and the rules file together, so the next developer or assistant session starts from the same setup.
How to add a custom Rive mascot to a SwiftUI iOS app using Claude Code
- Get a finished .riv file. Start with a Rive file that has a state machine and clear inputs, such as a number input for mood. A Charmotion download also includes SwiftUI code, a README and an AI_README for the assistant.
- Add the RiveRuntime package. In Xcode, add https://github.com/rive-app/rive-ios with Swift Package Manager at 6.24.0 or newer, and add the RiveRuntime product to your app target.
- Connect the MCP server. Run claude mcp add-json with a type of http and the server URL, or put the same entry under mcpServers in .mcp.json at the repo root so the team shares it.
- Show the mascot with RiveViewModel. Add the .riv file to the app target, create a RiveViewModel with its file name in a SwiftUI view and return mascot.view() from body with a fixed frame.
- Bind app state and test. Map each app state to its mood number using the current data binding API, avoid the deprecated DataBind and bindViewModelInstance names, build for your deployment target and test every mood on a device.
Frequently asked questions
Do I need a Rive plugin for Xcode or for Claude Code?
No Xcode plugin is needed. The runtime is a Swift package, and Claude Code edits Swift and JSON files like any other project file. An MCP server is only needed if you want the assistant to create or export the character or fetch its download links. Rive's runtimes are open source and play any .riv file, so your app needs no separate runtime license to show the mascot.
Can I use a Lottie animation instead of Rive in the same app?
Yes, but the code is different. Lottie uses its own package and playback API, and a plain Lottie timeline does not give you the state machine and data binding this guide relies on. For the Lottie route in SwiftUI, see Lottie in SwiftUI. Choose Lottie for a single timeline with no runtime input, and Rive when the mascot must change mood from app state.
Which iOS version should my deployment target be?
The Apple runtime guide lists iOS 14.0 as the minimum. Pick the lowest version your analytics support, then test the mascot on it. The rive-ios repository's Package.swift defines a binary target, so check the platform minimum of the exact release you pin, since a newer release can raise its floor.
Why does Claude Code keep using the old Rive initializer?
Older tutorials still show DataBind and bindViewModelInstance, which rive-ios 6.28.0 deprecated. Put the current API in CLAUDE.md, name the deprecated symbols as banned in the prompt, and build with warnings visible so a deprecation shows up before review.
Sources
- Rive Apple runtime guide, Rive
- Rive Apple data binding guide, Rive
- rive-ios release 6.28.0, Rive (GitHub)
- Connect Claude Code to tools via MCP, Anthropic
- How Claude remembers your project (CLAUDE.md), Anthropic
- Charmotion MCP server, Charmotion