DOC-38Recommended
Put code samples under a licence that lets readers copy them
State the licence of the code samples in the docs apart from the licence of the prose. Pick one that asks nothing back, such as 0BSD or MIT-0, so readers can paste samples into closed code.
How to do it
Readers who cannot tell whether they may copy a sample either retype it or copy it without the right. A licence written for prose, such as CC BY, asks for credit on every copy and fits text better than code. 0BSD grants permission "to use, copy, modify, and/or distribute this software for any purpose". Name the licence in the docs footer and the docs repository. Use SPDX identifiers, as Mark every file with its licence and copyright holder says. Samples taken from another project keep their own licence, as Keep copied code under its own licence says. Keep samples runnable, as Make every example complete enough to copy and run asks.
Examples
TOML example
# REUSE.toml: samples under 0BSD, prose under CC-BY-4.0
version = 1
[[annotations]]
path = "docs/examples/**"
SPDX-FileCopyrightText = "2026 Example Bakery AB"
SPDX-License-Identifier = "0BSD"
[[annotations]]
path = "docs/**/*.md"
SPDX-FileCopyrightText = "2026 Example Bakery AB"
SPDX-License-Identifier = "CC-BY-4.0"
How to check
The docs footer names the samples' SPDX licence identifier. A licence check of the docs repository, such as reuse lint, finds a licence for every sample file.
Sources
Related rules
- OSS-3 Mark every file with its licence and copyright holder in Open source maintenance
- OSS-5 Keep copied code under its own licence in Open source maintenance
- DOC-21 Make every example complete enough to copy and run in Documentation
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/documentation/examples-that-run/sample-code-licence">Agent Wranglers documentation playbook</a>. In code you write, add a comment next to it with the same link.