npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nicknisi/pi-save-md

v0.1.2

Published

Save the last assistant message or session as markdown

Readme

@nicknisi/pi-save-md

Save the most recent assistant response in the current session to a Markdown file in the working directory. It exists because pi has no built-in way to export a single response to a file — the full session transcript lives in pi's session storage, but extracting just the latest answer as a standalone .md requires digging through that store. This extension adds one slash command, /save-md, that does it in place.

What it adds

  • Slash command: /save-md <name>

No tools, keybindings, widgets, overlays, event hooks, or custom message/entry types.

Usage

/save-md notes
/save-md notes.md
/save-md research/api-comparison

Behavior:

  1. Waits for the agent to be idle (ctx.waitForIdle()), so invoking it while a response is streaming waits for the response to finish.
  2. Walks the current session branch backwards (ctx.sessionManager.getBranch()) to find the latest assistant message.
  3. Extracts only text content blocks from that message, joining them with blank lines. Non-text blocks (tool calls, thinking, images) are dropped.
  4. Appends .md if the name doesn't already end in it, resolves the path relative to ctx.cwd, and writes the file.
  5. Ensures the file ends with a trailing newline.

Examples:

/save-md summary        → writes <cwd>/summary.md
/save-md docs/plan      → writes <cwd>/docs/plan.md (docs/ must already exist)

Failure modes, all reported via ctx.ui.notify:

| Condition | Level | Message | | ------------------------------------------- | ------- | ---------------------------------------------------- | | No assistant message in the current branch | warning | No assistant response to save | | Empty <name> argument | warning | Usage: /save-md name | | Latest assistant message has no text blocks | warning | The latest assistant response has no Markdown text | | Target file already exists | error | File already exists: <path> |

Configuration

None. No config files are read, no options exist, and no environment variables are consulted.

Dependencies

Peer dependencies (both *):

  • @earendil-works/pi-coding-agentExtensionAPI type. At runtime uses pi.registerCommand, ctx.waitForIdle, ctx.sessionManager.getBranch, ctx.ui.notify, and ctx.cwd.
  • @earendil-works/pi-aiAssistantMessage type only.

Runtime dependencies: Node builtins node:fs/promises (writeFile) and node:path (resolve). No npm dependencies, no workspace deps.

Caveats

  • Only text blocks are saved. Tool calls, tool results, thinking blocks, and any other non-text content in the assistant message are silently omitted. If the last assistant turn was purely tool calls with no final text, the command reports there is nothing to save.
  • Current branch only. getBranch() returns the active branch of the session tree; messages on other branches are not considered.
  • No overwrite. The file is written with flag wx (exclusive create). Re-running /save-md with the same name fails with an EEXIST error rather than overwriting. Delete the file or pick a new name.
  • No directory creation. Parent directories of the target path must already exist; otherwise writeFile throws (the error propagates rather than being notified).
  • Pi internals. Depends on the session entry shape (entry.type === "message", entry.message.role) and on ctx.sessionManager.getBranch() / ctx.ui.notify APIs, any of which could change across pi versions. The content-block filter is written defensively (structural checks, no casts) to tolerate shape drift in message content.

Install

pi install /Users/nicknisi/Developer/pi-extensions/packages/save-md