/gws:gmail-draft-from-markdown [file.md] [recipient-email-or-name] [--subject "Subject"] [--cc EMAIL] [--bcc EMAIL] [--from EMAIL] [--reply-to MESSAGE_ID] [--thread THREAD_ID] [--attach PATH]from gws
Converts a local markdown file to HTML and creates a Gmail draft via gws. Supports attachments, CC/BCC, threading replies, and returns a drafts URL for review.
Ships in gws. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Take a local markdown file, convert it to HTML, and save it as a Gmail draft (never sent). Returns a clickable Gmail drafts URL so the user can review and send from the Gmail UI.
Default is --draft, always. Thoughtful emails (coaching follow-ups, client
notes, anything personal) need human review before they go out. This skill
will never send an email directly.
# Codex: this path resolves under Claude Code; substitute the directory containing this plugin.
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT}"
bash "$PLUGIN_ROOT/scripts/auth-preflight.sh"
Also requires a markdown→HTML converter. The script prefers
marked (npm i -g marked) and
falls back to pandoc. It errors with a clear message if neither is
installed.
Run the entrypoint script, passing all arguments through:
# Codex: this path resolves under Claude Code; substitute the directory containing this SKILL.md.
SKILL_DIR="${CLAUDE_SKILL_DIR}"
bash "$SKILL_DIR/scripts/draft.sh" $ARGUMENTS
If no arguments were provided, ask the user for the markdown file path and
recipient (email or name). Subject is optional — the script derives it from a
Subject: ... line at the top of the markdown if present.
| Arg | Required | Notes |
|---|---|---|
<markdown-file> | yes | Path to a local .md file. |
<recipient> | yes | Email address, or a name to look up via Gmail search. |
--subject "..." | no | Overrides the Subject: line in the markdown. |
--cc EMAIL | no | Comma-separated. |
--bcc EMAIL | no | Comma-separated. |
--from EMAIL | no | Send-as alias (defaults to active account). |
--reply-to MESSAGE_ID | no | Thread the draft onto that message's conversation (see Threading). |
--thread THREAD_ID | no | Attach the draft to a threadId directly, no header lookup. Prefer --reply-to. |
--attach PATH | no | Attach a local file. Repeatable; composes with every other flag. |
@, it's used verbatim.gws gmail users messages list) and extracts the email from the
From: header (gws gmail +read --id ... --headers).By default the script creates a standalone draft. To attach the draft to an existing Gmail conversation so it shows up as a reply in that thread:
--reply-to MESSAGE_ID — the script looks up that message via
gws gmail users messages get (format metadata) and reads its threadId,
Message-ID, and References. It then:
message.threadId on the draft resource, andIn-Reply-To (the parent's Message-ID) and References (the
parent's References chain plus its Message-ID) into the MIME message.
Gmail needs those RFC 5322 headers — not just threadId — to thread the
reply reliably. If no --subject is given, the parent's subject is reused;
in reply mode a conventional Re: prefix is added when missing.--thread THREAD_ID — attaches to a threadId directly with no header lookup.
Weaker than --reply-to (no In-Reply-To/References), so prefer
--reply-to when you have the parent message id.The MESSAGE_ID for --reply-to is a Gmail message id (as returned by
gws gmail users messages list or the gws:gmail-read skill), not the raw
RFC Message-ID header value.
--attach PATH attaches a local file, and it is repeatable. Attachments
compose with everything else — --reply-to, --cc, --bcc, --from, subject
resolution — so a threaded reply carrying three PDFs is one invocation. Each
file becomes its own multipart/mixed part named by its basename, alongside
the HTML body.
Guardrails:
application/octet-stream.A small draft is passed inline as a base64 raw field. A large one is written
to a temp .eml and uploaded as message/rfc822 media instead. The script
picks the route by encoded size and reports the switch on stderr; there is no
flag for it.
The reason it is size and not "did you pass --attach" is that the limit being
dodged belongs to argv, and a long enough HTML body reaches it with nothing
attached at all. Two kernel limits bind, whichever comes first:
| Limit | Value | Notes |
|---|---|---|
| total argv + env | 1,048,576 on macOS | getconf ARG_MAX; 620KB of PDFs encodes to a 1,118,017-byte argument, and a 314KB markdown note to 445,533 |
| a single argument | 131,072 on Linux | MAX_ARG_STRLEN, 32 pages, regardless of ARG_MAX — this is the one that binds there, at roughly 96KB of message |
The threshold therefore sits well under the smaller of the two. Over it, the kernel refuses the call outright with "argument list too long" — which reads like anything but a size problem.
GMAIL_DRAFT_MAX_JSON_BYTES overrides the threshold, and 0 forces the upload
route. It exists for testing; normal use leaves it unset.
--subject "..." flagSubject: ... line at the top of the markdown (before the body)--reply-to is usedIn reply mode (--reply-to), the resolved subject is prefixed with Re:
unless it already starts with one.
The Subject: line is stripped from the body before conversion.
Before HTML conversion, the script strips:
--- … ---)Subject: ... header line> [!note] etc.)The script reads the draft back before it claims anything, and fails loudly rather than reporting a draft it cannot confirm:
DRAFT label. This is the check that keeps
"created a draft" from ever meaning "sent an email" — never report a draft
as sent, and never report one at all without this line in the output.--attach.The read-back uses format=full; format=metadata omits the MIME part tree
entirely, so filenames are invisible to it.
On success, prints the verification line, the draft id, and the account the draft landed in (all stderr), plus one URL line to stdout, addressed to that account explicitly:
Verified: DRAFT label present; attachments: agenda.pdf, proposal.pdf
Draft id: r-5387874580155353993
Draft created in account: [email protected]
https://mail.google.com/mail/[email protected]#drafts/<message-id>
The draft id is what gws gmail users drafts get|delete take; the id in the
URL is the message id. They are different values.
Open that URL in a browser to review and send the draft. The draft is created
in the active gws account (see the gws:account skill) — the authuser=
URL means the link opens the right mailbox even when multiple Google accounts
are signed in. Always relay the account email to the user along with the URL.
# Codex: this path resolves under Claude Code; substitute the directory containing this SKILL.md.
SKILL_DIR="${CLAUDE_SKILL_DIR}"
# Email address known
bash "$SKILL_DIR/scripts/draft.sh" ./coaching-followup.md [email protected] --subject "Session recap"
# Look up recipient by name (most recent correspondent wins)
bash "$SKILL_DIR/scripts/draft.sh" ./coaching-followup.md "Alice Smith"
# Subject embedded in markdown as a leading "Subject: ..." line
bash "$SKILL_DIR/scripts/draft.sh" ./note.md [email protected]
# Reply draft — thread onto an existing conversation (subject/threading auto-derived)
bash "$SKILL_DIR/scripts/draft.sh" ./reply.md [email protected] --reply-to 19f3de2c4f9ee065
# Attachments — repeatable, and composing with a threaded reply and BCCs
bash "$SKILL_DIR/scripts/draft.sh" ./reply.md [email protected] \
--reply-to 19f3de2c4f9ee065 \
--bcc "[email protected],[email protected]" \
--attach ~/Documents/proposal.pdf \
--attach ~/Documents/site-plan.pdf
For scripted or unattended use, pin the account explicitly instead of relying
on whichever account is active — GOOGLE_WORKSPACE_CLI_CONFIG_DIR is the one
knob that decides which mailbox the draft lands in:
# Codex: this path resolves under Claude Code; substitute the directory containing this SKILL.md.
SKILL_DIR="${CLAUDE_SKILL_DIR}"
# Personal account
GOOGLE_WORKSPACE_CLI_CONFIG_DIR=~/.config/gws \
bash "$SKILL_DIR/scripts/draft.sh" ./note.md [email protected]
# Work account
GOOGLE_WORKSPACE_CLI_CONFIG_DIR=~/.config/gws-accounts/work \
bash "$SKILL_DIR/scripts/draft.sh" ./note.md [email protected]
Set it on every command in the sequence, including the verification and
cleanup calls — a bare gws runs against the default account, so a draft
created in one mailbox and verified in another looks like a silent failure.
Use the gws:account skill to list the config dirs available on this machine.
For anything this skill does not cover — labels, sending, batch operations,
attachment downloads — you will be driving gws gmail users ... directly.
Four rules, each of which has already cost a session:
Run --help on the subcommand before the first call. Not gws --help,
the subcommand itself: gws gmail users drafts create --help. It lists the
exact option set, which is short and non-obvious. Guessing flags produces 400s
that read like auth or permission problems.
Every path, query, and URL parameter goes inside --params '<JSON>'.
There is no --userId, no --q, no --max-results, and no per-parameter flag
of any kind. Request bodies go in --json '<JSON>'; everything else is
--params.
# Right
gws gmail users messages list --params '{"userId":"me","q":"has:attachment","maxResults":5}'
# Wrong — these flags do not exist
gws gmail users messages list --userId me --q "has:attachment" --max-results 5
gws writes Using keyring backend: keyring to stderr on most calls.
Capture with 2>&1 and that line lands in front of the JSON, so every parse
downstream fails on a file that looks fine at a glance. Either keep the streams
separate (gws ... 2>/dev/null > out.json) or slice from the first { before
parsing. Save the raw response to a file first and parse the file — a direct
pipe into jq hides what actually came back.
--upload only accepts a path inside the current directory. An absolute
path elsewhere is refused with "resolves to ... which is outside the current
directory", so cd to the file's directory and pass the bare filename. On
macOS also resolve that directory with pwd -P: $TMPDIR sits under the
/var → /private/var symlink, and the logical path reads as outside itself.
# Parent message lookup for threading headers
gws gmail users messages get --params '{"userId":"me","id":"<MSG_ID>","format":"metadata","metadataHeaders":["Message-ID","References","Subject"]}'
# Create a draft from a prebuilt .eml, threaded, with attachments
# (run from the .eml's own directory)
gws gmail users drafts create --params '{"userId":"me"}' \
--json '{"message":{"threadId":"<THREAD_ID>"}}' \
--upload draft.eml --upload-content-type message/rfc822
# Read a draft back: DRAFT label + attachment filenames.
# format=full is required — format=metadata omits the MIME part tree.
gws gmail users drafts get --params '{"userId":"me","id":"<DRAFT_ID>","format":"full"}'
# Delete a draft (takes the DRAFT id, not the message id)
gws gmail users drafts delete --params '{"userId":"me","id":"<DRAFT_ID>"}'
Build the RFC 5322 message with python's stdlib email.message.EmailMessage:
set_content(html, subtype="html") for the body, add_attachment(data, maintype=…, subtype=…, filename=…) per file, In-Reply-To = the parent's
Message-ID, and References = the parent's References chain plus its
Message-ID. This skill's own builder already does exactly that and is
callable on its own:
Codex: this path resolves under Claude Code; substitute the directory containing this SKILL.md.
SKILL_DIR="${CLAUDE_SKILL_DIR}"
[email protected] SUBJECT="Re: Proposal" HTML_FILE=body.html \
OUT_EML=draft.eml THREAD_ID='<THREAD_ID>' \
IN_REPLY_TO='<[email protected]>' \
REFERENCES='<[email protected]> <[email protected]>' \
python3 "$SKILL_DIR/scripts/build-message.py" proposal.pdf site-plan.pdf
OUT_EML is where it may write the .eml — it does so only when the message
is too large to pass inline, and prints the draft metadata JSON in that case.
Otherwise it leaves that path alone and prints the whole
{"message":{"raw":…}} body for drafts create --json, so whether the file
exists afterward is the routing answer. MAX_JSON_BYTES=0 forces the upload
side.
gws auth login.gws auth status to confirm which account is
active. The active account is resolved via the gws account helpers (see
the gws:account skill).No markdown→HTML converter found: Install one — npm i -g marked or
brew install pandoc.Attachment not found / not readable: The path is checked before any
API call — fix the path; ~ is expanded by the shell, not by the script, so
quote carefully.Attachments exceed Gmail's 25MB limit: Link the files from Drive
instead (see the gws:md-to-google-doc skill) or send fewer per draft.resolves to ... which is outside the current directory: A --upload
path restriction, not a permissions problem. See Raw gws CLI survival
notes above.draft ... does not carry the DRAFT label: Stop and report it. Do not
retry and do not describe the message as sent — something created a message
that is not a draft, and that needs eyes on it.gws gmail users drafts delete before retrying, so a half-formed draft
is not left in the mailbox.authuser=-addressed URL for exactly this reason.
Bare gws verification commands run against the default account unless
GOOGLE_WORKSPACE_CLI_CONFIG_DIR is set to the active account's config.The gws CLI is powerful but the markdown → HTML → draft → drafts-URL
workflow takes 6+ tool calls to discover. This skill collapses it to one
invocation and codifies the draft, don't send default.
Attachments and threading are here for the same reason: composing a
multipart/mixed RFC 5322 message, uploading it as message/rfc822 from the
one directory --upload accepts, and reading the result back to prove it is a
draft is a long chain to rediscover, and each link has a failure mode that
looks like something else.
What SKILL.md sets; muted values are Claude Code's defaults
Triggers on 'draft an email from this file/note', 'gmail draft from markdown', 'create a draft in Gmail', 'draft a follow-up email', 'turn this note into an email draft', 'draft a reply with these files attached', 'attach these PDFs to a Gmail draft'.
Other plugins' skills for the same job
npx claudepluginhub jtsternberg/claude-plugins --plugin gws7 skills in this plugin
/gws-accountCheck, add, list, or switch the active Google account. The only way to manage gws accounts — the CLI has no `account` subcommand./gws-calendarGoogle Calendar via the gws CLI — 'what's on my calendar', today's meetings, schedule, find an event, pull its Meet/Zoom link, create events, list calendars./gmail-readSearch and read Gmail via gws — 'find the email about X', 'search my inbox for', read a message's full body as plain text./google-doc-to-mdDownload a Google Doc (tabs supported) as local markdown, via gws CLI, gcloud ADC, or the Drive connector./md-to-google-docUpload or sync local markdown to Google Drive as a Google Doc, via gws CLI, gcloud ADC, or the Drive connector./gws-youtubeManage the user's own YouTube playlists via gws — list, add/remove videos, dedupe, merge, find duplicates, cleanup workflows. Use instead of raw YouTube Data API calls.