@andrzejchm/notion-cli 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,474 +0,0 @@
1
- # Notion CLI — Agent Skill Reference
2
-
3
- > **Audience:** AI coding agents (Claude Code, OpenCode, Codex) and developers.
4
- > Use this reference to query Notion pages and databases directly from the terminal or within automated workflows.
5
-
6
- The `notion` CLI provides read access to Notion workspaces via the official API. Agents can fetch page content as markdown, query structured databases as JSON, and discover workspace resources — all without leaving the shell.
7
-
8
- ---
9
-
10
- ## Table of Contents
11
-
12
- 1. [Installation & Setup](#installation--setup)
13
- 2. [Agent Setup by Platform](#agent-setup-by-platform)
14
- 3. [Output Modes](#output-modes)
15
- 4. [Command Reference](#command-reference)
16
- - [Authentication](#authentication)
17
- - [Search & Discovery](#search--discovery)
18
- - [Page Reading](#page-reading)
19
- - [Database Operations](#database-operations)
20
- 5. [Common Agent Patterns](#common-agent-patterns)
21
- 6. [ID and URL Formats](#id-and-url-formats)
22
- 7. [Troubleshooting](#troubleshooting)
23
-
24
- ---
25
-
26
- ## Installation & Setup
27
-
28
- ```bash
29
- npm install -g @andrzejchm/notion-cli
30
- notion init # interactive setup — enter your Notion integration token
31
- ```
32
-
33
- **Alternative: environment variable (preferred for CI and agent environments)**
34
-
35
- ```bash
36
- export NOTION_API_TOKEN=ntn_your_token_here
37
- ```
38
-
39
- Get your token at: https://www.notion.so/profile/integrations/internal
40
-
41
- > **Integration access:** Each page or database your agent needs must be explicitly shared with your integration.
42
- > In Notion: open the page → `⋯` menu → **Add connections** → select your integration.
43
-
44
- ---
45
-
46
- ## Agent Setup by Platform
47
-
48
- ### Claude Code
49
-
50
- Add to `CLAUDE.md`:
51
-
52
- ```markdown
53
- ## Notion Access
54
-
55
- Use `notion` CLI to access Notion pages and databases.
56
-
57
- - Auth: ensure `NOTION_API_TOKEN` is set, or run `notion init` once.
58
- - Page content: `notion read <id>` outputs markdown.
59
- - Structured data: `notion db query <id> --json | jq '.[] | .properties'`
60
- - See `docs/agent-skill.md` for full command reference and patterns.
61
- ```
62
-
63
- ### OpenCode
64
-
65
- Add to `.opencode/config.json`:
66
-
67
- ```json
68
- {
69
- "tools": ["bash"],
70
- "instructions": "notion CLI is available for Notion access. See docs/agent-skill.md for full usage."
71
- }
72
- ```
73
-
74
- Ensure `NOTION_API_TOKEN` is set in your shell environment before starting OpenCode.
75
-
76
- ### Codex / Generic Agents
77
-
78
- Add to system prompt or `AGENTS.md`:
79
-
80
- ```markdown
81
- Available tool: `notion` CLI (npm install -g @andrzejchm/notion-cli)
82
- Auth: set NOTION_API_TOKEN env var, or run `notion init` interactively.
83
- See docs/agent-skill.md for commands, flags, and agent patterns.
84
- ```
85
-
86
- ---
87
-
88
- ## Output Modes
89
-
90
- The CLI outputs plain text tables by default — in terminal and when piped.
91
-
92
- | Context | Default Output | Override flag |
93
- |-------------------|-----------------------------|--------------------|
94
- | Terminal (TTY) | Formatted tables, colored | `--json` for JSON |
95
- | Piped / agent | Plain text tables | `--json` for JSON |
96
-
97
- **For agents: add `--json` to get machine-readable output:**
98
-
99
- ```bash
100
- notion search "my query" --json | jq '.[]'
101
- notion ls --json | jq '.[] | {id, title}'
102
- notion db query "$DB_ID" --json | jq '.[] | .properties.Status'
103
- ```
104
-
105
- **For page content: markdown is always the default in both modes:**
106
-
107
- ```bash
108
- notion read "$PAGE_ID" # markdown output (works in terminal AND piped)
109
- notion read "$PAGE_ID" --json # raw JSON block tree
110
- ```
111
-
112
- **Global flags** (apply to all commands):
113
-
114
- | Flag | Effect |
115
- |----------|-----------------|
116
- | `--json` | Force JSON output |
117
-
118
- ---
119
-
120
- ## Command Reference
121
-
122
- ### Authentication
123
-
124
- #### `notion init`
125
-
126
- Interactive setup wizard. Prompts for a profile name and integration token, validates the token against the Notion API, and saves the profile.
127
-
128
- ```bash
129
- notion init
130
- ```
131
-
132
- - Must be run in a TTY (terminal). Use `NOTION_API_TOKEN` env var in non-interactive environments.
133
- - On success: saves profile to `~/.notion.yaml` and sets it as active.
134
-
135
- ---
136
-
137
- #### `notion profile list`
138
-
139
- Lists all saved auth profiles with the active profile marked.
140
-
141
- ```bash
142
- notion profile list
143
- ```
144
-
145
- ```bash
146
- notion profile list --json
147
- # [{"name":"default","workspace":"My Workspace","active":true}, ...]
148
- ```
149
-
150
- ---
151
-
152
- #### `notion profile use <name>`
153
-
154
- Switches the active profile.
155
-
156
- ```bash
157
- notion profile use work
158
- ```
159
-
160
- ---
161
-
162
- #### `notion profile remove <name>`
163
-
164
- Removes a saved profile. If the removed profile was active, no profile is set as active.
165
-
166
- ```bash
167
- notion profile remove old-profile
168
- ```
169
-
170
- ---
171
-
172
- ### Search & Discovery
173
-
174
- #### `notion search <query>`
175
-
176
- Searches workspace titles (not full-text content). Returns pages and databases accessible to your integration.
177
-
178
- ```bash
179
- notion search "Meeting Notes"
180
- notion search "project docs" --type page
181
- notion search "tracker" --type database
182
- ```
183
-
184
- **Flags:**
185
-
186
- | Flag | Description |
187
- |-------------------|------------------------------------------|
188
- | `--type page` | Return only pages |
189
- | `--type database` | Return only databases |
190
- | `--json` | Force JSON output |
191
-
192
- **Agent usage:**
193
-
194
- ```bash
195
- notion search "Weekly Review" --type page | jq '.[0].id'
196
- notion search "Tasks" --type database --json | jq '.[0].id'
197
- ```
198
-
199
- **JSON output shape:**
200
-
201
- ```json
202
- [
203
- {
204
- "id": "abc123def456789012345678901234ab",
205
- "title": "Weekly Review",
206
- "type": "page",
207
- "url": "https://www.notion.so/myworkspace/Weekly-Review-abc123"
208
- }
209
- ]
210
- ```
211
-
212
- ---
213
-
214
- #### `notion ls`
215
-
216
- Lists all top-level pages and databases shared with your integration.
217
-
218
- ```bash
219
- notion ls
220
- notion ls --json
221
- ```
222
-
223
- **Agent usage:**
224
-
225
- ```bash
226
- notion ls | jq '.[] | select(.type == "database") | {id, title}'
227
- ```
228
-
229
- ---
230
-
231
- #### `notion open <id/url>`
232
-
233
- Opens a Notion page or database in the default browser. Prints the URL to stdout for scriptable use.
234
-
235
- ```bash
236
- notion open abc123def456789012345678901234ab
237
- notion open "https://www.notion.so/myworkspace/My-Page-abc123"
238
- ```
239
-
240
- ---
241
-
242
- #### `notion users`
243
-
244
- Lists all members of the workspace.
245
-
246
- ```bash
247
- notion users
248
- notion users --json
249
- ```
250
-
251
- **JSON output shape:**
252
-
253
- ```json
254
- [
255
- {
256
- "id": "user-uuid",
257
- "name": "Alice Smith",
258
- "email": "alice@example.com",
259
- "type": "person"
260
- }
261
- ]
262
- ```
263
-
264
- ---
265
-
266
- #### `notion comments <id/url>`
267
-
268
- Lists all comments on a page.
269
-
270
- ```bash
271
- notion comments abc123def456789012345678901234ab
272
- notion comments "https://www.notion.so/myworkspace/My-Page-abc123" --json
273
- ```
274
-
275
- **JSON output shape:**
276
-
277
- ```json
278
- [
279
- {
280
- "id": "comment-uuid",
281
- "author": "Alice Smith",
282
- "text": "This looks good!",
283
- "created": "2026-01-15T10:00:00Z"
284
- }
285
- ]
286
- ```
287
-
288
- ---
289
-
290
- ### Page Reading
291
-
292
- #### `notion read <id/url>`
293
-
294
- Fetches a Notion page and outputs its content as markdown. This is the primary command for reading page content.
295
-
296
- ```bash
297
- notion read abc123def456789012345678901234ab
298
- notion read "https://www.notion.so/myworkspace/My-Page-abc123def456"
299
- notion read abc123def456789012345678901234ab --json # raw JSON block tree
300
- ```
301
-
302
- **Flags:**
303
-
304
- | Flag | Description |
305
- |----------|----------------------------------|
306
- | `--json` | Output raw Notion JSON block tree |
307
-
308
- **Notes:**
309
- - Default output is always markdown (even when piped).
310
- - Accepts 32-char hex IDs, UUID format, or full Notion URLs.
311
- - The page must be shared with your integration.
312
-
313
- **Agent usage:**
314
-
315
- ```bash
316
- # Read and search for a section
317
- notion read "$PAGE_ID" | grep -A 10 "## Action Items"
318
-
319
- # Extract all headings
320
- notion read "$PAGE_ID" | grep "^#"
321
-
322
- # Pass to LLM for summarization
323
- notion read "$PAGE_ID" | your-summarize-command
324
- ```
325
-
326
- ---
327
-
328
- ### Database Operations
329
-
330
- #### `notion db schema <id/url>`
331
-
332
- Retrieves the schema (property names and types) of a Notion database. **Always run this before building filters** to see available properties and valid select/status values.
333
-
334
- ```bash
335
- notion db schema abc123def456789012345678901234ab
336
- notion db schema "$DB_ID" --json
337
- ```
338
-
339
- **JSON output shape:**
340
-
341
- ```json
342
- {
343
- "id": "abc123def456789012345678901234ab",
344
- "title": "Project Tracker",
345
- "properties": {
346
- "Name": { "type": "title" },
347
- "Status": {
348
- "type": "select",
349
- "options": ["Not started", "In Progress", "Done"]
350
- },
351
- "Assignee": { "type": "people" },
352
- "Due Date": { "type": "date" }
353
- }
354
- }
355
- ```
356
-
357
- ---
358
-
359
- #### `notion db query <id/url>`
360
-
361
- Queries a Notion database with optional filters, sorting, and column selection.
362
-
363
- ```bash
364
- notion db query abc123def456789012345678901234ab
365
- notion db query "$DB_ID" --filter "Status=Done"
366
- notion db query "$DB_ID" --filter "Priority=High" --filter "Status=In Progress"
367
- notion db query "$DB_ID" --sort "Name:asc"
368
- notion db query "$DB_ID" --sort "Created:desc"
369
- notion db query "$DB_ID" --columns "Title,Status,Assignee"
370
- notion db query "$DB_ID" --json
371
- ```
372
-
373
- **Flags:**
374
-
375
- | Flag | Description |
376
- |------------------------|----------------------------------------------------------------|
377
- | `--filter "Prop=Val"` | Filter rows where property equals value. Repeatable. |
378
- | `--sort "Prop:dir"` | Sort by property. Direction: `asc` or `desc`. Repeatable. |
379
- | `--columns "A,B,C"` | Limit output to specific columns (comma-separated). |
380
- | `--json` | Force JSON output. |
381
-
382
- **Agent usage:**
383
-
384
- ```bash
385
- # Get all done items as JSON
386
- notion db query "$DB_ID" --filter "Status=Done" --json | jq '.[] | .properties'
387
-
388
- # Extract title and status for each row
389
- notion db query "$DB_ID" --json | jq '.[] | {id, title: .properties.Name, status: .properties.Status}'
390
-
391
- # Get most recently modified items
392
- notion db query "$DB_ID" --sort "Last edited:desc" --columns "Title,Status" | head -20
393
- ```
394
-
395
- **JSON output shape:**
396
-
397
- ```json
398
- [
399
- {
400
- "id": "row-uuid",
401
- "properties": {
402
- "Name": "Project Alpha",
403
- "Status": "In Progress",
404
- "Assignee": "Alice Smith",
405
- "Due Date": "2026-03-01"
406
- }
407
- }
408
- ]
409
- ```
410
-
411
- ---
412
-
413
- ## Common Agent Patterns
414
-
415
- ```bash
416
- # Pattern 1: Find a page by title, then read it
417
- PAGE_ID=$(notion search "Meeting Notes" --type page | jq -r '.[0].id')
418
- notion read "$PAGE_ID"
419
-
420
- # Pattern 2: Get all items with a specific status from a database
421
- DB_ID=$(notion search "Project Tracker" --type database | jq -r '.[0].id')
422
- notion db query "$DB_ID" --filter "Status=Done" | jq '.[] | .properties'
423
-
424
- # Pattern 3: List recent entries sorted by date
425
- notion db query "$DB_ID" --sort "Last edited:desc" --columns "Title,Status" | head -20
426
-
427
- # Pattern 4: Read a page and extract specific content
428
- notion read "$PAGE_ID" | grep -A 5 "## Action Items"
429
-
430
- # Pattern 5: Check database schema before building a filter
431
- notion db schema "$DB_ID" # see what properties exist and their valid values
432
- notion db query "$DB_ID" --filter "Status=In Progress"
433
-
434
- # Pattern 6: Using URLs instead of IDs
435
- notion read "https://www.notion.so/myworkspace/My-Page-abc123def456"
436
- notion db query "https://www.notion.so/myworkspace/My-DB-abc123def456"
437
-
438
- # Pattern 7: Combine search + query in one pipeline
439
- notion search "Tasks" --type database | jq -r '.[0].id' | xargs -I{} notion db query {} --filter "Assignee=Alice" --json
440
- ```
441
-
442
- ---
443
-
444
- ## ID and URL Formats
445
-
446
- The CLI accepts any of these formats for the `<id>` argument in all commands:
447
-
448
- | Format | Example |
449
- |--------------|------------------------------------------------------|
450
- | 32-char hex | `abc123def456789012345678901234ab` |
451
- | UUID | `abc123de-f456-7890-1234-5678901234ab` |
452
- | Full URL | `https://www.notion.so/workspace/Page-Title-abc123` |
453
-
454
- All commands (`read`, `db query`, `db schema`, `open`, `comments`) accept any of these formats.
455
-
456
- ---
457
-
458
- ## Troubleshooting
459
-
460
- **Page not found (404):** The page must be shared with your integration.
461
- In Notion: open the page → `⋯` menu → **Add connections** → select your integration.
462
-
463
- **Unauthorized (401):** Your token is invalid or expired.
464
- Run `notion init` to reconfigure, or set a new `NOTION_API_TOKEN`.
465
- Get a new token at: https://www.notion.so/profile/integrations/internal
466
-
467
- **Search returns no results:** Search is title-only (not full-text content search).
468
- The page or database must also be explicitly shared with your integration.
469
-
470
- **Empty database query:** No entries match your filters, or the database has no entries.
471
- Run `notion db schema <id>` first to see available properties and their valid values.
472
-
473
- **`notion init` fails in agent/CI environment:** `notion init` requires an interactive terminal (TTY).
474
- Use the `NOTION_API_TOKEN` environment variable instead.