Set up the PyTorch Docstring skill

The PyTorch docstring skill helps Claude Code document functions and methods cleanly in the project’s Sphinx style and conventions.

Published on 09.09.2026

What the docstring skill is and why it matters

The skill named docstring lives directly inside the official PyTorch repository at .claude/skills/docstring/SKILL.md and is automatically picked up by Anthropic Claude Code whenever someone works inside the PyTorch source tree. A Claude Code skill is essentially a markdown file with focused instructions that Claude loads for a specific kind of task, so the same conventions do not need to be re-explained in every request. In this case the skill focuses on writing and updating docstrings, the in-code documentation blocks attached to functions and methods that help other PyTorch developers understand an API without reading the implementation. According to the source files torch/_tensor_docs.py and torch/nn/functional.py referenced in the skill, it follows the internal style PyTorch has maintained for years, which keeps generated text consistent with the rest of the documented codebase. It is worth noting for readers unfamiliar with the ecosystem that PyTorch is one of the most widely used machine learning frameworks, and consistent docstrings there directly affect both code readability and the automatically generated documentation website.

Prerequisites

Using the skill requires a working Claude Code installation and access to the PyTorch source, either through a local clone of the pytorch/pytorch repository or through a separate project that wants to adopt the same documentation conventions. Because the skill file is plain text with no executable dependencies, no additional packages, API keys, or permissions are needed. Anyone who wants to reuse the conventions in a project outside PyTorch itself should have a basic understanding of Sphinx and reStructuredText, since that markup format is the foundation of every rule in the skill.

Setting it up step by step

Anyone working directly inside the official PyTorch repository does not need to do anything extra: Claude Code automatically reads skills from the .claude/skills directory and activates the matching one whenever a task involves writing or editing a docstring. To reuse the conventions in a separate project, such as a PyTorch extension or a closely related library, copy the SKILL.md file from the PyTorch repository into your own .claude/skills/docstring folder and adjust the name and description in the header if needed so Claude can match it correctly. Claude Code then picks up the skill on its next start; restarting the tool is usually enough.

Security and best practices

Because the skill only defines formatting and style rules for text documentation and never executes code, makes network calls, or touches credentials, the risk profile of using it is very low. Even so, it is worth manually reviewing generated docstrings, especially where mathematical formulas or cross-references to other classes and functions are involved, because broken Sphinx directives typically only surface once the documentation is actually built, resulting in broken links or misrendered formulas. Anyone adapting the skill for a separate project should also make sure the adopted conventions genuinely fit that project's own documentation tooling, since copying them without adjustment can produce inconsistent results if the target project does not use Sphinx.

Practical example and limitations

A typical example is documenting a new convolution function: the skill guides Claude to start with the full function signature including parameters and return type, follow it with a short description, then list parameters under an Args section with type annotations and default values, and reference related classes such as torch.nn.Conv2d where useful. The clear limitation of the skill is that it was built specifically for PyTorch's reStructuredText style and cannot be transferred unchanged to other common docstring formats such as the Google style or the NumPy style. Anyone working outside the PyTorch ecosystem should therefore treat the rules as a template that needs adaptation to local conventions rather than something to adopt verbatim.

Published on 09.09.2026

Categories

Frequently asked questions

Does the skill replace tests?

No. It structures docstrings, while examples and claims still need checking against code, tests, and the documentation build.

Which documentation format does it target?

The source follows Sphinx and reStructuredText together with PyTorch API documentation conventions.