Instacart
by @bigdaddyluke
Place grocery orders on Instacart via browser automation. Supports search, reorder, smart lookback based on order history, and nightly auto-replenishment.
clawhub install instacart-skillπ About This Skill
name: instacart description: Place grocery orders on Instacart via browser automation. Supports search, reorder, smart lookback based on order history, and nightly auto-replenishment. homepage: https://www.instacart.com metadata: {"clawdbot":{"emoji":"π","requires":{"bins":["openclaw","gog"],"env":["INSTACART_URL","INSTACART_EMAIL"]}}}
Instacart Ordering
You are an agent driving a browser to build and place grocery orders on Instacart. The user tells you what they want; you search products, build the cart, and confirm before checkout.
Prerequisites
openclaw browser commands to control a Chromium session. A browser profile must be configured (default: openclaw).INSTACART_CODE_EMAIL is set. The email account must be authenticated in gog (gog auth list to verify).Environment Variables
Set these in your agent's env file (e.g. .env, .env.personal):
| Variable | Required | Description |
|----------|----------|-------------|
| INSTACART_URL | Yes | Base URL (e.g. https://www.instacart.com or https://www.instacart.ca) |
| INSTACART_EMAIL | Yes | Login email for the Instacart account |
| INSTACART_CODE_EMAIL | No | Email address where Instacart sends verification codes. Must be authed in gog CLI. If set, the agent fetches codes automatically. If unset, the agent asks the user. |
Store Mappings
Create a JSON file at memory/instacart-storefronts.json mapping casual store names to Instacart slugs:
{
"costco": "costco",
"walmart": "walmart",
"safeway": "safeway"
}
Slugs match the store path on Instacart (e.g. instacart.com/store/costco). If the file is missing or malformed, skip it and search Instacart directly for the store the user named. If the user names a store not in the map, search Instacart directly or ask the user for the correct storefront URL.
Workflow
1. Read env vars first. Read .env.personal (or your env file) to get INSTACART_URL, INSTACART_EMAIL, and INSTACART_CODE_EMAIL before opening the browser. Also read memory/instacart-storefronts.json if the user named a store. Do these reads in parallel.
2. Open Instacart and check login state. Open INSTACART_URL, snapshot the page. If you see "Log in" or "Sign up" buttons, run the login flow (see Login Flow below). If you see an account menu or cart icon, you're logged in β proceed.
3. Build the cart. Choose the best strategy for the request:
- Search: Navigate to the store, search for each item, let the user pick from results.
- Reorder: If user says "same as last time" or "reorder", open their recent orders for that store, use the reorder flow, then ask what to add/remove.
- Smart lookback (default when order history is available):
1. Open order history for the active store.
2. Build a candidate list of items ordered 2 or more times.
3. For each candidate, estimate reorder cadence from prior gaps (prefer median days between purchases; fallback to average if needed).
4. Compare days since last purchase to cadence. If due/overdue, add to cart.
5. If item is already in cart, do not duplicate β mark as already in cart.
4. Handle duplicates and quantity mismatches. If the user asks for an item that is already in cart, tell them it is already there and confirm whether to increase quantity. If the user requests a specific quantity (e.g. "2 milks") and a smaller quantity is already in cart, offer to add the difference.
5. Iterate with the user. After each action, snapshot the page, tell the user what you see, and ask what to do next. Don't auto-pick when products are ambiguous β show options and let them choose.
6. Confirm before checkout. Present: item count, subtotal, fees/tip, total, delivery address, payment method. Include an Auto-added from lookback section listing anything added by cadence logic and anything skipped as already in cart. Wait for explicit "yes" / "place it" / "go ahead" before clicking Place Order.
Speed Rules
Minimize tool calls. Every call adds latency.
gog CLI exclusively for email retrieval. Opening Gmail wastes 10+ tool calls on Google's login flow.Safety
Browser Reliability
openclaw browser stop
2. Wait 2 seconds
3. Run: openclaw browser start
4. Run: openclaw browser status to verify running: true
5. Re-open the page with openclaw browser --browser-profile openclaw open "" --json to get a fresh targetId
6. Continue from where you left off
open command to get a new targetId, then continue from where you left off.Cart Clearing
When the user asks to clear or empty their cart:
1. Open the store storefront page 2. Click the cart icon to open the cart view 3. Click the remove/delete button on each item until the cart is empty 4. Verify the cart indicator shows 0 items
If a remove button's element ref fails to register a click, fall back to evaluating a direct JavaScript click on the same element (see the evaluate command below).
Nightly Auto-Replenishment Mode
When invoked by a nightly automation task:
1. Open Instacart, ensure logged in.
2. Run Smart lookback for each frequently used storefront (or the mapped default stores in memory/instacart-storefronts.json).
3. Add only due/overdue items with 2+ historical purchases.
4. Never duplicate an item already in cart β mark it as already present.
5. Post a concise summary with:
- auto-added items,
- items skipped because already in cart,
- items considered but not yet due.
6. Do not place an order in nightly mode.
Browser Command Reference
All commands use openclaw browser to control a Chromium session. After opening a page, subsequent commands require the --target-id returned by the open command.
Core Commands
# Open a URL in a new tab (returns JSON with targetId)
openclaw browser --browser-profile openclaw open "" --jsonNavigate an existing tab to a new URL
openclaw browser --browser-profile openclaw navigate "" --target-id ""Snapshot the current page (returns element refs and visible content)
Use --limit 3000 for most pages. Increase to 5000+ for large carts where items may be truncated.
openclaw browser --browser-profile openclaw snapshot --format ai --limit 3000 --target-id ""Click an element by its ref
openclaw browser --browser-profile openclaw click "" --target-id ""Type text into an input and submit the form
openclaw browser --browser-profile openclaw type "" "" --submit --target-id ""Execute JavaScript directly (fallback when element refs are unreliable)
openclaw browser --browser-profile openclaw evaluate "document.querySelector('').click()" --target-id ""
Login Flow
Follow this sequence. If Instacart's UI has changed (e.g. button text differs, OAuth redirect, CAPTCHA), adapt based on what you see in the snapshot. Do not stall β describe the unexpected UI to the user and ask how to proceed.
Aim for ~8 tool calls. Verification email delays or retries may push beyond this β that's fine.
1. Open INSTACART_URL β get targetId
2. Snapshot β check for "Log in" button. If no login button, you're already logged in β done.
3. Click the "Log in" button
4. Type INSTACART_EMAIL into the email field with --submit
5. Fetch verification code via gog (see below) β this is one exec call
6. Snapshot β find the code input field
7. Type the 6-digit code into the verification field with --submit
8. Snapshot β confirm logged-in state (account menu visible)
#### Retrieving the Verification Code
Use gog CLI. This is the only method. Never open Gmail, Yahoo, Outlook, or any email provider in the browser.
gog gmail messages search "from:instacart subject:verification newer_than:10m" \
--account "" --json --max 1
The code is the 6-digit number in the email subject (e.g. "109781 is your Instacart verification code"). Extract it with a regex or from the subject field.
If no results, wait 20 seconds and retry once. If still nothing, ask the user for the code.
#### What NOT to do during login
Response Style
βοΈ Configuration
openclaw browser commands to control a Chromium session. A browser profile must be configured (default: openclaw).INSTACART_CODE_EMAIL is set. The email account must be authenticated in gog (gog auth list to verify).Environment Variables
Set these in your agent's env file (e.g. .env, .env.personal):
| Variable | Required | Description |
|----------|----------|-------------|
| INSTACART_URL | Yes | Base URL (e.g. https://www.instacart.com or https://www.instacart.ca) |
| INSTACART_EMAIL | Yes | Login email for the Instacart account |
| INSTACART_CODE_EMAIL | No | Email address where Instacart sends verification codes. Must be authed in gog CLI. If set, the agent fetches codes automatically. If unset, the agent asks the user. |
Store Mappings
Create a JSON file at memory/instacart-storefronts.json mapping casual store names to Instacart slugs:
{
"costco": "costco",
"walmart": "walmart",
"safeway": "safeway"
}
Slugs match the store path on Instacart (e.g. instacart.com/store/costco). If the file is missing or malformed, skip it and search Instacart directly for the store the user named. If the user names a store not in the map, search Instacart directly or ask the user for the correct storefront URL.