beta.skills.create: undocumented requirement that files path prefix must match SKILL.md name: field
Summary
beta.skills.create() requires that every file path in the files parameter is prefixed with a top-level directory whose name exactly matches the name: field in SKILL.md. This requirement is not mentioned in the SDK docstring, the README, or any error message until after the first failed attempt. The error messages themselves require multiple iterations to decode.
Reproduction
import anthropic
client = anthropic.Anthropic()
SKILL_MD = b"""---
name: my-skill
description: Example skill.
---
Skill content here.
"""
# Fails with 400: "SKILL.md file must be exactly in the top-level folder."
client.beta.skills.create(
display_title="my-skill",
files=[("SKILL.md", SKILL_MD, "text/markdown")],
)
Second attempt after reading the error:
# Fails with 400: "The folder name 'skills' must match the skill name 'my-skill' in SKILL.md."
client.beta.skills.create(
display_title="my-skill",
files=[("skills/SKILL.md", SKILL_MD, "text/markdown")],
)
Expected behaviour
Either the API accepts "SKILL.md" as a valid top-level path, or the error on first failure clearly states the required format (e.g. "Path must be '<name>/SKILL.md' where <name> matches the name: field in SKILL.md").
What works
# OK — directory name matches name: field in frontmatter exactly
client.beta.skills.create(
display_title="my-skill",
files=[("my-skill/SKILL.md", SKILL_MD, "text/markdown")],
)
Suggested fix
Either:
-
Document the requirement in the
create()docstring and/or README — a single sentence: "The path of each file must be prefixed with a directory whose name matches thename:field inSKILL.md." -
Handle it in the SDK — parse the
name:field from the suppliedSKILL.mdbytes and automatically rewrite bare filenames to{name}/filenamebefore sending, removing the need for callers to know about this layout constraint.
Environment
anthropicSDK: 0.99.0- Python: 3.14
Confirming the repro on anthropic==0.97.0. The asymmetry is the part that stuck out to me.
_archive_top_dir in src/anthropic/lib/tools/_skills.py already encodes the "single wrapper directory named after the skill" convention on the download side — it strips that wrapper when unpacking so files land flat in dest. The upload side has the same convention but the caller has to construct it. The SDK already knows the canonical layout in one direction.
The cleanest fix is on beta.skills.create: parse name: from the supplied SKILL.md (or fall back to a normalized display_title) and prefix any file path that isn't already under <name>/. That matches the download behaviour symmetrically and avoids a docs-only patch that future readers will still trip on.
Happy to send a PR in that shape if there's interest. Otherwise a single line in the docstring — "the path of each file must be prefixed with a directory whose name matches the name: field in SKILL.md" — would at least stop the silent first-attempt failure.
Confirming @Zawwarsami16's read. The download/upload asymmetry is the part that should drive the fix — _archive_top_dir already canonicalizes the wrapper-directory layout on extract, so requiring callers to reconstruct it on create is the inconsistency. I hit this building a public skills repo (nordeval-skills) and only figured out the <name>/ prefix requirement by trial-and-error across two failed attempts. A docstring line would help; SDK-side normalization (option 2) would mean future callers don't trip on it at all.
Thanks for confirming, @avalyset — the two-failed-attempts cost on nordeval-skills is exactly the friction a docs-only patch wouldn't fix.
To restate the SDK-side shape concretely so it's easy to evaluate: parse name: from the supplied SKILL.md bytes (the same parse the API already does server-side), and rewrite any file path that isn't already under <name>/ to that prefix before sending. That makes the upload path symmetric with _archive_top_dir on the download side and turns the silent first-attempt failure into a non-event. Adds maybe 15 lines in src/anthropic/lib/tools/_skills.py plus a unit test.
PR offer still stands. Happy to send it in either shape (docstring-only or full normalization) if anyone on the SDK side wants to flag a preference — otherwise I'll wait for a maintainer signal before opening one.
Hi, I'd like to work on this. I'll submit a PR shortly.
@avalyset sorry for the long delay here, and thanks for documenting the failure sequence so precisely. You're right that the top-level directory in each file path has to match the name: in SKILL.md and that neither the docs nor the error messages say so up front. The validation and its messages live on the API side and the docstring is generated from the API spec; we'll take it under consideration internally, but I'm closing it here since it isn't actionable in this repo.