Blog
6 min read

How to Sort a Folder of Files by Client and Year with Claude Code

Founder and CEO, The Drive AI

TL;DR: Add The Drive AI to Claude Code with one command, ask it to sort a folder by client and year, and it reads each file, proposes the whole reorganization as one change with a preview, applies it, and can undo it in one step. Below is a real run on six invoices named scan_0412.pdf, Final FINAL v3.pdf and so on. Every output shown is what the tools returned.

Most folders that need sorting look like this: files named by whoever saved them, a mix of clients, two years of work in one place. Moving them one at a time through a drive's own API works, but you approve each move, you can't see the whole change before it happens, and there's no way to take it back as a unit.

This walkthrough does it the other way: one change, previewed, applied, and reversible. It uses Claude Code, but any MCP client works the same way, and there's a shell-only version at the end.

What is the folder we're sorting?

Six invoice PDFs in /Inbox, for three clients across 2025 and 2026. The names say nothing about what's inside:

doc_88231.pdf
Final FINAL v3.pdf
IMG_2290.pdf
invoice (2).pdf
receipt-copy.pdf
scan_0412.pdf

The goal is /Clients/<client>/<year>/, with each file renamed to its date, client and invoice number.

How do you connect The Drive AI to Claude Code?

One command:

claude mcp add --scope local --transport http thedriveai https://thedriveai.fastmcp.app/mcp

The first time Claude Code uses it, a browser opens and you sign in to The Drive AI with whatever your account uses (Google, Microsoft, Apple or email), then allow what Claude may do. Your Google Drive, OneDrive, SharePoint or Dropbox folders appear inside The Drive AI as folders, so the same steps work on them.

What do you ask it?

Sort everything in /Inbox into /Clients/<client>/<year>, and rename each file to
"<date> <client> invoice <number>.pdf". Show me the preview before you apply anything.

How does it know which client each file belongs to?

It reads them. The file names are no help, so Claude opens each one with fs_read. This is what came back for scan_0412.pdf:

--- /Inbox/scan_0412.pdf · 1 pages · 79 chars total ---
INVOICE 1041
Bill to: Acme Logistics
Date: 2026-03-14
Total due: USD 4,200.00

Scanned PDFs work too: The Drive AI reads the text layer, and runs OCR on scans when they're uploaded.

What does the preview show?

Claude doesn't move anything yet. It sends the whole reorganization to changeset_propose as one change, and gets back a preview. This is the preview from the run, with the folder list shortened and long lines wrapped:

Changeset — "Sort Inbox by client and year"
operations: 16 (create_folder 10, move 6;
            6 of the moves also rename on arrival)
risk: low — 16 non-destructive operation(s)
      within the auto-apply limit of 20
new folders: /Clients, /Clients/Acme Logistics, ...
samples:
  move /Inbox/scan_0412.pdf → /Clients/Acme Logistics/2026
       as "2026-03-14 Acme Logistics invoice 1041.pdf"
  move /Inbox/invoice (2).pdf → /Clients/Acme Logistics/2025
       as "2025-11-02 Acme Logistics invoice 1029.pdf"
  move /Inbox/Final FINAL v3.pdf → /Clients/Northwind Traders/2026
       as "2026-02-20 Northwind Traders invoice 1038.pdf"
  move /Inbox/doc_88231.pdf → /Clients/Northwind Traders/2025
       as "2025-08-09 Northwind Traders invoice 1017.pdf"
  move /Inbox/IMG_2290.pdf → /Clients/Globex Corporation/2026
       as "2026-04-01 Globex Corporation invoice 1044.pdf"
  move /Inbox/receipt-copy.pdf → /Clients/Globex Corporation/2025
       as "2025-09-30 Globex Corporation invoice 1022.pdf"

Three things to read in it:

  • The count. 16 operations: ten folders and six moves, each move also renaming the file. Nothing else is touched.
  • The risk. Low, because nothing is deleted and it's under 20 operations. Low-risk changes apply straight away; anything else waits for you.
  • The samples. Every move, with its destination and new name, before anything happens. If a name is wrong, say so and Claude proposes again.

What happens when you apply it?

Changeset: 16 applied, 0 failed.

The six files now sit here:

/Clients/Acme Logistics/2025/2025-11-02 Acme Logistics invoice 1029.pdf
/Clients/Acme Logistics/2026/2026-03-14 Acme Logistics invoice 1041.pdf
/Clients/Globex Corporation/2025/2025-09-30 Globex Corporation invoice 1022.pdf
/Clients/Globex Corporation/2026/2026-04-01 Globex Corporation invoice 1044.pdf
/Clients/Northwind Traders/2025/2025-08-09 Northwind Traders invoice 1017.pdf
/Clients/Northwind Traders/2026/2026-02-20 Northwind Traders invoice 1038.pdf

What if the change deletes something?

Then it stops and asks. Here is what came back when the empty /Inbox was sent to the trash in the same run:

risk: medium — 1 destructive operation(s) (trash) need confirmation
Needs the person's confirmation. Nothing has changed yet.

Claude shows you that preview in its own words and only applies it once you agree. The confirmation is tied to that exact change: agreeing to trash one folder isn't agreeing to trash another.

How do you undo it?

Ask Claude to undo the sort. It calls changeset_undo, which proposes the reverse as a change of its own, and applies it:

Undo changeset: 16 operations (move 6, trash 10), risk low.
Changeset: 16 applied, 0 failed.

All six files went back to /Inbox under their original names, and the ten empty folders went to the trash. One request, not sixteen.

Can you do this without Claude Code?

Yes, from any shell, with nothing to install:

npx @thedriveai/cli login          # prints a code to approve at thedrive.ai/oauth/mcp/device
npx @thedriveai/cli ls /Inbox
npx @thedriveai/cli cat /Inbox/scan_0412.pdf
npx @thedriveai/cli propose "Sort Inbox by client and year" '<ops as JSON>'
npx @thedriveai/cli undo <changeset>

The CLI makes the same calls. A change that needs your confirmation stops and prints the preview unless you pass --yes. The run above used it.

An agent working for someone without an account can run npx @thedriveai/cli signup instead. It gets a sandbox workspace and a claim link. The person opens the link, sees the files the agent made, and claims them into their own workspace.

Frequently Asked Questions

Does this work on my Google Drive, not just The Drive AI?

Yes. Connect Google Drive, OneDrive, SharePoint or Dropbox in The Drive AI and those folders appear in the same tree. The same preview, apply and undo steps work on them, including shared drives.

Can Claude Code move files without asking me?

Only low-risk changes: ones that delete nothing and stay under 20 operations. Anything that trashes files, or a larger change, waits for your confirmation, tied to that exact preview.

What if the agent gets a file wrong?

Read the preview before it applies. If a destination or a name is wrong, tell Claude and it proposes again. If you only notice afterwards, undo the whole change in one step.

Does it read the contents of my files?

Only when it needs to, as in this run where the file names said nothing. File contents are treated as data, never as instructions to the agent.

Which other MCP clients work?

Any client that supports remote MCP servers: Claude.ai and Claude Desktop, ChatGPT, Cursor, Codex, Gemini CLI and VS Code. Setup for each is on the MCP page. For how The Drive AI compares with other file MCP servers, see the best MCP servers for Google Drive, OneDrive and Dropbox. For what Claude can do in Drive on its own, see Can Claude organize your Google Drive?.

Share it with your network

You might also find useful