---
slug: "pi-open-last-response"
source_type: "readme"
source_url: "https://cdn.jsdelivr.net/gh/wujunchuan/pi-open-last-response@main/README.md"
repo: "https://github.com/wujunchuan/pi-open-last-response"
source_file: "README.md"
branch: "main"
---
# pi-open-last-response

A local Pi extension that writes the latest completed assistant response to a temporary Markdown file and opens it in your external editor.

## Why

Long assistant replies are inconvenient to scroll through inside the Pi TUI. `/open-last` lets you read the newest reply in Cursor, VS Code, Zed, Sublime, or your configured editor without manually copying and pasting.

## Install

From npm:

```bash
pi install npm:pi-open-last-response
```

From GitHub:

```bash
pi install git:github.com/wujunchuan/pi-open-last-response
```

For local development:

```bash
pi install /Users/john/Project/Github/pi-open-last-response
```

Then reload Pi:

```text
/reload
```

## Commands

```text
/open-last
/open-last-response
/olast
```

Examples:

```text
/open-last
/open-last cursor
/open-last code --reuse-window
/open-last --path-only
```

`--path-only` writes the Markdown file and prints the path without opening an editor.

## Editor selection

Priority:

1. editor command passed as command args, e.g. `/open-last cursor`
2. `PI_OPEN_LAST_EDITOR`
3. non-terminal `VISUAL` / `EDITOR`
4. auto-detected GUI/open command:
   - macOS: `cursor`, `code`, `zed`, `subl`, `open`
   - Linux: `cursor`, `code`, `zed`, `subl`, `xdg-open`
   - Windows: `cursor.cmd`, `code.cmd`, `notepad.exe`

Recommended config:

```bash
export PI_OPEN_LAST_EDITOR="cursor"
# or
export PI_OPEN_LAST_EDITOR="code --reuse-window"
```

By default files are written under your OS temp directory, in `pi-open-last-response/`. Override with:

```bash
export PI_OPEN_LAST_DIR="$HOME/.pi/open-last"
```

## Development

```bash
npm install
npm run check
```

## Pi package

This repository is a Pi package because `package.json` contains:

```json
{
  "pi": {
    "extensions": ["./src/index.ts"]
  }
}
```

## License

MIT
