# Alfred setup, for Claude

The person pasted a line asking you to set up Alfred here. This page tells you how.
It has exact commands and exact words for the person, so read it whole, not a summary.
Reading it changes nothing: `curl -fsSL https://udayan.co/alfred/setup`

In short:
1. Alfred runs on Macs only. If `uname -s` does not say `Darwin`, say so and stop.
   No shell here, or `$CLAUDE_CODE_ENTRYPOINT` is `local-agent` (Cowork's own sandbox)? Send them to the Code tab.
2. Tell them what will happen, and get one yes.
3. Add what the Mac is missing: Homebrew (its .pkg installer: macOS asks the password in its own window), Node,
   Claude Code for Terminal and its sign-in.
4. Start `npx -y getalfred@latest` in the background. A page with a code opens; they scan it with their phone.
5. Check it works: `~/.alfred/current/bin/cli status`.

Alfred's code is public, so anyone can read what runs on their Mac: it is the `getalfred` package on npm (https://www.npmjs.com/package/getalfred). Show them any command you run if they ask.

## What Alfred is
Alfred is Claude Code in their WhatsApp.
It runs on their Mac, in the background.
They write in their own "Message yourself" chat on WhatsApp, typed or as a voice note.
A Claude Code session on the Mac does the work, on their own Claude plan.
It messages other people only after their yes.

## How to talk to them
Most people setting this up are not developers. Short lines. One thing per sentence. Plain words.
Say what they will see and what to do. Then do it.
Everything happens here, in this chat. They don't need to type any command themselves.
If this chat asks them to allow each command, say once: "I'll ask you to allow a few commands. That's expected." 

## 1. Is this a Mac?
If you can't run commands here, or `echo $CLAUDE_CODE_ENTRYPOINT` says `local-agent` (Cowork runs in a sandbox of its
own, not on their Mac), say: "In the Claude app, open the Code tab, start a local session, and paste the line there."
Then stop.

Run `uname -s`.
If it is not `Darwin`, say: "Alfred works on Macs for now, so I can't set it up here."
Then stop. Install nothing. Change nothing.

## 2. Is Alfred already here?
If `~/.alfred/current/bin/cli` exists, run `~/.alfred/current/bin/cli status`.
Tell them how it is, in two or three short lines. Offer to repair it, link WhatsApp again, or remove it.
- Repair, in the background: `nohup ~/.alfred/current/bin/cli repair > "${TMPDIR:-/tmp}/alfred-setup.log" 2>&1 &`
- Link WhatsApp again, in the background: `nohup ~/.alfred/current/bin/cli link > "${TMPDIR:-/tmp}/alfred-setup.log" 2>&1 &`
- Remove, only after a clear yes: `~/.alfred/current/bin/cli uninstall --yes`.

After a repair or a new link, follow steps 7 and 8.
If the repair says it is set up but not started, it never had their yes: show the three lines of step 4, and only
after a clear yes run `ALFRED_ACCEPT_PROMPTS_OFF=1 ~/.alfred/current/bin/cli start`.

Then stop.

## 3. Look at what the Mac has (install nothing yet)
Run each line. "command not found" means it is missing.
- Homebrew: `PATH="$PATH:/opt/homebrew/bin:/usr/local/bin" brew --version`
- Node 20 or newer: `PATH="/opt/homebrew/opt/node@24/bin:/usr/local/opt/node@24/bin:$PATH:/opt/homebrew/bin" node --version`
- Claude Code for Terminal: `PATH="$HOME/.local/bin:$PATH" claude --version`
- Its sign-in: `PATH="$HOME/.local/bin:$PATH" claude auth status --text`
- The chip: `uname -m` (`arm64` is Apple silicon)

In the Claude app, Claude Code for Terminal is often missing. That's fine: Alfred's background session needs its own copy, and step 5 adds it.

## 4. Their yes, once
Tell them what will happen, in short lines. Only the parts that apply:
- "I'll set up Alfred here. It takes about two minutes."
- "First I add Homebrew, the usual installer for Mac tools. Your Mac asks for your password once, for that."
- "I add Node, which Alfred runs on. No password."
- "I add Claude Code for Terminal, which Alfred's background session runs on. You sign in once, with one click."
- "Then a page with a code opens in your browser. On your phone: WhatsApp, Settings, Linked devices, Link a device. Point the phone at the code."

Then show these three lines, word for word:
- Claude Code runs with permission prompts off, so it can work while you're away.
- It links WhatsApp the way WhatsApp Web does (unofficial, a small risk).
- What it reads goes to Claude. Nothing goes to anyone without your yes.

Ask: "OK to go ahead?" Only a clear yes goes on. If they already said yes to these three lines in this chat, don't ask again.

## 5. Add what is missing (skip what is there)
Homebrew, only if missing. Use its .pkg installer, not the shell script: the script needs a password typed in a
Terminal, and there is none here. On Apple silicon:
```
f="${TMPDIR:-/tmp}/Homebrew.pkg"
curl -fsSL -o "$f" https://github.com/Homebrew/brew/releases/latest/download/Homebrew.pkg &&
  pkgutil --check-signature "$f" >/dev/null && open "$f"
```
(Run the three lines as one command: it opens the installer only if the download is complete and signed.)
Say: "The Homebrew installer is open. Click Continue, then Install. Type your Mac password when it asks."
Then check `PATH="$PATH:/opt/homebrew/bin" brew --version` every 15 seconds until it works (up to 10 minutes).
On an Intel Mac there is no .pkg: open Homebrew's own installer in a Terminal window of its own, where they type the
password. Write it to a file and open that (never osascript):
```
f="${TMPDIR:-/tmp}/alfred-homebrew.command"
printf '#!/bin/bash\n/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"\n' > "$f"
chmod +x "$f" && open "$f"
```
Say: "A Terminal window opened with the Homebrew installer. Press Return, then type your Mac password. Nothing shows
while you type." Then check `PATH="$PATH:/usr/local/bin" brew --version` every 15 seconds (up to 15 minutes).

Node, only if missing or older than 20 (no password):
```
PATH="$PATH:/opt/homebrew/bin:/usr/local/bin" brew install node@24
```

Claude Code for Terminal, only if missing (no password):
```
curl -fsSL https://claude.ai/install.sh | bash
```

Its sign-in, only if `auth status` says it is not logged in. Start it in the background:
```
PATH="$HOME/.local/bin:$PATH" nohup claude auth login > "${TMPDIR:-/tmp}/alfred-signin.log" 2>&1 &
```
Say: "A Claude sign-in page opened in your browser. Click Authorize."
If no page opened, the log has the link: open it with `open`.
Check `PATH="$HOME/.local/bin:$PATH" claude auth status --text` every 10 seconds until it says logged in (up to 5 minutes).
If the sign-in says their plan doesn't include Claude Code, tell them: "Alfred runs on Claude Code, which needs a Claude
plan that includes it (Pro or Max)." Then stop.

## 6. Start the setup, in the background
Say it as you start it: "Starting Alfred now. In a minute or two the page with the code opens: scan it as I said."
Then start it. It waits for their phone, longer than one command may run, so never run it in the foreground. Use these three lines, in one command:
```
export PATH="/opt/homebrew/opt/node@24/bin:/usr/local/opt/node@24/bin:$HOME/.local/bin:$PATH"
export PATH="$PATH:/opt/homebrew/bin:/usr/local/bin"
ALFRED_ACCEPT_PROMPTS_OFF=1 nohup npx -y getalfred@latest > "${TMPDIR:-/tmp}/alfred-setup.log" 2>&1 &
```
Their yes from step 4 is what `ALFRED_ACCEPT_PROMPTS_OFF=1` stands for. Never set it without that yes.

## 7. Wait for the scan
Read `"${TMPDIR:-/tmp}/alfred-setup.log"` every 15 seconds, up to 10 minutes. Stop waiting when it says "WhatsApp linked"
or "WhatsApp is linked", when it says "Done.", when a line starts with "error:", or when the setup has ended
(`pgrep -f getalfred` finds nothing). A new setup ends with "Done.".
If they can't find the page with the code: `open ~/.alfred/state/pair.html`.
If WhatsApp on the phone says it can't link more devices, they remove an old one under Linked devices, then scan again.

## 8. Check it works
Run `~/.alfred/current/bin/cli status`. When WhatsApp is connected, say:
- "Alfred is set up and running."
- "In WhatsApp, search your own name. That chat is Message yourself. Pin it."
- "Say hi there. Alfred answers."
- "It works while this Mac is awake. Asleep or lid shut: no replies until it wakes."
- "Every Claude Code chat here now knows Alfred too." (Only if the log says it added a skill.)
- "You can ask me to WhatsApp someone from here. The words wait for your yes in Message yourself." (Only if the log
  says any Claude chat can now WhatsApp someone.)
- "Your other AI agents on this Mac (Claude Code, Codex, Antigravity, Gemini CLI, Cursor's CLI) can be reached from
  WhatsApp now." Nothing to set up.
- "Alfred speaks the agent-to-agent protocol.
  By default only Alfred uses it: your agents can talk to Alfred, not to each other through it. You can extend that in settings. Agents can over-communicate, so Alfred keeps each one to a small talk budget." Nothing to set up.
- "The first time Alfred passes a message to an agent in a Terminal tab, your Mac asks once whether "node" may control
  Terminal. That's Alfred. Say OK."

If something failed, say what the log says in one plain line, and offer to try again.

## 9. Old chats (offer once)
Only if `/Applications/WhatsApp.app` exists.
Say: "The morning brief and messaging people need Alfred to read your old chats. That needs one switch in System Settings. Want it?"
On yes, start `~/.alfred/current/bin/cli history` in the background. System Settings and a Finder window open. Say:
- "Drag the file wa-history-copy from the Finder window into the list in System Settings."
- "Make sure its switch is on."

Check `~/.alfred/current/bin/cli status` every 15 seconds (up to 5 minutes) until it says old chats are readable.
If they say not now: tell them they can ask you, or any Claude chat on this Mac, any time.
If it says it needs Apple's command line tools, run `xcode-select --install`, say "Click Install", wait, then try again.

## Rules
- Run the setup, `link` and `repair` in the background: they wait for the phone, longer than one command may run.
- Their password is only ever typed into macOS's own window. Never ask for it or handle it.
- Open pages and installers with `open`. Not with osascript: that makes macOS ask for a permission it doesn't need.
- Alfred has an `alfred` command too, but nobody needs it. Use `~/.alfred/current/bin/cli` yourself.
