Step-by-step instructions to install and run cairn on a new macOS machine. cairn is a personal-use worklog tool — every machine you run it on uses its own secrets and configuration.
한국어 가이드: SETUP.ko.md
Most people should use the desktop app instead. The cairn desktop app has a guided first-run wizard that connects Notion + GitHub (reusing your
ghCLI login when present), writes.env+worklog.config.jsonfor you, and owns auto-publish scheduling. This guide is the manual / headless / CLI-only path — for a server with no GUI, or for automating withlaunchd. Cross-device stats sync is a desktop-app feature (sign in with Google in the app) and is not part of this CLI flow.
- macOS — required only for the headless
launchdschedule (§9); the desktop app handles scheduling itself - Node 24 LTS — see .nvmrc. Install via
nvm,volta, orhomebrew. - pnpm 10+ —
npm install -g pnpm - Claude Pro or Max subscription — cairn calls the Claude Agent SDK and inherits your Claude Code OAuth credentials. No separate Anthropic API key is required when you are signed in to Claude Code locally.
- Notion account with at least one workspace where you can create an internal integration.
- GitHub account with PRs / reviews you want to track.
git clone https://github.com/<owner>/cairn.git
cd cairn
nvm use # respects .nvmrc
pnpm install
pnpm buildpnpm build compiles @cairn/core into packages/core/dist/main.js, the entry point used by both the CLI and the launchd jobs.
cairn writes to one Notion workspace at a time per integration. The same parent page hosts both the daily worklog DB and the rollup DB (auto-created on first run).
- Open https://www.notion.so/profile/integrations and click New integration.
- Give it a name (e.g.
cairn-personal) and pick the workspace you will publish into. - Capabilities: enable Read content, Update content, Insert content.
- Save and copy the Internal Integration Secret (starts with
ntn_…).
- In the same workspace, create a regular page that will host cairn's databases (e.g.
cairnorWorklog). - Open the page menu → Connections → Add connections → select your integration. The integration must be able to read/write this page.
- Copy the page URL. The 32-character hex segment at the end is the page ID. Format it as a UUID with dashes (
8-4-4-4-12). Example:https://notion.so/My-cairn-aabbccddeeff00112233445566778899 → pageId = aabbccdd-eeff-0011-2233-445566778899
cairn filters Notion edits to entries you authored, using your user ID.
curl -sS https://api.notion.com/v1/users/me \
-H "Authorization: Bearer ntn_your_token_here" \
-H "Notion-Version: 2022-06-28" \
| jq -r '.id'Copy the UUID — that is your myUserId.
cairn supports multiple GitHub accounts (e.g. personal + work). Create a fine-grained PAT for each account you want to track:
- https://github.com/settings/personal-access-tokens/new (while logged into that account)
- Resource owner: yourself (or the org if you want to track org PRs).
- Repository access: pick the specific repos you want to track.
- Permissions (Repository permissions):
Pull requests: Read-only,Contents: Read-only,Metadata: Read-only. - Generate and copy the token (starts with
github_pat_…).
cairn never writes to GitHub. Read-only access is sufficient.
Each token goes into a separate .env variable (see §6) and is referenced by githubAccounts[].tokenEnv in worklog.config.json (see §7).
For each local repo whose commits you want included, you need its absolute path. Make sure git config user.email matches the email associated with your authoring identity in those repos:
cd /path/to/repo
git config user.emailcairn uses this to filter commits to ones you authored.
Copy the example and fill in the secrets you obtained above:
cp .env.example .envMACHINE_NAME=personal-mac
NODE_ENV=development
# MACHINE_NAME labels this machine; NODE_ENV=production enables native notifications
# (the launchd plists set it). Both have sane defaults.
ANTHROPIC_OAUTH_TOKEN=
# Optional. Leave empty when running under Claude Code (inherits OAuth).
GITHUB_TOKEN_PERSONAL=github_pat_...
GITHUB_TOKEN_WORK=github_pat_...
# Add GITHUB_TOKEN_<LABEL> for each githubAccounts[].tokenEnv you reference.
NOTION_TOKEN_PERSONAL=ntn_...
NOTION_TOKEN_WORK=ntn_...
# Add NOTION_TOKEN_<LABEL> for each notionWorkspaces[].tokenEnv you reference.
CAIRN_CONFIG_PATH=
# Optional. Overrides the worklog.config.json path (defaults to ./worklog.config.json)..env is gitignored. Keep it that way.
Create worklog.config.json in the repo root with:
{
"localGitRepos": ["/Users/me/code/repo-1", "/Users/me/code/repo-2"],
"githubAccounts": [
{ "label": "personal", "tokenEnv": "GITHUB_TOKEN_PERSONAL" },
{ "label": "work", "tokenEnv": "GITHUB_TOKEN_WORK" }
],
"notionWorkspaces": [
{
"label": "personal",
"tokenEnv": "NOTION_TOKEN_PERSONAL",
"myUserId": "<your-notion-user-id>",
"worklog": { "pageId": "<parent-page-id>" }
}
]
}githubAccounts is a free-form array — add as many entries as you have GitHub identities. The label is a human-readable name you choose (personal, work, oss, side-project-a, …); cairn echoes it back in every PR summary and surfaces it in the Korean digest, so pick something short and unambiguous. tokenEnv is the .env variable name that holds the PAT — convention is GITHUB_TOKEN_<UPPER_LABEL>, but any name works as long as .env and this file agree. Omit the array (or leave it empty) only if you want to track zero GitHub accounts.
You only need worklog.pageId (the parent page from §3.2). cairn auto-creates two inline databases inside that page on first run:
Daily Worklog (cairn)— daily worklog DBRollup (cairn)— weekly/monthly rollup DB (created on first weekly/monthly run)
The discovered databaseId and dataSourceId for each are written back into worklog.config.json automatically. If you want the rollup DB on a different page, set a separate rollup.pageId explicitly — otherwise it defaults to the same parent as the worklog DB.
worklog.config.json is gitignored.
node packages/core/dist/main.js --mode=daily --date=$(date +%F) --dry-runYou should see GitHub / local-git / Notion activity dumped as JSON.
node packages/core/dist/main.js --mode=daily --date=$(date +%F)Expected on a successful first run:
- A new inline DB
Daily Worklog (cairn)appears on your parent page. - A new page
<date> 작업 일지is published in that DB. worklog.config.jsongainsdatabaseId/dataSourceIdunderworklog.- A macOS notification appears:
cairn 일지 — <date> 발행 (gh:N / git:N / notion:N).
Re-running on the same date should print worklog page already exists — skip (use --force to recreate) and emit a skip notification. Use --force to archive and recreate.
Once a daily page exists in a given week / month, you can produce the rollup:
node packages/core/dist/main.js --mode=weekly --date=$(date +%F)
node packages/core/dist/main.js --mode=monthly --date=$(date +%F)The rollup DB is auto-created on the first such run. Weekly title format: 2026-W19 주간 정리. Monthly: 2026-05 월간 정리.
Desktop-app users can skip this section. Auto-publish is owned by the desktop app at a time you choose in your local timezone (ADR 0015);
launchdis the deprecated headless / CLI-only scheduler, kept for GUI-less setups.
Register all three jobs (daily, weekly, monthly) in one shot:
ops/install.shThe script:
- Reads each
ops/com.user.cairn-{daily,weekly,monthly}.plist.template - Substitutes your absolute Node path,
cairndirectory, and$HOME - Writes the resolved plists to
~/Library/LaunchAgents/ - Loads them via
launchctl bootstrap gui/$UID
Verify:
launchctl list | grep cairnDefault schedule (system TZ):
| Job | Schedule |
|---|---|
| daily | every day, 19:00 + 23:00, + RunAtLoad |
| weekly | every Monday, 07:00 + 11:00, + RunAtLoad |
| monthly | every 2nd of the month, 07:00 + 11:00, + RunAtLoad |
Each job has two scheduled slots so a sleeping laptop catches up at the second wake-up. RunAtLoad: true also fires once on user login / session start, and the daily mode automatically backfills any missing days within the last 7 days — so opening the laptop after a closed-overnight stretch publishes whatever was missed.
If you want the 03:00-style early slot to fire even with the lid closed, run with --with-wake:
ops/install.sh --with-wakeThis adds sudo pmset repeat wakeorpoweron MTWRFSU 02:55:00. The Mac wakes briefly at 02:55, the 03:00 launchd slot fires cairn, and the system goes back to sleep. A sentinel file (~/.cairn/pmset-installed-by-cairn) tracks that cairn installed this, so --uninstall removes it cleanly without touching unrelated pmset schedules.
Caveats:
pmset repeatis system-wide and only supports one schedule slot — installing this overwrites any other tool'spmset repeat.- Requires
sudo. - Wake reliability with lid closed depends on AC vs battery, MacBook generation, and Apple Silicon firmware. Keep the charger connected for overnight reliability.
For most laptop-only personal use, the default (RunAtLoad + daily backfill) is enough — --with-wake is for users who want strict timing without manual laptop opens.
ops/install.sh --uninstallRemoves the three plists; if --with-wake was used, also removes the cairn-installed pmset repeat (sentinel-checked).
- Per-run pino logs:
~/.cairn/logs/cairn-YYYY-MM-DD.log(rotated daily bypino-roll). - launchd stdout / stderr:
~/.cairn/logs/launchd.{out,err}.log,launchd-weekly.{out,err}.log,launchd-monthly.{out,err}.log. - macOS native notifications fire only when
NODE_ENV=production(set by the launchd plists). Manual CLI runs are silent so dev iteration doesn't spam your notification center.
cairn is designed to run on multiple personal machines (e.g. work laptop + home laptop). For each new machine:
- Repeat §2 (clone, install, build).
- Repeat §6 (
.env) — never sync.envacross machines. - Repeat §7 (
worklog.config.json) — only the local-repo absolute paths differ; Notion / GitHub identifiers are shared. - Repeat §9 (
ops/install.sh).
Each machine writes to the same Notion workspace, and idempotency prevents conflicts on the same date.
The DB is created lazily on the first publish, not at config load. If --mode=weekly reports no daily pages in range — skipping summarizer + publisher, no publish happens, so no DB. Run with a date range that contains at least one published daily.
Either worklog.pageId is not set in worklog.config.json or the corresponding tokenEnv (e.g. NOTION_TOKEN_PERSONAL) is empty in .env.
Check that the integration is shared with the parent page (§3.2 step 2). The integration cannot see pages it has not been added to.
- The notification only fires under
NODE_ENV=production. Manual runs from a terminal are silent by design. - For launchd-triggered runs: System Settings → Notifications → Script Editor → ensure alerts are allowed (osascript notifications use Script Editor's notification permission).
StartCalendarIntervalis absolute time. Sleeping laptops do not catch up missed slots — that is why daily / weekly / monthly each have two time slots, plusRunAtLoad: trueso the agent fires on user login / session start.- Force a manual fire to verify:
launchctl kickstart -k gui/$UID/com.user.cairn-daily. - Check logs:
tail -f ~/.cairn/logs/launchd.err.log. - Missed days are auto-backfilled: when daily mode runs without an explicit
--date, it queries the worklog DB for the last--backfill-days(default 7) and publishes any missing dates in chronological order. RunAtLoad means this happens the next time you open the laptop. A single batched notification covers the lot. - To disable backfill for a one-off run: pass
--backfill-days=0. To target a specific date: pass--date=YYYY-MM-DD(this also disables backfill — you asked for that date specifically). - To wake the Mac from sleep at the scheduled time so even lid-closed nights fire on time, use
ops/install.sh --with-wake(see §9).
The cost callout only renders when the runner is the operator (CAIRN_OPERATOR_SECRET env matches the hash baked into source). External users / forks see no cost callout — this is intentional (ADR 0009).