@penumbral-labs/pi-copy-code
A pi extension for ergonomic copying of assistant code blocks.
Package details
Install @penumbral-labs/pi-copy-code from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@penumbral-labs/pi-copy-code- Package
@penumbral-labs/pi-copy-code- Version
0.2.0- Published
- May 15, 2026
- Downloads
- not available
- Author
- aasmall
- License
- MIT
- Types
- extension
- Size
- 18.3 KB
- Dependencies
- 0 dependencies · 2 peers
Pi manifest JSON
{
"extensions": [
"./extensions/copy-code/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-copy-code
A pi package for copying fenced code blocks from assistant messages without terminal selection padding.
pi-copy-code adds one command and one shortcut:
/copy-codectrl+alt+c
It reads the latest assistant message, extracts fenced code blocks, and copies the raw code text to your clipboard. If there is more than one block, it opens a small two-pane picker with a live preview.
Features
- Copy raw fenced code instead of rendered terminal cells.
- Preserve whitespace-sensitive YAML, shell, Python, and heredoc indentation.
- Copy one block immediately when there is only one block.
- Choose between multiple blocks with a preview picker.
- Copy all blocks at once from the picker.
- Edit a selected block in your external editor before copying.
- Clipboard fallback order:
- native clipboard command when available (
pbcopy,wl-copy,xclip,xsel,clip.exe) - OSC 52 terminal clipboard sequence when native clipboard commands are unavailable
- native clipboard command when available (
Install
From npm:
pi install npm:@penumbral-labs/pi-copy-code
From GitHub:
pi install git:github.com/penumbral-labs/pi-copy-code
Or from a local checkout:
cd /path/to/pi-copy-code
pi install "$(pwd)"
Then reload pi:
/reload
For a one-off run without installing:
pi -e npm:@penumbral-labs/pi-copy-code
or, from GitHub:
pi -e git:github.com/penumbral-labs/pi-copy-code
or, from a local checkout:
pi -e "$(pwd)"
Usage
Copy code from the latest assistant message:
/copy-code
or press:
ctrl+alt+c
Edit before copying:
/copy-code edit
When multiple blocks are available, the picker opens:
↑/↓orj/k— move selectionenter— run the default action/copy-code: copy/copy-code edit: edit, then copy
e— edit selected block, then copyescorq— cancel
The first picker item is All code blocks, which copies all blocks separated by blank lines.
External editor setup
Edit mode opens your external editor directly using $VISUAL, then $EDITOR.
For NeoVim:
export VISUAL=nvim
# or
export EDITOR=nvim
If neither variable is set, /copy-code edit shows a warning and cancels.
What counts as a code block?
pi-copy-code extracts fenced markdown blocks from the latest assistant message:
```bash
echo hello
```
~~~python
print("hello")
~~~
Indented markdown code blocks are not currently extracted.
Package shape
The package uses pi's package manifest in package.json:
{
"keywords": ["pi-package"],
"pi": {
"extensions": ["./extensions/copy-code/index.ts"]
}
}
Core pi packages are peer dependencies, per pi package guidance.
Development
Run tests:
npm test
Check publish contents:
npm pack --dry-run
Test fixture
Ask pi to emit multiple fenced blocks, then run /copy-code:
apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
script.sh: |
if [ -n "$FOO" ]; then
echo "$FOO"
fi
from dataclasses import dataclass
@dataclass
class Config:
host: str
port: int = 8080
@property
def url(self) -> str:
return f"http://{self.host}:{self.port}"