# copy-code

Pi coding-agent extension that copies fenced code blocks from recent assistant
(and tool result) messages into the system clipboard.

## Triggers

- Shortcut: `ctrl+shift+y` -> picker over recent code blocks
- Command:  `/cc` -> picker
- Command:  `/cc last` -> copy the most recent block
- Command:  `/cc 2` -> copy the 2nd-most-recent block (1-based)
- Command:  `/cc all` -> concatenate all blocks from the latest assistant message

The command is named `/cc` because `/copy` conflicts with a pi built-in
interactive command.

## Install

```sh
# global (writes ~/.pi/agent/settings.json)
pi install https://github.com/burneikis/pi-copy-code

# or project-local (writes .pi/settings.json)
pi install -l https://github.com/burneikis/pi-copy-code
```

Try it for a single run without installing:

```sh
pi -e https://github.com/burneikis/pi-copy-code
```

After installing, `/reload` inside pi (or restart it).

Remove with:

```sh
pi remove https://github.com/burneikis/pi-copy-code
```

## Clipboard backends

Auto-detected at session start. First match wins:

- macOS: `pbcopy`
- Linux Wayland: `wl-copy` (preferred when `WAYLAND_DISPLAY` is set)
- Linux X11: `xclip`, then `xsel`
- Windows / WSL: `clip.exe`

If none are found you'll see a one-time error notification when you trigger a copy.

## Notes

- Scans both assistant text content and tool-result text content (newest first).
- Thinking content is ignored.
- Picker shows up to 30 most recent blocks with `lang`, line count, and a one-line preview.
