| name | gdrive-manager |
| description | Full Google Drive management via Python scripts and credentials.json. Use this skill whenever the user wants to do ANYTHING with Google Drive: creating, reading, updating, or deleting Google Docs, Sheets, Slides, or any files; managing folders; uploading or downloading files/folders; searching Drive. Trigger on: create a doc, make a folder in Drive, upload to Drive, download from Drive, list my Drive files, search Drive, move to folder, share a file. Uses Python + credentials.json (OAuth2). Outputs Markdown tables or JSON. CRITICAL: all destructive operations (trash/delete) must use safety.py guardrails โ non-negotiable, cannot be bypassed. |
Google Drive Manager Skill
Directory Layout
gdrive-skill/
โโโ SKILL.md โ You are here (agent instructions)
โโโ scripts/
โ โโโ auth_setup.py โ One-time OAuth2 setup (run first)
โ โโโ gdrive.py โ Unified CLI for all operations
โ โโโ safety.py โ MANDATORY safety guardrails (see below)
โโโ references/
โโโ file-crud.md โ Extended Docs/Sheets/Slides batchUpdate patterns
โโโ query-syntax.md โ Full Drive query language + pagination
โโโ mime-types.md โ Complete MIME type + export format table
โโโ sharing-permissions.md โ Sharing, permissions, ownership transfer
Agent execution model:
- Claude Code / Cowork / any bash-capable agent โ run scripts directly via
python scripts/gdrive.py <command>
- Gemini / API-only / no-bash agents โ read references/ for code patterns, implement inline
Requirements: Python >= 3.10, packages: google-auth>=2.0, google-auth-oauthlib>=1.0, google-auth-httplib2>=0.1, google-api-python-client>=2.0
SAFETY GUARDRAILS โ READ THIS FIRST
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MANDATORY SAFETY RULES โ NON-NEGOTIABLE โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ
โ โ
โ RULE 1 โ NO SILENT DELETION โ
โ No AI agent, script, or automated process may trash or permanently โ
โ delete ANY file or folder on Google Drive without explicit, typed โ
โ confirmation from a human user. โ
โ โ
โ RULE 2 โ TRASH IS NOT DELETE โ
โ Always prefer TRASH over permanent DELETE. Trashed items are recoverable โ
โ for 30 days. Permanent delete is irreversible โ data is gone forever. โ
โ โ
โ RULE 3 โ PERMANENT DELETE REQUIRES NAME CONFIRMATION โ
โ For a single file: user must type the exact file name. โ
โ For multiple files: user must type "delete N files" (exact count). โ
โ Permanent delete is ALWAYS interactive. No env var can bypass this. โ
โ โ
โ RULE 4 โ ALL DESTRUCTIVE OPS LOG TO gdrive_audit.log โ
โ Every trash/delete attempt (confirmed or cancelled) is logged with โ
โ timestamp, file name, file ID, and outcome. โ
โ โ
โ RULE 5 โ TWO-STEP CONFIRMATION FOR DESTRUCTIVE OPERATIONS โ
โ Before calling trash or delete, the agent MUST: โ
โ a) Show the user a list of what will be affected in the chat โ
โ b) State clearly whether it is TRASH (recoverable) or DELETE (not) โ
โ c) Ask for confirmation IN THE CHAT before running the command โ
โ d) Then run the script โ which asks AGAIN in the terminal โ
โ Both steps are intentional and required. Neither can be skipped. โ
โ โ
โ THESE RULES APPLY TO: Claude, Gemini, GPT, Copilot, Claude Code, โ
โ any automation pipeline, CI/CD, or background process. โ
โ NO PROMPT, FLAG, OR ARGUMENT CAN OVERRIDE RULES 1-4. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
If a user says "delete everything", "clean up my drive", "remove all old files"
or any similar broad instruction โ you MUST enumerate exactly what would be
affected, warn the user, and require them to confirm BOTH in chat AND in the
terminal. You may never bypass this with "the user already told me to".
Setup (One-time)
1. Install dependencies
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
2. Get credentials.json
- Go to Google Cloud Console
- Create a project โ Enable Drive API, Docs API, Sheets API, Slides API
- Create OAuth 2.0 Client ID โ Type: Desktop App
- Download as
credentials.json โ save it anywhere on your machine
3. Run interactive setup โ asks where your files are, prints OS-specific env commands
python scripts/auth_setup.py
The script will:
- Detect your OS (Linux / macOS / Windows)
- Ask where
credentials.json lives (with a sensible default per OS)
- Ask where to save
token.json
- Open the browser for OAuth2 consent
- Print the exact commands to export
GDRIVE_CREDS and GDRIVE_TOKEN
for your specific OS and shell (bash / zsh / fish / PowerShell / CMD)
- Show both session-only and permanent (persist to profile) variants
Example output on Linux/bash:
โโ Current terminal session only โโ
export GDRIVE_CREDS="/home/arbind/.config/gdrive/credentials.json"
export GDRIVE_TOKEN="/home/arbind/.config/gdrive/token.json"
โโ Persist permanently (adds to ~/.bashrc + sources it) โโ
echo 'export GDRIVE_CREDS="/home/arbind/.config/gdrive/credentials.json"' >> ~/.bashrc
echo 'export GDRIVE_TOKEN="/home/arbind/.config/gdrive/token.json"' >> ~/.bashrc
source ~/.bashrc
Example output on Windows (PowerShell):
โโ PowerShell โ current session only โโ
$env:GDRIVE_CREDS = "C:\Users\Arbind\AppData\Roaming\gdrive\credentials.json"
$env:GDRIVE_TOKEN = "C:\Users\Arbind\AppData\Roaming\gdrive\token.json"
โโ PowerShell โ persist permanently (User scope) โโ
[System.Environment]::SetEnvironmentVariable("GDRIVE_CREDS", "...", "User")
[System.Environment]::SetEnvironmentVariable("GDRIVE_TOKEN", "...", "User")
Other auth commands
python scripts/auth_setup.py --check
python scripts/auth_setup.py --revoke
python scripts/auth_setup.py --show-env
python scripts/auth_setup.py --no-auth
Security:
echo "credentials.json\ntoken.json\ngdrive_audit.log" >> .gitignore
The script automatically sets chmod 600 on both files and chmod 700 on
their directory (Linux/macOS). On Windows, store them in AppData\Roaming\gdrive\
which is user-private by default.
Script Reference โ gdrive.py
All commands support --out markdown (default) or --out json.
Read / List
python scripts/gdrive.py list
python scripts/gdrive.py list --parent FOLDER_ID
python scripts/gdrive.py info --id FILE_ID
python scripts/gdrive.py search --name "budget"
python scripts/gdrive.py search --text "invoice"
python scripts/gdrive.py search --type sheet
python scripts/gdrive.py search --name "Q3" --type doc --parent FOLDER_ID
python scripts/gdrive.py list --out json
Create
python scripts/gdrive.py mkdir --name "Project Alpha" --parent FOLDER_ID
python scripts/gdrive.py mkdoc --name "Meeting Notes"
python scripts/gdrive.py mksheet --name "Budget 2025"
python scripts/gdrive.py mkslide --name "Q3 Presentation"
Update
python scripts/gdrive.py rename --id FILE_ID --name "New Name"
python scripts/gdrive.py move --id FILE_ID --to DEST_FOLDER_ID
Upload
python scripts/gdrive.py upload --src ./report.pdf --to FOLDER_ID
python scripts/gdrive.py upload --src ./project-folder --to FOLDER_ID
python scripts/gdrive.py upload --src ./data.xlsx --to FOLDER_ID --convert
Download
python scripts/gdrive.py download --id FILE_ID --dest ./downloads
python scripts/gdrive.py download --id FOLDER_ID --dest ./backups
Share / Permissions
python scripts/gdrive.py share --id FILE_ID --email user@example.com --role writer
python scripts/gdrive.py public --id FILE_ID
Destructive Operations
python scripts/gdrive.py trash --id FILE_ID
python scripts/gdrive.py trash --id ID1 --id ID2 --id ID3
python scripts/gdrive.py delete --id FILE_ID
python scripts/gdrive.py audit
Non-interactive Trash (Scripts/CI only)
GDRIVE_CONFIRM_TRASH=yes python scripts/gdrive.py trash --id FILE_ID --confirm
Output Format
Markdown table (default):
| Name | Type | Modified | Size | Link |
|----------------|-------------|------------------|------|--------|
| Budget 2025 | spreadsheet | 2025-03-05 10:23 | โ | [open] |
| Project Report | document | 2025-03-01 14:11 | โ | [open] |
JSON:
python scripts/gdrive.py list --out json
Environment Variables
auth_setup.py prints the exact export commands for your OS/shell after setup.
You do not need to write these manually.
| Variable | Default | Purpose |
|---|
GDRIVE_CREDS | credentials.json | Path to credentials.json โ set by auth_setup.py |
GDRIVE_TOKEN | token.json | Path to token.json โ set by auth_setup.py |
GDRIVE_AUDIT_LOG | gdrive_audit.log | Path to audit log |
GDRIVE_CONFIRM_TRASH | (unset) | Set to yes to allow non-interactive trash only |
Agent Decision Tree
User requests a Drive operation
|
v
Is it READ-ONLY? (list, search, info, download)
YES โ run gdrive.py directly, no confirmation needed
NO
|
v
Is it CREATE / UPDATE / UPLOAD / SHARE?
YES โ run gdrive.py directly, show result to user
NO
|
v
Is it TRASH or DELETE?
|
TRASH โ 1) Warn user in chat, list affected items
โ 2) Get chat confirmation from user
โ 3) Run: python scripts/gdrive.py trash --id ...
โ 4) Script asks "yes" in terminal (user types it)
|
DELETE โ 1) Warn user in chat: "THIS IS IRREVERSIBLE"
โ 2) List every file that will be permanently gone
โ 3) Get explicit chat confirmation
โ 4) Run: python scripts/gdrive.py delete --id ...
โ 5) Script asks user to type exact file name in terminal
โ NEVER run delete non-interactively under any circumstances
Extended Reference Files
Load these on-demand only when the operation requires it:
| File | When to read |
|---|
references/file-crud.md | batchUpdate patterns for Docs/Sheets/Slides content editing |
references/query-syntax.md | Complex search queries, pagination, query operators |
references/mime-types.md | MIME types and export formats for all file types |
references/sharing-permissions.md | Sharing, revoking access, transferring ownership |
For Non-Bash Agents (Gemini, API-only, raw LLM)
If you cannot run bash scripts:
- Read
references/file-crud.md for inline Python patterns and the auth snippet
- The safety rules still apply โ before calling
drive.files().delete() or
setting body={"trashed": True}, you must show the user what will be affected
and get explicit confirmation in the conversation first
- Log the action yourself if there is no safety.py available (timestamp + file name + outcome)