← All NIPs

NIP-C0

Code Snippets

DraftEvents

Share code as kind 1337 events: the content is the code, and tags give the language, file name, license, dependencies and source repository.

At a glance

Status
In use and still allowed to change.
Kinds
Tags
  • description
  • extension
  • l
  • license
  • name
  • repo
  • runtime
Last changed
Dec 30, 2025

Try it

Edit the form or the JSON: both stay in sync, the badge says whether the result is valid, and tapping any field explains it.

Examples
Valid 1 note

Not signed yet · Demo keys only. These personas' secret keys are public on purpose.

Form
Jan 1, 2025, 12:00 AM UTC

Content

The code itself.

Tags

  1. l Recommended

    Programming language.

  2. name Optional

    Name of the snippet, usually a file name.

  3. extension Optional

    File extension, used to highlight and download the snippet.

  4. description Optional

    What the code does, in a sentence.

  5. runtime Optional

    Runtime or environment it was written for.

  6. license Optional

    License of the code. Repeat for multiple licenses.

  7. repo Optional

    Where the code comes from.

Add tag

How this NIP works

Step 1 of 5

The code is the content

Put the snippet in the content exactly as written. Clients keep whitespace and indentation and offer one-click copy.

In the course

No course chapter covers this NIP yet. The editor above is the quickest way in.

Builds on

See also

Specification

Specification text is quoted in English from the nostr-protocol/nips repository. Our explanations and the interface are translated. Source on GitHub at commit 0046368

Read the spec466 words, quoted from the repository at commit 0046368.

Abstract

This NIP defines a new event kind for sharing and storing code snippets. Unlike regular text notes (kind:1), code snippets have specialized metadata like language, extension, and other code-specific attributes that enhance discoverability, syntax highlighting, and improved user experience.

Event Kind

This NIP defines kind:1337 as a code snippet event.

The .content field contains the actual code snippet text.

Optional Tags

  • l - Programming language name (lowercase). Examples: "javascript", "python", "rust"
  • name - Name of the code snippet, commonly a filename. Examples: "hello-world.js", "quick-sort.py"
  • extension - File extension (without the dot). Examples: "js", "py", "rs"
  • description - Brief description of what the code does
  • runtime - Runtime or environment specification (e.g., "node v18.15.0", "python 3.11")
  • license - License under which the code (along with any related data contained within the event, when available, such as the description) is shared. This MUST be a standard SPDX short identifier (e.g., "MIT", "GPL-3.0-or-later", "Apache-2.0") when available. An additional parameter containing a reference to the actual text of the license MAY be provided. This tag can be repeated, to indicate multi-licensing, allowing recipients to use the code under any license of choosing among the referenced ones
  • dep - Dependency required for the code to run (can be repeated)
  • repo - Reference to a repository where this code originates. This MUST be either a standard URL or, alternatively, the address of a NIP-34 Git repository announcement event in the form "30617:<32-bytes hex a pubkey>:<d tag value>". If a repository announcement is referenced, a recommended relay URL where to find the event should be provided as an additional parameter

Format

{
  "id": "<32-bytes lowercase hex-encoded SHA-256 of the the serialized event data>",
  "pubkey": "<32-bytes lowercase hex-encoded public key of the event creator>",
  "created_at": <Unix timestamp in seconds>,
  "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-bytes signature of the id>"
}

Client Behavior

Clients that support this NIP SHOULD:

  1. Display code snippets with proper syntax highlighting based on the language.
  2. Allow copying the full code snippet with a single action.
  3. Render the code with appropriate formatting, preserving whitespace and indentation.
  4. Display the language and extension prominently.
  5. Provide "run" functionality for supported languages when possible.
  6. Display the description (if available) as part of the snippet presentation.

Clients MAY provide additional functionality such as:

  1. Code editing capabilities
  2. Forking/modifying snippets
  3. Creating executable environments based on the runtime/dependencies
  4. Downloading the snippet as a file using the provided extension
  5. Sharing the snippet with attribution