GitHub Gists
Create or view gists using the GitHub CLI (gh).
Arguments
$ARGUMENTS
Format: [action] [args...]
create [filename]- Create a new gist (default action)view <gist_id>- View gist contentlist- List your gistsedit <gist_id>- Edit an existing gistdelete <gist_id>- Delete a gist
Examples
/github:gist create snippet.js
/github:gist create snippet.js --public
/github:gist view abc123def
/github:gist list
/github:gist edit abc123def
Instructions
Required GitHub CLI preflight
Before any workflow step, read ../../references/github-cli-preflight.md and complete it. Do not run workflow commands until gh installation and authentication are verified.
Create Gist (default)
Check for staged/selected content:
- If filename provided, read that file
- If content is selected/provided, use that
- Otherwise, ask user what to include
Prepare safe inputs:
- Require a filename. Validate it as a basename without path traversal.
- Write selected/provided content to a temporary file whose basename is the
intended gist filename. Never put gist content in
echo, a generated shell command, or an interpolated heredoc. - Write the optional description to a separate temporary text file, then load it into a quoted variable.
Prompt for gist options:
- Public or private (default: private)
- Description (optional)
- Filename
Confirm public disclosure: For a public gist, show the verified host, account, filename, and byte count, warn that deletion cannot reliably undo indexing or copies, and require explicit confirmation immediately before creation. A secret gist does not require this extra disclosure gate.
Create the gist non-interactively:
gist_description=$(<"$description_file") gh gist create "$content_file" --desc "$gist_description" [--public]GH_HOSTfrom the preflight is mandatory becausegh gistdoes not accept a repository or hostname flag.Report gist URL to the user.
View Gist
gh gist view <gist_id> --raw
List Gists
gh gist list --limit 20
Edit Gist
Fetch the current filenames, require the user to identify the file being
changed, write the replacement content to <content_file>, and generate a JSON
request body with a JSON-aware tool or library. Do not open $EDITOR.
gh api --method PATCH "gists/<gist_id>" --input <payload_file>
Delete Gist
After explicit user confirmation, use the non-interactive flag:
gh gist delete <gist_id> --yes
Output Format
After creation:
Created gist: https://gist.github.com/<username>/<id>
Files:
- filename.js (123 bytes)
Error Handling
- If the GitHub CLI preflight fails, stop and follow its installation or browser-authentication guidance; do not run the gist command.
- If gist not found: "Error: Gist '' not found"
- If file not found: "Error: File '' not found"