Notion Sync
by @robansuini
Bi-directional sync and management for Notion pages and databases. Use when working with Notion workspaces for collaborative editing, research tracking, proj...
clawhub install notion-syncπ About This Skill
name: notion-sync description: Bi-directional sync and management for Notion pages and databases. Use when working with Notion workspaces for collaborative editing, research tracking, project management, or when you need to sync markdown files to/from Notion pages or monitor Notion pages for changes. homepage: https://github.com/robansuini/agent-skills repository: https://github.com/robansuini/agent-skills/tree/main/productivity/notion-sync license: MIT-0 metadata: clawdis: requires: env: [NOTION_API_KEY] bins: [node] stateDirs: [memory]
Notion Sync
Bi-directional sync between markdown files and Notion pages, plus database management utilities for research tracking and project management.
Upgrading
From v2.0: Replace --token "ntn_..." with --token-file, --token-stdin, or NOTION_API_KEY env var. Bare --token is no longer accepted (credentials should never appear in process listings).
From v1.x: See v2.0 changelog for migration details.
Requirements
ntn_ or secret_)Setup
1. Go to https://www.notion.so/my-integrations 2. Create a new integration (or use an existing one) 3. Copy the "Internal Integration Token" 4. Pass the token using one of these methods (priority order used by scripts):
Option A β Token file (recommended):
echo "ntn_your_token" > ~/.notion-token && chmod 600 ~/.notion-token
node scripts/search-notion.js "query" --token-file ~/.notion-token
Option B β Stdin pipe:
echo "$NOTION_API_KEY" | node scripts/search-notion.js "query" --token-stdin
Option C β Environment variable:
export NOTION_API_KEY="ntn_your_token"
node scripts/search-notion.js "query"
Auto default: If ~/.notion-token exists, scripts use it automatically even without --token-file.
5. Share your Notion pages/databases with the integration: - Open the page/database in Notion - Click "Share" β "Invite" - Select your integration
JSON Output Mode
All scripts support a global --json flag.
{ "error": "..." }Example:
node scripts/query-database.js --limit 5 --json
Path Safety Mode
Scripts that read/write local files are restricted to the current working directory by default.
md-to-notion.js, add-to-database.js, notion-to-md.js, watch-notion.js--allow-unsafe-pathsExamples:
# Default (safe): path must be inside current workspace
node scripts/md-to-notion.js docs/draft.md "Draft"Intentional override (outside workspace)
node scripts/notion-to-md.js ~/Downloads/export.md --allow-unsafe-paths
Core Operations
1. Search Pages and Databases
Search across your Notion workspace by title or content.
node scripts/search-notion.js "" [--filter page|database] [--limit 10] [--json]
Examples:
# Search for newsletter-related pages
node scripts/search-notion.js "newsletter"Find only databases
node scripts/search-notion.js "research" --filter databaseLimit results
node scripts/search-notion.js "AI" --limit 5
Output:
[
{
"id": "page-id-here",
"object": "page",
"title": "Newsletter Draft",
"url": "https://notion.so/...",
"lastEdited": "2026-02-01T09:00:00.000Z"
}
]
2. Query Databases with Filters
Query database contents with advanced filters and sorting.
node scripts/query-database.js [--filter ] [--sort ] [--limit 10] [--json]
Examples:
# Get all items
node scripts/query-database.js xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFilter by Status = "Complete"
node scripts/query-database.js \
--filter '{"property": "Status", "select": {"equals": "Complete"}}'Filter by Tags containing "AI"
node scripts/query-database.js \
--filter '{"property": "Tags", "multi_select": {"contains": "AI"}}'Sort by Date descending
node scripts/query-database.js \
--sort '[{"property": "Date", "direction": "descending"}]'Combine filter + sort
node scripts/query-database.js \
--filter '{"property": "Status", "select": {"equals": "Complete"}}' \
--sort '[{"property": "Date", "direction": "descending"}]'
Common filter patterns:
{"property": "Status", "select": {"equals": "Done"}}{"property": "Tags", "multi_select": {"contains": "AI"}}{"property": "Date", "date": {"after": "2024-01-01"}}{"property": "Published", "checkbox": {"equals": true}}{"property": "Count", "number": {"greater_than": 100}}3. Update Page Properties
Update properties for database pages (status, tags, dates, etc.).
node scripts/update-page-properties.js [--type ] [--json]
Supported types: select, multi_select, checkbox, number, url, email, date, rich_text
Examples:
# Set status
node scripts/update-page-properties.js Status "Complete" --type selectAdd multiple tags
node scripts/update-page-properties.js Tags "AI,Leadership,Research" --type multi_selectSet checkbox
node scripts/update-page-properties.js Published true --type checkboxSet date
node scripts/update-page-properties.js "Publish Date" "2024-02-01" --type dateSet URL
node scripts/update-page-properties.js "Source URL" "https://example.com" --type urlSet number
node scripts/update-page-properties.js "Word Count" 1200 --type number
4. Batch Update
Batch update a single property across multiple pages in one command.
Mode 1 β Query + Update:
node scripts/batch-update.js --filter '' [--type select] [--dry-run] [--limit 100]
Example:
node scripts/batch-update.js Status Review \
--filter '{"property":"Status","select":{"equals":"Draft"}}' \
--type select
Mode 2 β Page IDs from stdin:
echo "page-id-1\npage-id-2\npage-id-3" | \
node scripts/batch-update.js --stdin [--type select] [--dry-run]
Features:
--dry-run: prints pages that would be updated (with current property value) without writing--limit : max pages to process (default 100)has_more/next_cursor) up to limit5. Markdown β Notion Sync
Push markdown content to Notion with full formatting support.
node scripts/md-to-notion.js \
"" \
"" \
"" [--json] [--allow-unsafe-paths]
Example:
node scripts/md-to-notion.js \
"projects/newsletter-draft.md" \
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
"Newsletter Draft - Feb 2026"
Supported formatting:
Features:
Output:
Parsed 294 blocks from markdown
β Created page: https://www.notion.so/[title-and-id]
β Appended 100 blocks (100-200)
β Appended 94 blocks (200-294)β
Successfully created Notion page!
6. Notion β Markdown Sync
Pull Notion page content and convert to markdown.
node scripts/notion-to-md.js [output-file] [--json] [--allow-unsafe-paths]
Example:
node scripts/notion-to-md.js \
"abc123-example-page-id-456def" \
"newsletter-updated.md"
Features:
7. Change Detection & Monitoring
Monitor Notion pages for edits and compare with local markdown files.
node scripts/watch-notion.js "" "" [--state-file ] [--json] [--allow-unsafe-paths]
Example:
node scripts/watch-notion.js \
"abc123-example-page-id-456def" \
"projects/newsletter-draft.md"
State tracking: By default maintains state in memory/notion-watch-state.json (relative to current working directory). You can override with --state-file (supports ~ expansion):
node scripts/watch-notion.js "" "" --state-file ~/.cache/notion-watch-state.json
Default state schema:
{
"pages": {
"": {
"lastEditedTime": "2026-01-30T08:57:00.000Z",
"lastChecked": "2026-01-31T19:41:54.000Z",
"title": "Your Page Title"
}
}
}
Output:
{
"pageId": "",
"title": "Your Page Title",
"lastEditedTime": "2026-01-30T08:57:00.000Z",
"hasChanges": false,
"localPath": "/path/to/your-draft.md",
"actions": ["β No changes since last check"]
}
Automated monitoring: Schedule periodic checks using cron, CI pipelines, or any task scheduler:
# Example: cron job every 2 hours during work hours
0 9-21/2 * * * cd /path/to/workspace && node scripts/watch-notion.js "" ""
The script outputs JSON β pipe it to any notification system when hasChanges is true.
8. Database Management
#### Add Markdown Content to Database
Add a markdown file as a new page in any Notion database.
node scripts/add-to-database.js "" [--json] [--allow-unsafe-paths]
Examples:
# Add research output
node scripts/add-to-database.js \
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
"Research Report - Feb 2026" \
projects/research-insights.mdAdd project notes
node scripts/add-to-database.js \
\
"Sprint Retrospective" \
docs/retro-2026-02.mdAdd meeting notes
node scripts/add-to-database.js \
\
"Weekly Team Sync" \
notes/sync-2026-02-06.md
Features:
Note: Additional properties (Type, Tags, Status, etc.) must be set manually in Notion UI after creation.
#### Inspect Database Schema
node scripts/get-database-schema.js [--json]
Example output:
{
"object": "database",
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"title": [{"plain_text": "Ax Resources"}],
"properties": {
"Name": {"type": "title"},
"Type": {"type": "select"},
"Tags": {"type": "multi_select"}
}
}
Use when:
#### Archive Pages
node scripts/delete-notion-page.js [--json]
Note: This archives the page (sets archived: true), not permanent deletion.
Common Workflows
Collaborative Editing Workflow
1. Push local draft to Notion:
node scripts/md-to-notion.js draft.md "Draft Title"
2. User edits in Notion (anywhere, any device)
3. Monitor for changes:
node scripts/watch-notion.js
# Returns hasChanges: true when edited
4. Pull updates back:
node scripts/notion-to-md.js draft-updated.md
5. Repeat as needed (update same page, don't create v2/v3/etc.)
Research Output Tracking
1. Generate research locally (e.g., via sub-agent)
2. Sync to Notion database:
node scripts/add-research-to-db.js
3. User adds metadata in Notion UI (Type, Tags, Status properties)
4. Access from anywhere via Notion web/mobile
Page ID Extraction
From Notion URL: https://notion.so/Page-Title-abc123-example-page-id-456def
Extract: abc123-example-page-id-456def (last part after title)
Or use the 32-char format: abc123examplepageid456def (hyphens optional)
Limitations
Troubleshooting
"Could not find page" error:
"Module not found" error:
Rate limiting:
Resources
scripts/
Core Sync:
Search & Query:
Database Management:
Utilities:
All scripts use only built-in Node.js modules (https, fs) - no external dependencies required.
references/
βοΈ Configuration
1. Go to https://www.notion.so/my-integrations 2. Create a new integration (or use an existing one) 3. Copy the "Internal Integration Token" 4. Pass the token using one of these methods (priority order used by scripts):
Option A β Token file (recommended):
echo "ntn_your_token" > ~/.notion-token && chmod 600 ~/.notion-token
node scripts/search-notion.js "query" --token-file ~/.notion-token
Option B β Stdin pipe:
echo "$NOTION_API_KEY" | node scripts/search-notion.js "query" --token-stdin
Option C β Environment variable:
export NOTION_API_KEY="ntn_your_token"
node scripts/search-notion.js "query"
Auto default: If ~/.notion-token exists, scripts use it automatically even without --token-file.
5. Share your Notion pages/databases with the integration: - Open the page/database in Notion - Click "Share" β "Invite" - Select your integration
π Tips & Best Practices
"Could not find page" error:
"Module not found" error:
Rate limiting: