onenote-cli
v0.1.0
Published
CLI tool to operate Microsoft OneNote via Graph API
Readme
onenote-cli
Make your OneNote notebooks survive in the age of AI.
A CLI that lets AI agents (and humans) search, read, and operate your OneNote — with full-text page-level search and deep links that open directly to the matching page.
Features
- Page-level search — search inside all your OneNote pages, get results with URLs that open directly to the matching page in OneNote Online
- Notebooks / Sections / Pages — list, get, create, delete via Graph API
- 5,000-item workaround — when Graph OneNote API is blocked by the SharePoint document library limit, automatically falls back to OneDrive file API + local binary parsing
- Local cache — downloads
.onefiles, extracts text (UTF-8 + UTF-16LE), builds a searchable index - Official OneNote URLs — resolves page GUIDs via
GET /me/onenote/sections/0-{guid}/pagesto get URLs that bypass OneNote Online's session caching - Device code flow auth — works in SSH / headless / terminal environments
- Cross-directory —
.env.localand cache are loaded from the package directory, soonenoteworks from any working directory
Install
As an AI Agent Skill
# Claude Code / OpenClaw / Codex / Cursor / any SKILL.md-compatible agent
npx skills add snomiao/onenote-cliManual
git clone https://github.com/snomiao/onenote-cli.git
cd onenote-cli
bun installSetup
- Register an Azure AD app at entra.microsoft.com (see docs/setup.md for full walkthrough)
- Copy
.env.exampleto.env.localand set your Client ID:cp .env.example .env.local # Edit .env.local with your Application (client) ID - Login:
bun run src/index.ts auth login
Usage
# Auth
onenote auth login # Login via device code flow
onenote auth whoami # Show current user
onenote auth setup # Print setup instructions
onenote auth logout # Clear tokens
# Notebooks
onenote notebooks list
onenote notebooks get <id>
onenote notebooks create <name>
# Sections (falls back to OneDrive if Graph API is blocked)
onenote sections list -n <notebook-id>
onenote sections create -n <notebook-id> --name <name>
# Pages
onenote pages list -s <section-id>
onenote pages get <id>
onenote pages content <id>
onenote pages create -s <section-id> -t <title> -b "<html>"
onenote pages delete <id>
# Search
onenote sync # Download and cache all sections
onenote search <query> # Full-text page-level search (local)
onenote search <query> -o # Online section-level search (Graph API)Search Example
$ onenote search 年金番号
# (20250303) nenkin bangou screenshot @mynaportal
Section: MyNumberCard-マイナンバカード | Notebook: sno@ja
基础**年金番号** ...
https://snomiao-my.sharepoint.com/.../Notebooks/sno@ja?wd=target(...)
2 page-level results found.Clicking the URL opens OneNote Online directly on the matching page.
How Search Works
onenote syncdownloads all.onesection files from OneDrive- Extracts page GUIDs from the MS-ONESTORE binary format
- Fetches official page URLs via OneNote Graph API (
/me/onenote/sections/0-{guid}/pages) - On search, scans the binary for matches (UTF-8 and UTF-16LE), attributes each match to the correct page via context-based anchor lookup
- Returns results with official OneNote URLs that navigate directly to the page
See docs/local-search-architecture.md for the full technical design.
API Permissions Required
| Permission | Type | Purpose |
|---|---|---|
| Notes.Read | Delegated | Read notebooks |
| Notes.ReadWrite | Delegated | Create/modify pages |
| Notes.ReadWrite.All | Delegated | Access all notebooks |
| Files.Read | Delegated | Download .one files from OneDrive |
| Files.Read.All | Delegated | Access all accessible files |
| Sites.Read.All | Delegated | Search via SharePoint listItem API |
File Structure
src/
index.ts CLI entry point (yargs)
auth.ts MSAL device code flow + .env.local auto-loader
graph.ts Microsoft Graph API client (OneNote + OneDrive)
cache.ts Local cache, .one binary parser, page GUID extraction
docs/
setup.md Azure AD registration walkthrough
local-search-architecture.md Technical design of local search
graph-api-endpoints.md OneNote Graph API reference
development-notes.md Lessons learned
onen0te-cli-analysis.md Competitor UX analysisConfiguration
| Source | Location | Priority |
|---|---|---|
| .env.local | Package root (auto-loaded) | Highest |
| ~/.onenote-cli/config.json | Home directory | Fallback |
| ONENOTE_CLIENT_ID env var | Shell environment | Overrides all |
Cache location: <package>/.onenote/cache/ (override with ONENOTE_CACHE_DIR)
License
MIT
