Open Instagram in Chrome browser and check messages. Use when user says "open instagram", "go to instagram", "check instagram messages", "instagram DMs", "check DMs", or "/instagram".
Open Instagram using PinchTab, log in if needed, then check and reply to all direct messages.
shopwithus.aiLoveyou1BEFORE replying to any product question, read the product catalog:
cat ~/.claude/plugins/marketplaces/online-shop-skills/skills/instagram/products.json
pinchtab fill does NOT work for login fields. Use pinchtab eval with native input value setter.email and pass (NOT username/password).contenteditable div. Use: pinchtab eval to focus/clear → pinchtab keyboard inserttext to type → pinchtab click the "Send" button.~/.pinchtab/config.json.nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 & — the 1s delay ensures Chrome activates AFTER the bash command returns. Append this to the END of every bash call, not just setup.instagram profile for session persistence — avoids re-login on every run.pinchtab nav to thread URL instead."You: <text>" in sidebar after sending. Textbox reverts to val="\n" — this is normal.CRITICAL: Headless default instances auto-spawn and steal CLI commands from the visible headed instance. This causes the user to see only a blank/login screen in Chrome while commands silently execute in the invisible headless instance.
Run this guard BEFORE every pinchtab command (nav, snap, click, eval, keyboard). Prefix every bash call that uses pinchtab with pt_guard &&:
# Define the guard function (run once at the start of the session, in Step 1)
pt_guard() {
local PT_TOKEN=$(python3 -c "import json; print(json.load(open('$HOME/.pinchtab/config.json')).get('server',{}).get('token',''))" 2>/dev/null)
# Kill ALL non-instagram and ALL headless instances
for inst in $(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/instances | python3 -c "import sys,json; [print(i['id']) for i in json.load(sys.stdin) if i['status']=='running' and (i.get('headless',False) or i.get('profileName','')!='instagram')]" 2>/dev/null); do
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" http://localhost:9867/instances/$inst/stop > /dev/null
done
# Ensure attached to the headed instagram instance
local INST=$(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/instances | python3 -c "import sys,json; insts=json.load(sys.stdin); print(next((i['id'] for i in insts if not i.get('headless',True) and i['status']=='running' and i.get('profileName','')=='instagram'),''))" 2>/dev/null)
if [ -n "$INST" ]; then
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" "http://localhost:9867/instances/$INST/attach" > /dev/null
fi
}
Usage pattern for EVERY bash call that uses pinchtab:
pt_guard && pinchtab nav "https://..." && sleep 2 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
Note: Use ; (not &&) before the nohup so Chrome activation runs even if a prior command fails.
&& — never run separate bash calls for sequential commands that don't need output inspection.; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &Always stop ALL existing instances and start fresh. The instagram profile preserves cookies/session, so restarting is safe and avoids stale instance errors.
# Ensure PinchTab is running
if ! curl -sf --max-time 2 http://localhost:9867/health > /dev/null 2>&1; then
nohup pinchtab > /tmp/pinchtab.log 2>&1 &
for i in 1 2 3 4 5 6 7 8; do curl -sf http://localhost:9867/health > /dev/null 2>&1 && break; sleep 1; done
fi
PT_TOKEN=$(python3 -c "import json; print(json.load(open('$HOME/.pinchtab/config.json')).get('server',{}).get('token',''))" 2>/dev/null)
# Stop ALL running instances to avoid stale instance "context canceled" errors
for inst in $(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/instances | python3 -c "import sys,json; [print(i['id']) for i in json.load(sys.stdin) if i['status']=='running']" 2>/dev/null); do
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" http://localhost:9867/instances/$inst/stop > /dev/null
done
sleep 2
# Find or create instagram profile (persists login session)
PROFILE_ID=$(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/profiles | python3 -c "import sys,json; profiles=json.load(sys.stdin); print(next((p['id'] for p in profiles if p['name']=='instagram'),''))" 2>/dev/null)
if [ -z "$PROFILE_ID" ]; then
PROFILE_ID=$(curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" http://localhost:9867/profiles -d '{"name":"instagram","description":"Instagram shopwithus.ai session"}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))")
echo "Created instagram profile: $PROFILE_ID"
fi
# Start fresh headed instance with instagram profile (explicitly headless=false)
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" http://localhost:9867/instances/start -d "{\"profileId\":\"$PROFILE_ID\",\"mode\":\"headed\",\"headless\":false}" > /dev/null
sleep 3
# CRITICAL: Kill headless instances repeatedly — they can auto-spawn with a delay.
# Check 3 times with 1s gaps to catch late spawners.
for attempt in 1 2 3; do
for inst in $(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/instances | python3 -c "import sys,json; [print(i['id']) for i in json.load(sys.stdin) if i['status']=='running' and (i.get('headless',False) or i.get('profileName','')!='instagram')]" 2>/dev/null); do
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" http://localhost:9867/instances/$inst/stop > /dev/null
echo "Stopped rogue instance: $inst"
done
sleep 1
done
# Attach to the headed instagram instance
INSTAGRAM_INST=$(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/instances | python3 -c "import sys,json; insts=json.load(sys.stdin); print(next((i['id'] for i in insts if not i.get('headless',True) and i['status']=='running' and i.get('profileName','')=='instagram'),''))" 2>/dev/null)
if [ -n "$INSTAGRAM_INST" ]; then
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" "http://localhost:9867/instances/$INSTAGRAM_INST/attach" > /dev/null
echo "Attached to instagram instance: $INSTAGRAM_INST"
fi
# Define pt_guard function for use in ALL subsequent bash calls (export via file)
cat > /tmp/pt_guard.sh << 'GUARD'
pt_guard() {
local PT_TOKEN=$(python3 -c "import json; print(json.load(open('$HOME/.pinchtab/config.json')).get('server',{}).get('token',''))" 2>/dev/null)
for inst in $(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/instances | python3 -c "import sys,json; [print(i['id']) for i in json.load(sys.stdin) if i['status']=='running' and (i.get('headless',False) or i.get('profileName','')!='instagram')]" 2>/dev/null); do
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" http://localhost:9867/instances/$inst/stop > /dev/null
done
local INST=$(curl -s -H "Authorization: Bearer $PT_TOKEN" http://localhost:9867/instances | python3 -c "import sys,json; insts=json.load(sys.stdin); print(next((i['id'] for i in insts if not i.get('headless',True) and i['status']=='running' and i.get('profileName','')=='instagram'),''))" 2>/dev/null)
if [ -n "$INST" ]; then
curl -s -X POST -H "Authorization: Bearer $PT_TOKEN" -H "Content-Type: application/json" "http://localhost:9867/instances/$INST/attach" > /dev/null
fi
}
GUARD
echo "pt_guard helper saved to /tmp/pt_guard.sh"
# Bring Chrome to front so user can watch
nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
source /tmp/pt_guard.sh && pt_guard && pinchtab nav "https://www.instagram.com/direct/inbox/" && sleep 2 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
textbox "Password" or button "Log In" → NOT logged in, go to Step 3.source /tmp/pt_guard.sh && pt_guard && pinchtab eval "(function() { var u = document.querySelector('input[name=email]'); var p = document.querySelector('input[name=pass]'); var s = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set; s.call(u, 'shopwithus.ai'); u.dispatchEvent(new Event('input', {bubbles: true})); u.dispatchEvent(new Event('change', {bubbles: true})); s.call(p, 'Loveyou1'); p.dispatchEvent(new Event('input', {bubbles: true})); p.dispatchEvent(new Event('change', {bubbles: true})); return 'filled'; })()" && pinchtab eval "document.querySelector('input[type=submit]').click(); 'clicked'"; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
Wait and check:
sleep 3 && source /tmp/pt_guard.sh && pt_guard && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
textbox "Code"): ask user for the code, wait for them to enter it.source /tmp/pt_guard.sh && pt_guard && pinchtab click <not_now_ref> && sleep 1 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
Repeat if another prompt appears.source /tmp/pt_guard.sh && pt_guard && pinchtab nav "https://www.instagram.com/direct/inbox/" && sleep 2 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
The inbox snapshot shows:
button "user-profile-picture <Name> <message> <time> Unread"link "Request (N)"Process message requests FIRST (if Request (N) with N > 0):
source /tmp/pt_guard.sh && pt_guard && pinchtab click <request_link_ref> && sleep 1 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
For each request conversation:
source /tmp/pt_guard.sh && pt_guard && pinchtab click <conversation_button_ref> && sleep 1 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
Accept → reply → verify (chain as much as possible):
source /tmp/pt_guard.sh && pt_guard && pinchtab click <accept_button_ref> && sleep 1; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
source /tmp/pt_guard.sh && pt_guard && pinchtab eval "(function() { var el = document.querySelector('div[contenteditable=\"true\"][role=\"textbox\"]'); el.focus(); el.innerHTML = ''; return 'ok'; })()" && pinchtab keyboard inserttext "reply text here" && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
source /tmp/pt_guard.sh && pt_guard && pinchtab click <send_button_ref> && sleep 2 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
Verify: look for "You: <reply>" in sidebar. Then go back:
source /tmp/pt_guard.sh && pt_guard && pinchtab click <back_button_ref> && sleep 1 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
Process inbox conversations:
Navigate back to inbox:
source /tmp/pt_guard.sh && pt_guard && pinchtab nav "https://www.instagram.com/direct/inbox/" && sleep 2 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
For each unread conversation, navigate directly to thread URL (DO NOT click sidebar):
source /tmp/pt_guard.sh && pt_guard && pinchtab nav "https://www.instagram.com/direct/t/<thread_id>/" && sleep 2 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
Send reply:
source /tmp/pt_guard.sh && pt_guard && pinchtab eval "(function() { var el = document.querySelector('div[contenteditable=\"true\"][role=\"textbox\"]'); el.focus(); el.innerHTML = ''; return 'ok'; })()" && pinchtab keyboard inserttext "reply text here" && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
source /tmp/pt_guard.sh && pt_guard && pinchtab click <send_button_ref> && sleep 2 && pinchtab snap -i -c; nohup bash -c 'sleep 1 && osascript -e "tell application \"Google Chrome\" to activate"' > /dev/null 2>&1 &
After processing all messages, present a summary:
If any pinchtab command fails with "context canceled" or 503, the pt_guard function already handles this. Just run:
source /tmp/pt_guard.sh && pt_guard
Then retry the failed command with pt_guard && prefix as usual.