1 Overview
Developers share code on Nostr today inside plain text notes (kind:1, see NIP-01 and NIP-10). A text note carries no metadata about the code. Clients cannot tell the language. They cannot highlight syntax. They cannot offer a correct filename for download.
This NIP defines a separate event kind for code snippets. The event stores the code itself in content. A set of optional tags describes the code: language, name, extension, description, runtime, license, dependencies, and source repository.
The extra metadata improves discoverability. A client can filter snippets by language. It improves syntax highlighting. It improves the whole user experience around shared code.
Every tag in this NIP is optional. A bare kind-1337 event with only code in content is valid. Add tags when you know them; clients degrade gracefully when they are missing.
l tag.2 The Snippet Event: Kind 1337
This NIP defines kind:1337 as a code snippet event. The content field contains the actual code snippet text. Nothing else goes in content: no markdown fences, no commentary.
{
"id": <32-byte lowercase hex sha256 of the serialized event>
"pubkey": <32-byte lowercase hex public key of the author>
"created_at": <unix timestamp, seconds>
"kind": 1337,
"content": <the code snippet text>
"tags": [ <optional metadata tags, see §3> ]
"sig": <64-byte signature of the id>
}
Kind 1337 sits in the regular range (1000–9999) of NIP-01. Relays store every snippet event. A new snippet does not replace an old one. To change a snippet, publish a new event.
3 Optional Tags
All eight tags are optional. Each tag adds one piece of metadata about the code:
| Tag | Value | Rule |
|---|---|---|
| l | language name | Programming language, lowercase. Examples: javascript, python, rust. |
| name | snippet name | Name of the snippet, commonly a filename. Examples: hello-world.js, quick-sort.py. |
| extension | file extension | Extension without the dot. Examples: js, py, rs. |
| description | free text | A brief description of what the code does. |
| runtime | runtime spec | Runtime or environment. Examples: node v18.15.0, python 3.11. |
| license | SPDX identifier | License for the code and related event data. Repeatable. See below. |
| dep | dependency | One dependency the code needs to run. Repeat the tag for each dependency. |
| repo | URL or address | The repository the code comes from. See below. |
The license tag
The license value covers the code and any related data in the event, such as the description. The value must be a standard SPDX short identifier when one exists. Examples: MIT, GPL-3.0-or-later, Apache-2.0. The tag may carry an additional parameter: a reference to the actual license text.
The tag can be repeated to indicate multi-licensing. The recipient may then use the code under any one of the referenced licenses, at their choosing.
The repo tag
The repo value points at the repository where the code originates. It must take one of two forms:
- A standard URL, such as
https://github.com/nostr-protocol/nostr. - The address of a NIP-34 git repository announcement event, in the form
30617:<32-byte hex pubkey>:<d tag value>. In this form, add an additional parameter: a recommended relay URL where the announcement event can be found.
The single-letter l tag is also the label tag of NIP-32, where it pairs with an L namespace tag. This NIP uses l alone, with a different meaning. Both share the same indexed #l filter, so a language query can match unrelated labeled events outside kind 1337. Always combine "#l" with "kinds": [1337].
4 Client Behavior
Clients that support this NIP should do six things:
- Display code snippets with proper syntax highlighting based on the language.
- Allow copying the full code snippet with a single action.
- Render the code with appropriate formatting. Preserve whitespace and indentation.
- Display the language and extension prominently.
- Provide a run function for supported languages when possible.
- Display the description, if available, as part of the snippet presentation.
Clients may add more functionality:
- Code editing capabilities.
- Forking and modifying snippets.
- Creating executable environments based on the runtime and dependencies.
- Downloading the snippet as a file, using the provided extension.
- Sharing the snippet with attribution.
A run function executes code from strangers. Sandbox it. Never run a snippet with access to the user's keys, files, or network without explicit consent.
5 Worked Example
The event below shares a small JavaScript function. Every optional tag is present:
{
"id": <32-byte lowercase hex sha256 of the serialized event>,
"pubkey": <32-byte lowercase hex public key of the event creator>,
"created_at": 1743264000,
"kind": 1337,
"content": "function helloWorld() {\n console.log('Hello, Nostr!');\n}\n\nhelloWorld();",
"tags": [
["l", "javascript"],
["extension", "js"],
["name", "hello-world.js"],
["description", "A basic JavaScript function that prints 'Hello, Nostr!' to the console"],
["runtime", "node v18.15.0"],
["license", "MIT"],
["repo", "https://github.com/nostr-protocol/nostr"]
],
"sig": <64-byte signature of the id>
}
The session below publishes the snippet, then fetches all JavaScript snippets from the same relay. Orange lines go to the relay. Blue lines come from the relay.
-- author publishes the snippet -- → ["EVENT", {"kind":1337, "content":"function helloWorld() {…", "tags":[["l","javascript"], …], …}] ← ["OK", "7ac21f30…", true, ""] -- a reader asks for JavaScript snippets -- → ["REQ", "snips", {"kinds":[1337], "#l":["javascript"], "limit":20}] ← ["EVENT", "snips", {"id":"7ac21f30…", "kind":1337, "content":"function helloWorld() {…", …}] ← ["EOSE", "snips"] → ["CLOSE", "snips"]
6 Version History
NIP-C0 is a young, stable draft. Notable changes, newest first:
- 20252025-12Typo and link fixes across two cleanup passes.
- 20252025-11General revision of the specification (#2138), tightening the tag definitions.
- 20252025-04Title and description cleanup in a repository-wide pass (#1888).
- 20252025-03fiatjaf renamed the file from 95 to C0, giving the NIP its hex number.
- Origin2025-03-29Christian Chiarulli published the code snippets proposal (#1852).
Original Proposal - Credits
| Author | Christian Chiarulli |
| First commit | 2025-03-29 — “NIP-C0: Code snippets” (PR #1852) |
| Status | draftoptional |
| Source | C0.md on GitHub - full change history |
7 See Also
- NIP-01 — the base event format, kind ranges, and the
#lindexed filter used here. - NIP-34 — git repository announcements; the target of the addressable
repoform. - NIP-32 — labeling; shares the single-letter
ltag name with this NIP. - NIP-10 — plain kind-1 text notes, the metadata-free way to paste code.
- NIP-19 — bech32 encodings for sharing snippet event pointers outside relays.