Skip to main content
skill CX Codex

microsoft-onedrive — Claude Code skill: OneDrive files via Graph

microsoft-onedrive is a Claude Code skill for listing, searching, downloading, and uploading OneDrive and SharePoint files through Microsoft Graph.

Apache-2.0 219 installs ★ 17 updated 2026-10-25

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add AceDataCloud/Skills --skill microsoft-onedrive -a claude-code
Open on GitHub

What microsoft-onedrive does

Inside are ready-made Graph calls for everyday drive work: root and subfolder listings, recursive search, recently modified items, files shared with you, download by id or by path, upload, folder creation, rename and move, delete, share links, and a SharePoint site listing.

The skill only uses Bash. Every request carries the bearer token from $MICROSOFT_ONEDRIVE_TOKEN, and the scopes were agreed at install time: Files.Read, Files.Read.All, Sites.Read.All, plus Files.ReadWrite.All when the user granted write access. It opens with /me so the account and drive are known before anything else happens. Graph errors arrive as JSON and the skill asks for them to be shown to the user unchanged.

Anything over 4 MB has to go through an upload session in 10 MiB chunks, a plain PUT will not do. Delete and share-link calls wait for the user's confirmation, since a link exposes the file outside the drive. An expired token shows up as 401 InvalidAuthenticationToken, and reinstalling the connector is the fix.

What it helps with

  • Locate a document somewhere in a SharePoint library
  • Fetch a file by path into the local project folder
  • Push a generated report into Documents
  • Create a view link for one file and send it on
  • Check which files changed recently across the drive

Example prompts for the agent

  • List the root of my OneDrive and show what changed this week
  • Find quarterly report.pdf in OneDrive and download it to tmp/
  • Upload report.pdf to Documents and make an organization view link

How to install microsoft-onedrive

1Skills CLI (Vercel)

npx skills add AceDataCloud/Skills --skill microsoft-onedrive -a claude-code

2Manually: put the files in place

~/.claude/skills/microsoft-onedrive/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/microsoft-onedrive/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about microsoft-onedrive

How do I install microsoft-onedrive in Claude Code?

Run npx skills add AceDataCloud/Skills --skill microsoft-onedrive -a claude-code, then confirm the skill file is at ~/.claude/skills/microsoft-onedrive/SKILL.md.

What does microsoft-onedrive do?

It gives the agent Graph request recipes for OneDrive and SharePoint files: listings, search, downloads and uploads, renaming, moving, deleting, and share links, all through curl and jq.

What does the skill need in order to run?

A valid bearer token in $MICROSOFT_ONEDRIVE_TOKEN. Writing requires Files.ReadWrite.All in that token, and SharePoint site access requires Sites.Read.All. A 401 InvalidAuthenticationToken response means the token expired and the connector has to be reinstalled.

Source text

SKILL.md · Apache-2.0
---
name: microsoft-onedrive
description: Read and manage OneDrive / SharePoint files via Microsoft Graph. Use when the user mentions OneDrive files / folders, SharePoint documents, file uploads / downloads, sharing links, or "my drive".
when_to_use: |
  Trigger when the user wants to read, list, search, upload, download,
  rename, move, share or delete files in OneDrive (personal or
  Microsoft 365 work / school) or SharePoint document libraries.
connections: [microsoft/onedrive]
allowed_tools: [Bash]
license: Apache-2.0
metadata:
  author: acedatacloud
  version: "1.0"
---

Drive Microsoft Graph for OneDrive / SharePoint via `curl + jq`. The
user's OAuth bearer token is in `$MICROSOFT_ONEDRIVE_TOKEN`; every call
needs it as `Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN`. The token
already carries the OneDrive scopes the user agreed to at install time
(`Files.Read`, `Files.Read.All`, optionally `Files.ReadWrite.All`,
`Sites.Read.All`).

The Graph API returns standard JSON; failures surface as JSON
`{"error": {"code": "...", "message": "..."}}` — show that error
verbatim to the user.

**Always start with `/me`** to confirm the connection works AND learn
which account / drive you're operating against.

## Recipes

### Verify auth (always run first)

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  https://graph.microsoft.com/v1.0/me \
  | jq '{displayName, mail, userPrincipalName}'
```

If you get `401 InvalidAuthenticationToken`, the token expired —
report it; the user has to reinstall the connector.

### List files in root

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/root/children?\$top=20&\$select=id,name,size,lastModifiedDateTime,folder,file" \
  | jq '.value[] | {id, name, size, kind: (if .folder then "folder" else .file.mimeType end), modified: .lastModifiedDateTime}'
```

Folders have `"folder":{"childCount":N}`, files have `"file":{"mimeType":"..."}`.

### List files in a sub-folder by path

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/root:/Documents:/children?\$top=20&\$select=id,name,size,lastModifiedDateTime"
```

Path uses `:` as the path/segment separator — `:/Documents/Q1:/children`.

### Search files (recursive)

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  --data-urlencode "q=quarterly report" --get \
  "https://graph.microsoft.com/v1.0/me/drive/root/search(q='quarterly report')?\$top=25&\$select=id,name,size,webUrl,lastModifiedDateTime"
```

> `search(q='')` with empty query returns 400. To find files by type
> without a keyword, search by extension: `search(q='.pdf')`.

### Recently modified files (cross-folder)

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/recent?\$top=25" \
  | jq '.value[] | {name, modified: .lastModifiedDateTime, parent: .parentReference.path}'
```

### Files shared with me

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/sharedWithMe?\$top=25" \
  | jq '.value[] | {name, size: .size, owner: .remoteItem.shared.owner.user.displayName}'
```

### Download a file by item id

```sh
# /content returns 302 to a pre-signed URL — let curl follow it.
curl -sSL -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/items/${ITEM_ID}/content" \
  -o "$SKILL_DIR/tmp/$(basename "$NAME")"
```

### Download a file by path

```sh
# URL-encode each path segment with jq -Rr @uri (or use printf encoding).
ENCODED=$(printf '%s' "Documents/report.docx" | jq -sRr @uri)
curl -sSL -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/root:/${ENCODED}:/content" \
  -o report.docx
```

### Upload a small file (< 4 MB)

```sh
curl -sS -X PUT \
  -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @/tmp/report.pdf \
  "https://graph.microsoft.com/v1.0/me/drive/root:/Documents/report.pdf:/content"
```

For files **> 4 MB** use an upload session (chunked):

```sh
# 1) create session
SESSION=$(curl -sS -X POST \
  -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"item":{"@microsoft.graph.conflictBehavior":"rename"}}' \
  "https://graph.microsoft.com/v1.0/me/drive/root:/Documents/big.zip:/createUploadSession")
UPLOAD_URL=$(echo "$SESSION" | jq -r .uploadUrl)
# 2) PUT in 10 MiB chunks with Content-Range: bytes <start>-<end>/<total>
# (See Microsoft Graph docs for the chunking loop; jq + dd makes this trivial.)
```

### Create a folder

```sh
curl -sS -X POST \
  -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Reports","folder":{},"@microsoft.graph.conflictBehavior":"rename"}' \
  https://graph.microsoft.com/v1.0/me/drive/root/children
```

`@microsoft.graph.conflictBehavior`: `rename` (auto-suffix), `replace`
(overwrite), `fail` (error if exists). Default is `fail`.

### Rename / move (PATCH)

**⚠️ Always show the source and destination before executing.**

```sh
# Rename only
curl -sS -X PATCH \
  -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"renamed.docx"}' \
  "https://graph.microsoft.com/v1.0/me/drive/items/${ITEM_ID}"

# Move to a different folder
curl -sS -X PATCH \
  -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$(jq -nc --arg pid "$NEW_PARENT_ID" '{parentReference:{id:$pid}}')" \
  "https://graph.microsoft.com/v1.0/me/drive/items/${ITEM_ID}"
```

### Delete

**⚠️ Always fetch the item name first and confirm with the user.**

```sh
# 1) Show what will be deleted
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/items/${ITEM_ID}?\$select=name,size,lastModifiedDateTime" \
  | jq '"Delete \(.name) (\(.size) bytes, modified \(.lastModifiedDateTime))?"'

# 2) After user confirms (returns 204 No Content)
curl -sS -X DELETE -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/me/drive/items/${ITEM_ID}" \
  -w "HTTP %{http_code}\n"
```

### Create a sharing link

**⚠️ Confirm with the user before sharing — this exposes data externally.**

```sh
curl -sS -X POST \
  -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type":"view","scope":"organization"}' \
  "https://graph.microsoft.com/v1.0/me/drive/items/${ITEM_ID}/createLink" \
  | jq '.link.webUrl'
```

`type`: `view` | `edit` | `embed`. `scope`: `anonymous` | `organization` | `users`.

### List SharePoint sites

Requires `Sites.Read.All`.

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/sites?search=*&\$top=10" \
  | jq '.value[] | {id, name: .displayName, webUrl}'
```

Files inside a site:

```sh
curl -sS -H "Authorization: Bearer $MICROSOFT_ONEDRIVE_TOKEN" \
  "https://graph.microsoft.com/v1.0/sites/${SITE_ID}/drive/root/children?\$top=20"
```

## OData quick reference

| Param | Example |
|---|---|
| `$select` | `id,name,size,lastModifiedDateTime` |
| `$filter` | `name eq 'report.docx'`, `size gt 1000000` |
| `$orderby` | `lastModifiedDateTime desc` |
| `$top` | `10` browsing, `25` search |
| `$expand` | `children`, `permissions` |

Use `--data-urlencode "$key=$value" --get` with curl to avoid shell-quoting `$` and spaces.

## Rules

- **Always pass `$select`** — defaults return 30+ fields per item.
- **`$top=10`** for browse, `25` for search. Don't paginate past 50 unless asked.
- **URL-encode IDs** if using them in a path — IDs can contain `+`, `/`, `=`. Use `jq -sRr @uri`.
- **Empty `search(q='')` returns 400** — search by extension if you don't have a keyword.

## CRITICAL: User consent for destructive actions

**Never** delete, overwrite or share without explicit confirmation. Pattern: **prepare → present → execute**.

| Action | What to show user |
|---|---|
| Delete | "Delete '{name}' ({size} bytes, modified {date})?" |
| Overwrite (`@microsoft.graph.conflictBehavior=replace`) | "Overwrite '{name}'? Existing: {size}, modified {date}" |
| Share (`createLink`) | "Create {type} link for '{name}' with {scope} access?" |
| Move | "Move '{name}' from {old folder} to {new folder}?" |
| Bulk | Count + sample: "Delete 12 files in /Reports/?" |

## Errors

- `401 InvalidAuthenticationToken` → token expired; user must reinstall the connector.
- `403 accessDenied` → scope missing (e.g. trying to write with read-only token); ask user to reinstall and tick the write scope.
- `429 TooManyRequests` → respect the `Retry-After` header (in seconds).
- `404 itemNotFound` → wrong id or path; double-check casing.

## Reference

For deep dives consult Microsoft's docs:
- Drive items: <https://learn.microsoft.com/en-us/graph/api/resources/driveitem>
- Upload large files: <https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession>
- Sharing: <https://learn.microsoft.com/en-us/graph/api/driveitem-createlink>

© acedatacloud · Apache-2.0 · AceDataCloud/Skills

Similar skills

All skills for Office documents →

From the same set67

The whole set →

More in the catalog

Project sponsors

Companies that keep this analytics open