# pi-linear-worktree

A [pi](https://github.com/badlogic/pi-mono) extension that fetches Linear issues and creates git worktrees to solve them.

Type `/linear ENG-123` and the agent will:

1. Fetch the full issue from Linear (title, description, comments, labels, relations)
2. Create a git worktree with a branch named after the issue
3. Send the issue context to the agent and start solving it

## Install

```bash
pi install npm:pi-linear-worktree
```

Or try it without installing:

```bash
pi -e npm:pi-linear-worktree
```

## Setup

Set your Linear API key as an environment variable:

```bash
export LINEAR_API_KEY=lin_api_xxxxxxxxxxxxx
```

You can create a personal API key at [Linear Settings → API](https://linear.app/settings/api).

## Usage

Inside a git repository, run:

```
/linear <issue-id>
```

For example:

```
/linear ENG-123
```

The extension will:

- Fetch the issue details from Linear
- Create a worktree at `../<branch-name>` relative to the repo root
- If the worktree/branch already exists, reuse it
- Name the pi session after the issue
- Send the full issue context to the agent to start working on it

## What gets sent to the agent

- Issue title, description, state, priority, assignee
- Labels and parent issue
- Related issues
- All comments (chronological)
- Worktree path and branch name
- Instructions to work in the worktree and commit when done

## License

MIT
