Background Processing logo

Background Processing

Community
rshankras
background-processing

Generates background processing infrastructure with BGTaskScheduler, background refresh, background downloads, and silent push handling. Use when user needs background tasks, periodic refresh, background URLSession downloads, or silent push notification processing.

Overview

Publisherrshankras
Repositoryclaude-code-apple-skills
Skill namebackground-processing
Stars
744
Forks
70
Bundled files
1
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by rshankras on GitHub. Read the source before you install it.

Installation

Install the Background Processing AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/rshankras/claude-code-apple-skills.git /tmp/claude-code-apple-skills
mkdir -p .claude/skills
cp -r /tmp/claude-code-apple-skills/skills/generators/background-processing .claude/skills/background-processing
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Background Processing in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Background Processing on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Background Processing is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Background Processing Generator

Generate production background processing infrastructure -- BGTaskScheduler for periodic refresh and long-running tasks, background URLSession for downloads/uploads that survive app termination, and silent push handling for server-triggered updates.

When This Skill Activates

Use this skill when the user:

  • Asks to "add background processing" or "background tasks"
  • Mentions "BGTaskScheduler" or "BGAppRefreshTask" or "BGProcessingTask"
  • Wants "background refresh" or "periodic background updates"
  • Asks about "background downloads" or "background uploads"
  • Mentions "silent push" or "content-available push notifications"
  • Wants data to sync or update while the app is in the background
  • Asks about "background fetch" or "background execution"

Pre-Generation Checks

1. Project Context Detection

  • Check deployment target (BGTaskScheduler requires iOS 13+)
  • Check Swift version (requires Swift 5.9+)
  • Check for @Observable support (iOS 17+ / macOS 14+)
  • Identify source file locations

2. Existing Background Task Detection

Search for existing background task code:

Glob: **/*BackgroundTask*.swift, **/*BGTask*.swift, **/*BackgroundDownload*.swift
Grep: "BGTaskScheduler" or "BGAppRefreshTask" or "BGProcessingTask" or "backgroundSession"

If existing background code found:

  • Ask if user wants to replace or augment it
  • If augmenting, identify what is missing and generate only those pieces

3. Info.plist Check

Search for existing background modes configuration:

Grep: "BGTaskSchedulerPermittedIdentifiers" or "UIBackgroundModes"

Check for push notification entitlements if silent push is needed:

Glob: **/*.entitlements
Grep: "aps-environment"

Configuration Questions

Ask user via AskUserQuestion:

  1. What background processing do you need?

    • App refresh (lightweight periodic updates -- weather, feeds, content)
    • Data processing (long-running -- database cleanup, ML model updates, large syncs)
    • Background downloads (files, media, assets that survive app termination)
    • Silent push notifications (server-triggered content updates)
    • Multiple (select which combination)
  2. How often should background tasks run?

    • Hourly (system decides exact timing, best-effort)
    • Every few hours (recommended for most apps)
    • Daily (content that changes infrequently)
    • On content change via push (server triggers update with silent push)
  3. Does the task need network access?

    • Yes -- needs background fetch or download capability
    • No -- local processing only (database maintenance, cleanup)

Generation Process

Step 1: Read Templates

Read templates.md for production Swift code.

Step 2: Create Core Files

Generate these files:

  1. BackgroundTaskManager.swift -- Central manager for registering and scheduling all background tasks
  2. BackgroundTaskConfiguration.swift -- Info.plist keys, entitlements, and task identifier constants

Step 3: Create Feature-Specific Files

Based on configuration: 3. BackgroundDownloadManager.swift -- If background downloads selected 4. SilentPushHandler.swift -- If silent push selected

Step 4: Determine File Location

Check project structure:

  • If Sources/ exists -> Sources/BackgroundProcessing/
  • If App/ exists -> App/BackgroundProcessing/
  • Otherwise -> BackgroundProcessing/

Output Format

After generation, provide:

Files Created

BackgroundProcessing/
├── BackgroundTaskManager.swift        # BGTaskScheduler registration & scheduling
├── BackgroundTaskConfiguration.swift  # Task identifiers and Info.plist config
├── BackgroundDownloadManager.swift    # Background URLSession downloads (optional)
└── SilentPushHandler.swift            # Silent push handling (optional)

Integration with App Lifecycle

Register tasks at app launch (must happen before app finishes launching):

swift
@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        BackgroundTaskManager.shared.registerTasks()
        return true
    }
}

Schedule refresh when app enters background:

swift
struct ContentView: View {
    @Environment(\.scenePhase) private var scenePhase

    var body: some View {
        NavigationStack {
            FeedView()
        }
        .onChange(of: scenePhase) { _, newPhase in
            if newPhase == .background {
                BackgroundTaskManager.shared.scheduleAppRefresh()
            }
        }
    }
}

Start a background download:

swift
func downloadAsset(from url: URL) {
    BackgroundDownloadManager.shared.startDownload(from: url)
}

Handle silent push in AppDelegate:

swift
func application(
    _ application: UIApplication,
    didReceiveRemoteNotification userInfo: [AnyHashable: Any]
) async -> UIBackgroundFetchResult {
    await SilentPushHandler.shared.handle(userInfo: userInfo)
}

Testing

Simulate background task in Xcode debugger (LLDB):

e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.app.refresh"]

Simulate expiration:

e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.app.refresh"]

Test background download:

swift
#if DEBUG
func simulateBackgroundDownload() {
    let testURL = URL(string: "https://example.com/test-asset.zip")!
    BackgroundDownloadManager.shared.startDownload(from: testURL)
}
#endif

Required Info.plist Configuration

Add to Info.plist:

xml
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
    <string>com.app.refresh</string>
    <string>com.app.processing</string>
</array>

Required Background Modes

In Xcode: Target > Signing & Capabilities > Background Modes:

  • Background fetch -- for BGAppRefreshTask
  • Background processing -- for BGProcessingTask
  • Remote notifications -- for silent push
  • Background download -- for background URLSession (automatic when using background configuration)

Common Patterns

Schedule Refresh on Entering Background

Always schedule the next refresh when the app goes to background. The system decides when to actually run it.

swift
BackgroundTaskManager.shared.scheduleAppRefresh()

Long-Running Processing with Expiration Handling

BGProcessingTask can run for minutes, but always handle the expirationHandler to save progress.

swift
task.expirationHandler = {
    // Save partial progress so next run can resume
    processingJob.saveCheckpoint()
}

Energy-Efficient Background Work

swift
// Only process on Wi-Fi + power
let request = BGProcessingTaskRequest(identifier: taskID)
request.requiresNetworkConnectivity = true
request.requiresExternalPower = true

Gotchas

Registration Must Happen Before didFinishLaunching Returns

BGTaskScheduler.shared.register(forTaskWithIdentifier:) must be called during didFinishLaunchingWithOptions. If called later, the registration silently fails. Always register in AppDelegate, never in a View.

System Controls Scheduling

The system decides when to run background tasks based on battery, network, user patterns, and frequency. You cannot guarantee exact timing. earliestBeginDate is a hint, not a guarantee.

Background URLSession Delegate Callbacks

Background URLSession delivers delegate callbacks even if the app was terminated and relaunched. The session must be recreated with the same identifier, and application(_:handleEventsForBackgroundURLSession:completionHandler:) must be implemented.

Silent Push Limitations

Silent push notifications are rate-limited by APNs. If you send too many, the system throttles them. Use them for important content changes, not periodic polling.

30-Second Window for App Refresh

BGAppRefreshTask gives you approximately 30 seconds of execution time. For longer work, use BGProcessingTask instead (which can run for several minutes when conditions are met).

Simulator Limitations

Background tasks do not run naturally on the Simulator. Use the LLDB _simulateLaunchForTaskWithIdentifier: command to trigger them manually during development.

References

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Background Processing AI skill do?

Generates background processing infrastructure with BGTaskScheduler, background refresh, background downloads, and silent push handling. Use when user needs background tasks, periodic refresh, background URLSession downloads, or silent push notification processing.

Why use Background Processing on TypingMind?

Because you install it once and use it with any model. Background Processing is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Background Processing in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/rshankras/claude-code-apple-skills/tree/main/skills/generators/background-processing. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Background Processing?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Background Processing?

As many as you like. As long as a model supports skills, you can use Background Processing with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Background Processing AI skill free?

Yes. It is published on GitHub by rshankras under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇