Ask a coding agent to fix a slow screen and you get a familiar answer. It reads the view, finds something that looks expensive, changes it, and reports that performance is improved. There is no number in the report, because the agent never measured anything. It recognised a pattern and assumed the rest.
I wrote a skill called swiftui-perf to make that answer impossible. It finds and fixes slow screens, slow launch, hangs and laggy scrolling in SwiftUI apps. This post is less about SwiftUI and more about how the skill is built, because the same structure works for any skill where “it looks better” is not an acceptable result.
The short version
- A skill is a procedure plus scripts. The scripts hold every fact; the model only makes the judgement calls.
- The agent never guesses a project value. A setup step asks once and writes a config file.
- One variable changes per run, and a script checks it. The agent cannot compare two runs that differ in two ways.
- A fix is kept only if it beats the noise floor by 5% or more. Otherwise it is reverted and written down as “no measurable effect”.
- Temporary measuring code has to leave. A script must say “clean” before the work counts as done.
- The main skill file is 101 lines. It is a router to 14 reference files, read one phase at a time.
- The skill remembers how to do the work, not what the results were.
- One copy of the skill serves Claude Code, Codex, Cursor and Gemini CLI.
Scripts hold the facts
My rule from the last post was a script for facts and the model for judgement. A skill is where that rule pays off most, because a skill runs many times on projects I have never seen.
The first non-negotiable in the skill is “config first”. The agent may not guess a scheme, a bundle ID, a build configuration or a simulator. A setup script detects what it can, the agent asks the user the rest, and the answers go into .swiftui-perf.json. Every other script reads that file.
This sounds like ceremony until you hit the reason for it. If you pass xcodebuild a configuration name that does not exist, it does not fail. It quietly builds another configuration. An agent that guessed “Release” on a project that calls it “Prod” would profile a debug build and report the numbers with full confidence.
The rest of the scripts follow the same idea. One builds, one records a trace, one turns a trace into short JSON, one turns log lines into a table of how long each screen took to open. There are 11 of them, about 2,100 lines in total, written in Node and bash with no dependencies. The agent runs them and reads small outputs. It never reads a raw trace.
One variable per run, checked by a script
The rule I care about most is that an A/B comparison changes one thing. I learned why the hard way: in one session a debug network inspector was turned off and a security flag was turned on in the same run. The screen opened faster. Nothing in the data could say which change did it.
Writing “change one thing at a time” in a skill file is not enough. An agent in the middle of a long session will bundle two changes because it seems efficient. So each run records its variables in a small file, along with the git commit, and a script compares two runs:
$ node runlog.mjs diff runs/base-1 runs/h1-1
change: - -> h1
code: 4e1c9a2 -> 4e1c9a2+dirty (name the code change in a key, for example change=h1)
ok: one variable changed
With two differences it prints not comparable: 2 variables changed; split into A/B runs that change one each and exits with an error. With none it says the run is a repeat, not an A/B. The agent cannot argue with an exit code.
The same script refuses to overwrite a run. A baseline that can be replaced is not a baseline.
Keep or revert is a table, not a feeling
After the measurement, the agent has to decide. That decision is where a model is most tempted to be generous to its own work, so the skill takes most of it away:
| Result | Decision |
|---|---|
| Better than the noise floor and at least 5% | keep |
| Inside the noise floor | revert, write “no measurable effect” |
| Worse | revert |
| Better on the simulator, not checked on a device | keep as “sim delta only” |
The details around the table matter as much. The decision uses the median, not the mean. The first run after an install is thrown away because the caches are cold. A second screen that nobody touched is measured as a control, and if the control moved too, the change is noise. Simulator numbers are only ever relative.
The report has the same discipline. Each finding has a status: kept, proposed or suspected. Without a run ID, a trace or a count behind it, the status is “suspected” and nothing stronger.
Temporary code has to leave
To measure a screen, the skill adds timing markers to the app. That is code I do not want in a commit. So the markers go in through one script and come out through the same script, and a third command reports the state. The skill’s definition of done includes that command printing “clean” and no measuring code showing in git diff.
The rule works for any skill that touches a project: anything the skill puts in, a script takes out, and a check proves it.
The skill file is a router
The main SKILL.md is 101 lines. It has the rules, a table of eight phases, and for each phase the reference file to read and the output to produce. The 14 reference files add up to about 1,000 lines, and the agent reads each one only when it reaches that phase.
- 0 Setup
- 1 Intake
- 2 Field data
- 3 Static scan
- 4 Instrumented run
- 5 Trace analysis
- 6 Fix loop
- 7 Report
- 00-setup
- 01-rendering-internals
- 02-hidden-apis-and-lldb
- 03-code-smells
- 04-instruments-xctrace
- 05-screen-open-metrics
- 06-launch
- 07-network-wait
- 08-field-data
- 09-test-environment
- 10-experiment-protocol
- 11-report-template
- 12-project-memory
This is the context lesson from the last post applied to skill design. Whatever is in the context is paid for on every call. A skill that puts Instruments details, LLDB tricks and launch-time theory in one file makes the agent carry all of it while it is only asking setup questions.
Each reference ends with a block called “Action plan output”, which the agent writes into a findings log when the phase ends. The log is on disk, so a session that stops halfway can be picked up.
Memory for the route, not the result
The skill keeps a small JSON file in the project, meant to be committed. It holds three things:
- Routes. How to reach a screen, as steps a new agent can repeat: “Tap the Profile tab (bottom right)”, then what to wait for.
- Obstacles. Something that blocked the work, together with what fixed it. For example a release build that closes itself on the simulator after five seconds, and the build flag that stops it.
- Facts. Stable things about the project that the config does not hold.
- 1 Launch the app and wait for the tab bar
- 2 Close the campaign popup if it shows (Close, top right)
- 3 Tap the Profile tab (bottom right)
- ✓ Ready when: the user name label is visible
The agent does not edit this file. A script does. It refuses text that looks like a password or a token. If the same obstacle is recorded twice, it raises a counter instead of adding a line. A new route replaces the old one.
One rule in that reference is “not for results”. Measurements go in the report. A number from last month is wrong today; the way to reach the Profile screen is probably still right. I have a second post on what happens when an agent’s memory ignores that rule.
One source, four agents
The skill format is nearly the same across Claude Code, Codex, Cursor and Gemini CLI, so there is one copy of the skill and five small manifest files that point at it. A validation script runs before each commit. It syntax-checks every script, parses every JSON file, and checks that the name, version and description match in all the manifests.
The skill text never mentions a project. No scheme names, no SDK names, no simulator IDs. If a fact belongs to one project, it comes from the config.
What I would copy into any skill
- Ask once, write a config, and never let the agent guess a value a script will use.
- Put each rule that matters behind a script with an exit code.
- Decide in advance what “better” means, with a number.
- Give every temporary change a way out and a check.
- Keep the main file short and route to the detail.
- Let the skill remember procedure. Leave results in the report.