
view-refactor
Refactor macOS SwiftUI views and scenes into stable structure. Use when splitting large views, tightening scene state, or narrowing AppKit escapes.
- Installs
- 52
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/openai/plugins --skill view-refactor- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads view-refactor automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
View Refactor
Overview
Refactor macOS views toward small, explicit, stable scene and view types. Default to native SwiftUI for layout, selection, commands, and settings. Reach for AppKit only at the narrow edges where desktop behavior truly requires it.
Core Guidelines
1) Model scenes explicitly
- Break the app into meaningful scene roots: main window, settings, utility windows, inspectors, or menu bar extras.
- Do not let one giant root view silently own every desktop surface.
2) Keep a predictable file shape
- Follow this ordering unless the file already has a stronger local convention:
- Environment
private/publiclet@State/ other stored properties- computed
var(non-view) initbody- computed view builders / other view helpers
- helper / async functions
2b) Split files by responsibility
- For non-trivial apps, do not keep the full app, all views, models, stores, networking clients, process clients, and helpers in one Swift file.
- Accept a single Swift file only for tiny throwaway examples or snippets: roughly under 50 lines, one screen, no persistence, no networking/process client, and no reusable models.
- Use
App/<AppName>App.swiftfor the@mainapp andAppDelegateonly. - Keep
Views/ContentView.swiftfocused on root layout and composition; move feature UI into files such asViews/SidebarView.swift,Views/DetailView.swift, andViews/ComposerView.swift. - Move value types and selection enums into
Models/*.swift, stores intoStores/*.swift, app-server/network/process clients intoServices/*.swift, and small formatters/resolvers/extensions intoSupport/*.swift. - Keep files small and named after the primary type they contain.
3) Prefer dedicated subview types over many computed some View fragments
- Extract meaningful desktop sections like sidebar rows, detail panels, inspectors, or toolbar content into focused subviews.
- Keep computed
some Viewhelpers small and rare. - Pass explicit data, bindings, and actions into subviews instead of handing down the whole scene model.
4) Keep selection and layout stable
- Prefer one stable split or window layout with local conditionals inside it.
- Avoid top-level branch swapping between radically different roots when selection changes.
- Let the layout be constant; let state drive the content inside it.
5) Extract commands, toolbars, and actions out of body
- Do not bury non-trivial button logic inline.
- Do not mix command routing, menu state, and layout in the same block if they can be named clearly.
- Keep
bodyreadable as UI, not as a desktop view controller.
6) Use scene and app storage intentionally
- Use
@SceneStoragefor per-window ephemeral state when it truly helps restore the scene. - Use
@AppStoragefor durable preferences, not transient UI toggles that only matter in one window. - Keep scene-owned state close to the scene root.
7) Keep AppKit escape hatches narrow
- If a representable or
NSWindowbridge exists, isolate it behind a small wrapper or helper. - Do not let AppKit references spread through unrelated SwiftUI views.
- If the bridge starts owning the feature, re-evaluate the architecture.
8) Observation usage
- For
@Observablereference types on modern macOS targets, store them as@Statein the owning view. - Pass observables explicitly to children.
- On older deployment targets, fall back to
@StateObjectand@ObservedObjectwhere needed.
Workflow
- Identify the current scene boundary and whether the file is trying to do too much.
- Reorder the file into a predictable top-to-bottom structure.
- Extract desktop-specific sections into dedicated subview types.
- Stabilize the root layout around selection, scenes, and commands rather than top-level branching.
- Move action logic, command routing, and toolbar behavior into named helpers or separate types.
- Tighten any AppKit bridge so the imperative edge is small and explicit.
- Keep behavior intact unless the request explicitly asks for structural and behavioral changes together.
Refactor Checklist
- Split oversized view files before adding more UI.
- Move pure models, identifiers, and selection enums out of view files.
- Move
Process,URLSession, app-server, and platform client code out of SwiftUI views intoServices/. - Keep
AppDelegateand the@mainapp entrypoint minimal. - Build after each major split so compile errors stay local.
Common Smells
- A root view that mixes window scaffolding, settings, toolbar code, command handling, and detail layout.
- A single app file that mixes app entrypoint, root layout, feature views, models, stores, service clients, and support extensions.
- iOS-style push navigation forced into a Mac sidebar-detail problem.
- Several booleans for mutually exclusive inspectors, sheets, or utility windows.
- AppKit objects passed through many SwiftUI layers without a clear ownership reason.
- Large computed view fragments standing in for real subviews.
Notes
- A good macOS refactor should make scene structure, selection flow, and command ownership obvious.
- When the problem is fundamentally a missing desktop pattern, use
swiftui-patterns. - When the problem is fundamentally a boundary with AppKit, use
appkit-interop.
FAQ
What does the view-refactor skill do?
Refactor macOS SwiftUI views and scenes into stable structure. Use when splitting large views, tightening scene state, or narrowing AppKit escapes.
How do I install view-refactor?
Run npx skills add https://github.com/openai/plugins --skill view-refactor in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/view-refactor/ (personal) or .claude/skills/view-refactor/ (project).
Which AI agents can use view-refactor?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is view-refactor safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains view-refactor?
It is published by openai in openai/plugins, and it is an official skill from the maker of the technology it covers. It has 52 recorded installs.
More from openai/plugins
ios-memgraph-leaks
openai/plugins
Capture and inspect iOS leaks and memgraphs. Use when debugging leaked objects, retain cycles, memory growth, or before/after leak evidence.
android-emulator-qa
openai/plugins
Use when validating Android feature flows in an emulator with adb-driven launch, input, UI-tree inspection, screenshots, and logcat capture.
plugin-creator
openai/plugins
Create and scaffold plugin directories for Codex with a required .codex-plugin/plugin.json, optional plugin folders/files, and baseline placeholders you can edit before publishing or testing. Use when Codex needs to create a new personal plugin, add optional plugin structure, or generate or update personal or repo-root .agents/plugins/marketplace.json entries for plugin ordering and availability metadata.
frontend-app-builder
openai/plugins
Use for new frontend applications, dashboards, games, creative websites, hero sections, and visually driven UI from scratch, or when the user explicitly asks for a redesign/restyle/modernization. Builds from clean, airy, high-taste, readable image-generated concept design with section-specific references, faithful implementation, and browser testing.
frontend-testing-debugging
openai/plugins
Use when testing, debugging, or making targeted improvements to rendered frontend apps through the Build Web Apps or web dev plugin: local dev servers, UI regressions, interaction bugs, console errors, responsive layout, and visual QA. Check whether the Browser plugin is available and use it first when it is; otherwise use regular Playwright with the recorded reason.
swiftui-liquid-glass
openai/plugins
Implement and review iOS 26+ SwiftUI Liquid Glass UI. Use when adopting Liquid Glass or checking its correctness, performance, and design fit.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.