megastep/codex-skills/axiom-extensions-widgets

Claude Code and agent skill by megastep/codex-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when implementing widgets, Live Activities, or Control Center controls - enforces correct patterns for timeline management, data sharing, and extension lifecycle to prevent common crashes and memory issues

Install

npx vskill@latest install megastep/codex-skills/axiom-extensions-widgets

SKILL.md

The same SKILL.md was published earlier as megastep/codex-skills/axiom-extensions-widgets.

Extensions & Widgets — Discipline

Core Philosophy

"Widgets are not mini apps. They're glanceable views into your app's data, rendered at strategic moments and displayed by the system. Extensions run in sandboxed environments with limited memory and execution time."

Mental model: Think of widgets as archived snapshots on a timeline, not live views. Your widget doesn't "run" continuously — it renders, gets archived, and the system displays the snapshot.

Extension sandboxing: Extensions have:

  • Limited memory (~30MB)
  • No network access in widget views (fetch in TimelineProvider only)
  • Separate bundle container from main app
  • Require App Groups for data sharing

When to Use This Skill

✅ Use this skill when:

  • Implementing any widget (Home Screen, Lock Screen, StandBy, Control Center)
  • Creating Live Activities
  • Debugging why widgets show stale data
  • Widget not appearing in gallery
  • Interactive buttons not responding
  • Live Activity fails to start
  • Control Center control is unresponsive
  • Sharing data between app and widget/extension

❌ Do NOT use this skill for:

  • Pure App Intents implementation (use app-intents-ref)
  • SwiftUI layout questions (use swiftui-layout)
  • Performance profiling (use swiftui-performance)
  • General debugging (use xcode-debugging)

Related Skills

  • extensions-widgets-ref — Comprehensive API reference
  • app-intents-ref — App Intents for interactive widgets
  • swift-concurrency — Async patterns for data fetching
  • swiftdata — Using SwiftData with App Groups

Example Prompts

1. "My widget isn't updating"

→ This skill covers timeline policies, refresh budgets, manual reload, and App Groups configuration

2. "How do I share data between app and widget?"

→ This skill explains App Groups entitlement, shared UserDefaults, and container URLs

3. "Widget shows old data even after I update the app"

→ This skill covers container paths, UserDefaults suite names, and WidgetCenter reload

4. "Live Activity fails to start"

→ This skill covers 4KB data limit, ActivityAttributes constraints, authorization checks

5. "Control Center control takes forever to respond"

→ This skill covers async ValueProvider patterns and optimistic UI

6. "Interactive widget button does nothing"

→ This skill covers App Intent perform() implementation and WidgetCenter reload


Red Flags / Anti-Patterns

Pattern 1: Network Calls in Widget View

Time cost: 2-4 hours debugging why widgets are blank or show errors

Symptom
  • Widget renders but shows no data
  • Console errors: "NSURLSession not available in widget extension"
  • Widget appears blank intermittently
❌ BAD Code
swift
struct MyWidgetView: View {
@State private var data: String?
var body: some View {
VStack {
if let data = data {
Text(data)
}
}
.onAppear {
// ❌ WRONG — Network in widget view
Task {
let (data, _) = try await URLSession.shared.data(from: apiURL)
self.data = String(data: data, encoding: .utf8)
}
}
}
}

Why it fails: Widget views are rendered, archived, and reused. Network calls in views are unreliable and may not execute.

✅ GOOD Code
swift
// Main app — prefetch and save
func updateWidgetData() async {
let data = try await fetchFromAPI()
let shared = UserDefaults(suiteName: "group.com.myapp")!
shared.set(data, forKey: "widgetData")
WidgetCenter.shared.reloadAllTimelines()
}
// Widget TimelineProvider — read from shared storage
struct Provider: TimelineProvider {
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let shared = UserDefaults(suiteName: "group.com.myapp")!
let data = shared.string(forKey: "widgetData") ?? "No data"
let entry = SimpleEntry(date: Date(), data: data)
let timeline = Timeline(entries: [entry], policy: .atEnd)
completion(timeline)
}
}

Pattern: Fetch data in main app, save to shared storage, read in widget.

Can TimelineProvider make network requests?

Yes, but with important caveats:

swift
struct Provider: TimelineProvider {
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
Task {
// ✅ Network requests ARE allowed here
let data = try await fetchFromAPI()
let entry = SimpleEntry(date: Date(), data: data)
completion(Timeline(entries: [entry], policy: .atEnd))
}
}
}

Constraints:

  • 30-second timeout - System kills extension if getTimeline() doesn't complete
  • No background sessions - Can't download large files
  • Battery cost - Every timeline reload uses battery
  • Not guaranteed - May fail on poor connections

Best practice: Prefetch in main app (faster, more reliable), use TimelineProvider network as fallback only.


Pattern 2: Missing App Groups

Time cost: 1-2 hours debugging why widget shows empty/default data

Symptom
  • Widget always shows placeholder or default values
  • Changes in main app don't reflect in widget
  • UserDefaults reads return nil in widget
❌ BAD Code
swift
// Main app
UserDefaults.standard.set("Updated", forKey: "myKey")
// Widget extension
let value = UserDefaults.standard.string(forKey: "myKey") // Returns nil!

Why it fails: UserDefaults.standard accesses different containers in app vs. extension.

✅ GOOD Code
swift
// 1. Enable App Groups entitlement in BOTH targets:
// - Main app target: Signing & Capabilities → + App Groups → "group.com.myapp"
// - Widget extension target: Same group identifier
// 2. Main app
let shared = UserDefaults(suiteName: "group.com.myapp")!
shared.set("Updated", forKey: "myKey")
// 3. Widget extension
let shared = UserDefaults(suiteName: "group.com.myapp")!
let value = shared.string(forKey: "myKey") // Returns "Updated"

Verification:

swift
let containerURL = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: "group.com.myapp"
)
print("Shared container: \(containerURL?.path ?? "MISSING")")
// Should print path, not "MISSING"

Pattern 3: Over-Refreshing (Budget Exhaustion)

Time cost: Poor user experience, battery drain, widgets stop updating

Symptom
  • Widget updates frequently at first, then stops
  • Console logs: "Timeline reload budget exhausted"
  • Widget becomes stale after a few hours
❌ BAD Code
swift
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
// ❌ WRONG — 60 entries at 1-minute intervals
for minuteOffset in 0..<60 {
let date = Calendar.current.date(byAdding: .minute, value: minuteOffset, to: Date())!
entries.append(SimpleEntry(date: date, data: "Data"))
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}

Why it's bad: System gives 40-70 reloads/day. This approach uses 24 reloads/hour → exhausts budget in 2-3 hours.

✅ GOOD Code
swift
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
// ✅ CORRECT — 8 entries at 15-minute intervals (2 hours coverage)
for offset in 0..<8 {
let date = Calendar.current.date(byAdding: .minute, value: offset * 15, to: Date())!
entries.append(SimpleEntry(date: date, data: getData()))
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}

Guidelines:

  • 15-60 minute intervals for most widgets
  • 5-15 minutes for time-sensitive data (stocks, sports)
  • Use .atEnd policy for automatic reload
  • Let system decide optimal refresh based on user engagement

Pattern 4: Blocking Main Thread in Controls

Time cost: Control Center control unresponsive, poor UX

Symptom
  • Tapping control in Control Center shows spinner for seconds
  • Control seems "stuck" or frozen
  • No immediate visual feedback
❌ BAD Code
swift
struct ThermostatControl: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "Thermostat") {
ControlWidgetButton(action: GetTemperatureIntent()) {
// ❌ WRONG — Synchronous fetch blocks UI
let temp = HomeManager.shared.currentTemperature() // Blocking call
Label("\(temp)°", systemImage: "thermometer")
}
}
}
}

Why it's bad: Button renders on main thread. Blocking network/database calls freeze UI.

✅ GOOD Code
swift
struct ThermostatProvider: ControlValueProvider {
func currentValue() async throws -> ThermostatValue {
// ✅ CORRECT — Async fetch, non-blocking
let temp = try await HomeManager.shared.fetchTemperature()
return ThermostatValue(temperature: temp)
}
var previewValue: ThermostatValue {
ThermostatValue(temperature: 72) // Instant fallback
}
}
struct ThermostatValue: ControlValueProviderValue {
var temperature: Int
}
struct ThermostatControl: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "Thermostat", provider: ThermostatProvider()) { value in
ControlWidgetButton(action: AdjustTemperatureIntent()) {
Label("\(value.temperature)°", systemImage: "thermometer")
}
}
}
}

Pattern: Use ControlValueProvider for async data, provide instant previewValue fallback.


Pattern 5: Missing Dismissal Policy (Zombie Live Activities)

Time cost: User annoyance, negative reviews

Symptom
  • Live Activities stay on Lock Screen for hours after event ends
  • Users must manually dismiss completed activities
  • Activity shows "Delivered" but won't disappear
❌ BAD Code
swift
// Start activity
let activity = try Activity.request(attributes: attributes, content: initialContent)
// Later... event completes
// ❌ WRONG — Never call .end()
// Activity stays forever until user dismisses

Why it's bad: Activities persist indefinitely unless explicitly ended.

✅ GOOD Code
swift
// When event completes
let finalState = DeliveryAttributes.ContentState(
status: .delivered,
deliveredAt: Date()
)
await activity.end(
ActivityContent(state: finalState, staleDate: nil),
dismissalPolicy: .default // Removes after ~4 hours
)
// Or for immediate removal
await activity.end(nil, dismissalPolicy: .immediate)
// Or remove at specific time
let dismissTime = Date().addingTimeInterval(30 * 60) // 30 min
await activity.end(nil, dismissalPolicy: .after(dismissTime))

Best practices:

  • .immediate — Transient events (timer completed, song finished)
  • .default — Most activities (shows "completed" state for ~4 hours)
  • .after(date) — Specific end time (meeting ends, flight lands)

Pattern 6: Exceeding 4KB Data Limit (Live Activities)

Time cost: Activity fails to start silently, hard to debug

Symptom
  • Activity.request() throws error
  • Console: "Activity attributes exceed size limit"
  • Activity never appears on Lock Screen
❌ BAD Code
swift
struct GameAttributes: ActivityAttributes {
struct ContentState: Codable, Hashable {
var teamALogo: Data // ❌ Large image data
var teamBLogo: Data
var playByPlay: [String] // ❌ Unbounded array
var statistics: [String: Any] // ❌ Large dictionary
}
var gameID: String
var venueName: String
}
// Fails if total size > 4KB
let activity = try Activity.request(attributes: attrs, content: content)

Why it fails: ActivityAttributes + ContentState combined must be < 4KB.

✅ GOOD Code

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
3
7-day trend score
7

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/megastep/codex-skills/axiom-extensions-widgets/badge)](https://verified-skill.com/skills/megastep/codex-skills/axiom-extensions-widgets)

Something wrong with this skill or its page? Tell us.