---
title: "@henryqw/pi-open-in"
seo:
  description: "Open the current Pi working directory with a configurable command."
---

<div class="not-prose my-6 flex flex-wrap items-center gap-3"><span class="text-sm text-muted-foreground">v1.0.1</span><a href="https://www.npmjs.com/package/@henryqw/pi-open-in" aria-label="View @henryqw/pi-open-in on npm"><img alt="Monthly npm downloads" height="20" src="https://img.shields.io/npm/dm/%40henryqw%2Fpi-open-in?cacheSeconds=7200&amp;color=1d4ed8&amp;label=downloads&amp;labelColor=101828&amp;style=flat-square" width="144"></a></div>

Open the current working directory with a configurable editor command. The default is `code`.

## Why

- **Created for**: Replace manually typed editor commands with one configurable action for the working directory.
- **Advantage**: `/open` works while the agent is busy and supports any simple editor command, defaulting to `code`.

## Install

```bash
pi install npm:@henryqw/pi-open-in
```

## Use

| Surface | Type | Purpose |
| --- | --- | --- |
| `/open` | command | Run `<command> <current-working-directory>`. Works while the agent is busy. |
| `/set-open-in` | command | Set the command used by `/open`. |

## Config

`~/.pi/agent/config/pi-open-in/config.json`

```json
{
  "command": "code"
}
```

- A missing file silently uses the default command, `"code"`.
- Reads do not create or write the config home.
- When the file exists, `command` is required. It must be a non-empty string.
- The command splits on whitespace into an executable and arguments. Tokens cannot contain spaces, and quoting is unsupported. Use a wrapper script for executables in spaced paths.
- An existing file must be a JSON object with exactly one non-empty string `command` property. Otherwise `/open` fails with a visible error and offers no open URI.
- Malformed files remain unchanged.
- Only `/set-open-in` writes the file. Its write is atomic.

## Owner API

Consumers use the owner API instead of reading this file.

```ts
import { loadOpenInConfig } from "@henryqw/pi-open-in/open-uri";

const { source, value } = loadOpenInConfig();
```

`source` is `"missing"` or `"file"`. `value.command` is validated.
Pass an agent directory to `loadOpenInConfig(agentDir)` when needed.

`configuredOpenUri(path)` returns a VS Code URI when the executable is `code`.
For `code -n` and `code --new-window`, it adds `windowId=_blank` so the link opens a new window.
It returns `undefined` for other commands or invalid config.

This extension owns command validation. `@henryqw/pi-config-store` owns the config home and storage.
