Opens Instagram Reels in a small centered Safari window while Claude works, autoscrolls, and closes it when Claude finishes.

A Claude Code mod for macOS. When you submit a prompt, it opens Instagram Reels in a small window centered on your screen (in Safari, so your Chrome windows stay put), scrolls to the next reel each time one finishes, and closes the window and hands focus back to you when Claude is done.
In a Claude Code terminal session:
/plugin install reels-while-you-wait --marketplace jemsley06/reels-while-you-wait
Answer y to add the marketplace, then press Enter for the user scope.
Type /reels to toggle it. Your choice is remembered across sessions.
/ (slash commands) never open Reels.hooks/register.ts 114 lines1import type { Register } from 'claude-code'
2import { AUTOSCROLL_JS } from './autoscroll'
3
4const OPEN = `use framework "AppKit"
5use scripting additions
6set prev to path to frontmost application as text
7set wasRunning to application "Safari" is running
8-- running with no windows holds nothing of yours: treat it as ours to quit afterwards
9if wasRunning then tell application "Safari" to if (count of windows) is 0 then set wasRunning to false
10-- \`launch\` starts Safari without the Start Page window a plain start opens
11if not wasRunning then tell application "Safari" to launch
12-- the screen holding the focused window; center a phone-sized 420x760 window on it
13set {{sx, sy}, {sw, sh}} to current application's NSScreen's mainScreen's frame() as list
14set x to sx + (sw - 420) div 2
15set y to (sh - 760) div 2
16tell application "Safari"
17 set existing to id of every window
18 make new document with properties {URL:"https://www.instagram.com/reels/"}
19 -- find our window as the new one on Instagram: right after creation \`front window\` can still be one of yours
20 set w to missing value
21 repeat 50 times
22 repeat with o in (every window)
23 if (id of o) is not in existing and (URL of current tab of o as text) contains "instagram.com" then set w to contents of o
24 end repeat
25 if w is not missing value then exit repeat
26 delay 0.1
27 end repeat
28 set bounds of w to {x, y, x + 420, y + 760}
29 set wid to id of w
30 -- Safari can still open its Start Page a moment after starting; close it so only Reels shows
31 if not wasRunning then
32 delay 1
33 repeat with o in (every window whose id is not wid)
34 if (URL of current tab of o as text) is in {"favorites://", "about:blank", "missing value"} then close o
35 end repeat
36 end if
37end tell
38-- not \`activate\`: that raises every Safari window over Claude; this raises only the new (key) one
39tell application "System Events" to set frontmost of process "Safari" to true
40return (wid as text) & linefeed & prev & linefeed & wasRunning`
41
42// every step checks Safari is running first: a \`tell\` to a quit Safari relaunches it, restoring old windows
43const INJECT = `on run argv
44 if application "Safari" is running then tell application "Safari" to do JavaScript (item 2 of argv) in current tab of (first window whose id is (item 1 of argv as integer))
45end run`
46
47const CLOSE = `on run argv
48 if not (application "Safari" is running) then return
49 -- read before closing: are you still watching, or have you moved on to something else?
50 tell application "System Events" to set stillWatching to frontmost of process "Safari"
51 tell application "Safari"
52 -- we started Safari: quit it unless you have a real page open (decided before closing: closes settle late)
53 set yours to 0
54 if item 3 of argv is "false" then
55 repeat with o in (every window whose id is not (item 1 of argv as integer))
56 if (URL of current tab of o as text) is not in {"favorites://", "about:blank", "missing value"} then set yours to yours + 1
57 end repeat
58 end if
59 if item 3 of argv is "false" and yours is 0 then
60 quit
61 else
62 close (every window whose id is (item 1 of argv as integer))
63 end if
64 end tell
65 if stillWatching then tell application (item 2 of argv) to activate
66end run`
67
68export const register: Register = on => {
69 // the open in flight, resolving to [windowId, prevApp, wasRunning]; awaited at turn end so a short turn can't miss it
70 // shortcut: it lives in a module variable, so a mod reload mid-turn leaves that window open
71 let opening: Promise<string[] | undefined> | undefined
72
73 on('session.start', async ($, e, next) => {
74 await $.command.register({ name: 'reels', description: 'Turn Reels-while-you-wait on or off' })
75 return next(e)
76 })
77
78 on('command.run', { command: 'reels' }, async $ => {
79 const isOff = !(await $.store.get('off'))
80 await $.store.set('off', isOff)
81 return { text: `Reels while you wait: ${isOff ? 'off' : 'on'}` }
82 })
83
84 on('prompt.submit', async ($, e, next) => {
85 // shortcut: skips every slash command (they may never end a turn, which would strand the window); skills invoked by slash won't get reels
86 if (!opening && !e.text.startsWith('/') && !(await $.store.get('off'))) {
87 opening = $.process.run(['osascript', '-e', OPEN]).then(opened => {
88 if (opened.exitCode === 0) return opened.stdout.trim().split('\n')
89 $.ui.toast(`reels: ${opened.stderr.trim()}`)
90 }).catch(err => void $.ui.toast(`reels: ${err}`))
91 const mine = opening
92 void opening.then(async win => {
93 if (!win || opening !== mine) return // turn already ended
94 await $.clock.sleep(5000) // let Instagram's page mount its <video>s
95 if (opening !== mine) return
96 const injected = await $.process.run(['osascript', '-e', INJECT, win[0], AUTOSCROLL_JS])
97 if (injected.exitCode !== 0)
98 $.ui.toast('reels: autoscroll needs Safari → Settings → Developer → Allow JavaScript from Apple Events')
99 }).catch(() => {}) // the window may already be closed when a turn is short
100 }
101 return next(e)
102 }).catch(($, e, next) => next(e)) // never block your prompt over a reels hiccup
103
104 on('turn.complete', async ($, e, next) => {
105 const result = await next(e)
106 if (!e.agentId && opening) {
107 const win = await opening
108 opening = undefined
109 if (win) await $.process.run(['osascript', '-e', CLOSE, ...win]).catch(() => {})
110 }
111 return result
112 })
113}
114hooks/autoscroll.ts 13 lines1// Injected into the Reels tab. Reels loop instead of firing 'ended', so "finished" = playhead near the end.
2export const AUTOSCROLL_JS = `(() => {
3 if (window.__reelScroll) return;
4 const done = new WeakSet();
5 window.__reelScroll = setInterval(() => {
6 const vids = [...document.querySelectorAll('video')];
7 const v = vids.find(v => !v.paused && v.duration && !done.has(v));
8 if (!v || v.currentTime < v.duration - 0.35) return;
9 done.add(v);
10 vids[vids.indexOf(v) + 1]?.scrollIntoView({ behavior: 'smooth', block: 'center' });
11 }, 250);
12})()`
13