/ai-analyst-plus:notion-ingestfrom ai-analyst-plus
Crawls a Notion workspace to extract business terms, metrics, product docs, and team structure into the organization knowledge system. Handles full or partial crawls with incremental updates.
Ships in ai-analyst-plus. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Requires the Notion connector enabled in Cowork.
Crawls a Notion workspace to extract business terms, metrics, product docs, and team structure. Populates the organization knowledge system.
Invoked as /notion-ingest or /notion-ingest {workspace_url}
.knowledge/user/integrations.yaml under notion.token
for the raw-API path.knowledge/organizations/{org}//setup-notion), or add an integration token to
.knowledge/user/integrations.yaml under notion.token."This skill uses a breadth-first crawl strategy to systematically traverse a Notion workspace, converting pages to structured knowledge entries. It does NOT require external Python packages — all Notion API calls use inline HTTP requests.
When running in an environment without actual Notion API access (e.g., for testing or evaluation):
The goal is to demonstrate you understand the workflow completely, not to produce encyclopedic output.
Preferred: the Notion connector. Try a test call to the connector's search tool (the Notion connector's search tool). If it works, use the connector's fetch/search tools for all Notion reads in the steps below; the crawl structure is unchanged, only the fetch mechanism differs.
Fallback: raw API with an integration token.
import yaml, os
# Load integration config
integrations_path = ".knowledge/user/integrations.yaml"
with open(integrations_path) as f:
config = yaml.safe_load(f)
notion_token = config.get("notion", {}).get("token")
if not notion_token:
print("No Notion connector and no token found. Run /setup-notion first.")
# HALT
Verify the token works with a simple API call:
GET https://api.notion.com/v1/users/me
Authorization: Bearer {token}
Notion-Version: 2022-06-28
IMPORTANT: Always ASK the user for crawl scope — do not assume. Present these options clearly and wait for their choice:
Notion workspace connected. How would you like to crawl?
1. **Full workspace** — Crawl all accessible pages (may be slow for large workspaces)
2. **Specific database** — Provide a database URL to crawl
3. **Specific page tree** — Provide a root page URL to crawl its children
4. **Search by keyword** — Search for pages matching specific terms
If the user already specified a scope in their request (e.g., "crawl our OKR database at [URL]"), proceed with that scope. Otherwise, present the options and wait for their selection before proceeding.
Algorithm: Breadth-First Search (BFS)
Queue ← [root_page_id]
Visited ← {}
Results ← []
WHILE Queue is not empty:
page_id ← Queue.dequeue()
IF page_id IN Visited: CONTINUE
Visited.add(page_id)
page ← fetch_page(page_id) # GET /v1/pages/{id}
children ← fetch_children(page_id) # GET /v1/blocks/{id}/children
result ← convert_to_knowledge(page, children)
Results.append(result)
# Enqueue child pages and linked databases
FOR child IN children:
IF child.type == "child_page" OR child.type == "child_database":
Queue.enqueue(child.id)
rate_limit_pause() # See Step 4
GET https://api.notion.com/v1/pages/{page_id}
Authorization: Bearer {token}
Notion-Version: 2022-06-28
GET https://api.notion.com/v1/blocks/{block_id}/children?page_size=100
Authorization: Bearer {token}
Notion-Version: 2022-06-28
Handle pagination via has_more and next_cursor.
Notion API limits: 3 requests per second for integration tokens.
import time
class RateLimiter:
"""Simple token-bucket rate limiter for Notion API."""
def __init__(self, requests_per_second=2.5):
self.min_interval = 1.0 / requests_per_second
self.last_request = 0
def wait(self):
elapsed = time.time() - self.last_request
if elapsed < self.min_interval:
time.sleep(self.min_interval - elapsed)
self.last_request = time.time()
Backoff strategy:
Retry-After header seconds, minimum 1sConvert Notion block types to markdown:
| Notion Block Type | Markdown Output |
|---|---|
| paragraph | Plain text |
| heading_1 | # Title |
| heading_2 | ## Title |
| heading_3 | ### Title |
| bulleted_list_item | - Item |
| numbered_list_item | 1. Item |
| code | ```lang\ncode\n``` |
| quote | > Quote |
| callout | > ℹ️ Callout |
| table | Markdown table |
| divider | --- |
| toggle | Treat as heading + nested content |
| child_page | [Page Title](notion://page_id) |
| child_database | [Database Title](notion://db_id) |
Rich text extraction:
**text***text*`text`[text](url)@{mention_name}For each crawled page, attempt to classify and extract structured knowledge:
| Page Contains | Classification | Target File |
|---|---|---|
| Term definitions, glossary entries | Glossary term | business/glossary/terms.yaml |
| KPI, metric, formula | Metric definition | business/metrics/index.yaml |
| Product name, feature list | Product entry | business/products/index.yaml |
| OKR, objective, key result | Objective | business/objectives/index.yaml |
| Team name, org chart | Team entry | business/teams/index.yaml |
| SQL query, data pattern | Query archaeology | .knowledge/query-archaeology/raw/ |
All crawled pages are saved as raw markdown to:
.knowledge/query-archaeology/raw/notion_{page_id_short}.md
With YAML frontmatter:
---
source: notion
page_id: {full_page_id}
title: {page_title}
url: {page_url}
crawled_at: {timestamp}
classification: {auto_class or "unclassified"}
---
During crawl, show progress updates periodically (every ~10-15 pages) to keep the user informed without overwhelming them:
🔄 Crawling Notion workspace...
Pages crawled: 45/~120 (estimated)
Terms extracted: 12
Metrics found: 5
Products found: 3
Errors: 1 (skipped)
Current: "Q4 2025 OKR Tracker"
For simulations: Show 2-3 progress snapshots (beginning, middle, end) rather than every single page. Focus on demonstrating the pattern, not exhaustive detail.
After crawl completes:
✅ Notion ingest complete!
Pages crawled: 127
Pages skipped: 3 (errors logged)
Knowledge extracted:
Glossary terms: 23 → business/glossary/terms.yaml
Metrics: 8 → business/metrics/index.yaml
Products: 5 → business/products/index.yaml
Objectives: 12 → business/objectives/index.yaml
Teams: 4 → business/teams/index.yaml
Raw pages saved: 127 → .knowledge/query-archaeology/raw/
Review extracted knowledge with `/business` to verify accuracy.
Auto-classifications may need manual correction.
For pages containing SQL queries or data patterns, create cookbook entries directly in the archaeology store. For each page with SQL content:
CK-{NNN} (scan .knowledge/query-archaeology/curated/cookbook/
for the highest existing number and increment).knowledge/query-archaeology/curated/cookbook/{entry_id}.yaml with:
id, title (the page title), description ("Reusable pattern: {title}"),
sql (the extracted SQL), dataset, tables, tags
(["notion-import", classification]), source_analysis ("notion:{page_id}"),
created_at and last_used (today), use_count: 0.knowledge/query-archaeology/curated/index.yaml| Error | Response |
|---|---|
| Invalid token | "Notion token is invalid or expired. Update in .knowledge/user/integrations.yaml." |
| Permission denied (403) | "Cannot access page '{title}'. Check integration permissions in Notion." |
| Rate limited (429) | Auto-retry with backoff (transparent to user) |
| Network error | Retry 3x, then skip page and continue |
| Empty workspace | "No accessible pages found. Verify the integration has access to your workspace." |
| Large workspace (500+) | "Large workspace detected (~{n} pages). This may take several minutes. Continue? [Y/n]" |
For subsequent runs, support incremental mode:
/notion-ingest --incremental
.knowledge/organizations/{org}/notion_sync_state.yaml for last sync timestampfilter.timestamp.last_edited_time.after parameter/notion-ingest reset — Clears all raw Notion pages and sync state. Does NOT remove
extracted knowledge entries (those must be cleaned via /business or manually).
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub ai-analyst-lab/ai-analyst-plugin --plugin ai-analyst-plus47 skills in this plugin
/always-compareNever present a metric or number in isolation; anchor every number to a comparison (prior period, benchmark, or another segment) or state that none is available. Use every time you show a number: rates, counts, revenue, averages, query results, chart labels, summary stats. Trigger on output containing "the rate is", "we saw", "total", "average", "conversion", "revenue", "users", "sessions", "churn", "AOV", "NPS", or any figure pulled from data./analysis-designTurn a vague hunch or stakeholder request into a rigorous analysis plan via a staged pipeline (hypothesis sharpening, confound scan, V1, feedback, V2 redesign). Trigger on "I think X caused Y", "design an analysis for", "what's driving", "V2 after feedback", "stakeholder comments", "redesign the analysis". Vs question-framing (the lightweight framing gate before every analysis): use THIS only for a real hunch, confound scan, or V1 to V2 redesign./analyst-coreOperating rules for every data analysis. Apply for ANY data-analysis intent: "analyze", "investigate", "why did X change", "compare", "report on", "dashboard", "metrics", "funnel", "retention", "revenue", "conversion", "trend", "segment", "forecast", "how are we doing", "dig into", "break down", or any question about data, a metric, a CSV, or a table. Sets the method and routes to the other skills; load before any analytical question.Other plugins' skills for the same job