> Threadwell can help you create Threadwell packages. Ask it to bundle your extensions, skills, or prompt templates.

# Threadwell Packages

Threadwell packages are an advanced local customization and distribution mechanism. They can bundle extensions, skills, and prompt templates through npm, git, or local paths. Normal Threadwell use does not require package authoring.

A package can declare resources in `package.json` under the `thread` key, or use conventional directories.

## Table of Contents

- [Install and Manage](#install-and-manage)
- [Package Sources](#package-sources)
- [Creating a Threadwell Package](#creating-a-threadwell-package)
- [Package Structure](#package-structure)
- [Dependencies](#dependencies)
- [Package Filtering](#package-filtering)
- [Enable and Disable Resources](#enable-and-disable-resources)
- [Scope and Deduplication](#scope-and-deduplication)

## Install and Manage

> **Security:** Threadwell packages run with full system access. Extensions execute arbitrary code, and skills can instruct the model to perform any action including running executables. Review source code before installing third-party packages.

```bash
thread install npm:@foo/bar@1.0.0
thread install git:github.com/user/repo@v1
thread install https://github.com/user/repo  # raw URLs work too
thread install /absolute/path/to/package
thread install ./relative/path/to/package

thread remove npm:@foo/bar
thread list                     # show installed packages from settings
thread update                   # update Threadwell and all non-pinned packages
thread update --extensions      # update all non-pinned packages only
thread update --self            # update Threadwell only
thread update --self --force    # reinstall Threadwell even if current
thread update npm:@foo/bar      # update one package
thread update --extension npm:@foo/bar
```

By default, `install` and `remove` write to global settings (`~/.threadwell/agent/settings.json`). Use `-l` to write to project settings (`.threadwell/settings.json`) instead. Project settings can be shared with your team, and Threadwell installs any missing packages automatically on startup.

To try a package without installing it, use `--extension` or `-e`. This installs to a temporary directory for the current run only:

```bash
thread -e npm:@foo/bar
thread -e git:github.com/user/repo
```

## Package Sources

Threadwell accepts three source types in settings and `thread install`.

### npm

```
npm:@scope/pkg@1.2.3
npm:pkg
```

- Versioned specs are pinned and skipped by package updates (`thread update`, `thread update --extensions`).
- Global installs use `npm install -g`.
- Project installs go under `.threadwell/npm/`.
- Set `npmCommand` in `settings.json` to pin npm package lookup and install operations to a specific wrapper command such as `mise` or `asdf`.

Example:

```json
{
  "npmCommand": ["mise", "exec", "node@20", "--", "npm"]
}
```

### git

```
git:github.com/user/repo@v1
git:git@github.com:user/repo@v1
https://github.com/user/repo@v1
ssh://git@github.com/user/repo@v1
```

- Without `git:` prefix, only protocol URLs are accepted (`https://`, `http://`, `ssh://`, `git://`).
- With `git:` prefix, shorthand formats are accepted, including `github.com/user/repo` and `git@github.com:user/repo`.
- HTTPS and SSH URLs are both supported.
- SSH URLs use your configured SSH keys automatically (respects `~/.ssh/config`).
- For non-interactive runs (for example CI), you can set `GIT_TERMINAL_PROMPT=0` to disable credential prompts and set `GIT_SSH_COMMAND` (for example `ssh -o BatchMode=yes -o ConnectTimeout=5`) to fail fast.
- Refs pin the package and skip package updates (`thread update`, `thread update --extensions`).
- Cloned to `~/.threadwell/agent/git/<host>/<path>` (global) or `.threadwell/git/<host>/<path>` (project).
- Runs `npm install` after clone or pull if `package.json` exists.

**SSH examples:**
```bash
# git@host:path shorthand (requires git: prefix)
thread install git:git@github.com:user/repo

# ssh:// protocol format
thread install ssh://git@github.com/user/repo

# With version ref
thread install git:git@github.com:user/repo@v1.0.0
```

### Local Paths

```
/absolute/path/to/package
./relative/path/to/package
```

Local paths point to files or directories on disk and are added to settings without copying. Relative paths are resolved against the settings file they appear in. If the path is a file, it loads as a single extension. If it is a directory, Threadwell loads resources using package rules.

## Creating a Threadwell Package

Add a `thread` manifest to `package.json` or use conventional directories. Include the `threadwell-package` keyword for discoverability.

```json
{
  "name": "my-package",
  "keywords": ["threadwell-package"],
  "threadwell": {
    "extensions": ["./extensions"],
    "skills": ["./skills"],
    "prompts": ["./prompts"]
  }
}
```

Paths are relative to the package root. Arrays support glob patterns and `!exclusions`.

## Package Structure

### Convention Directories

If no `thread` manifest is present, Threadwell auto-discovers resources from these directories:

- `extensions/` loads `.ts` and `.js` files
- `skills/` recursively finds `SKILL.md` folders and loads top-level `.md` files as skills
- `prompts/` loads `.md` files

## Dependencies

Third party runtime dependencies belong in `dependencies` in `package.json`. Dependencies that do not register extensions, skills, or prompt templates also belong in `dependencies`. When Threadwell installs a package from npm or git, it runs `npm install`, so those dependencies are installed automatically.

Threadwell bundles core packages for extensions and skills. If you import any of these, list them in `peerDependencies` with a `"*"` range and do not bundle them: `@threadwell/ai`, `@threadwell/agent-core`, `threadwell`, `@threadwell/tui`, `typebox`.

Other Threadwell packages must be bundled in your tarball. Add them to `dependencies` and `bundledDependencies`, then reference their resources through `node_modules/` paths. Threadwell loads packages with separate module roots, so separate installs do not collide or share modules.

Example:

```json
{
  "dependencies": {
    "shitty-extensions": "^1.0.1"
  },
  "bundledDependencies": ["shitty-extensions"],
  "threadwell": {
    "extensions": ["extensions", "node_modules/shitty-extensions/extensions"],
    "skills": ["skills", "node_modules/shitty-extensions/skills"]
  }
}
```

## Package Filtering

Filter what a package loads using the object form in settings:

```json
{
  "packages": [
    "npm:simple-pkg",
    {
      "source": "npm:my-package",
      "extensions": ["extensions/*.ts", "!extensions/legacy.ts"],
      "skills": [],
      "prompts": ["prompts/review.md"]
    }
  ]
}
```

`+path` and `-path` are exact paths relative to the package root.

- Omit a key to load all of that type.
- Use `[]` to load none of that type.
- `!pattern` excludes matches.
- `+path` force-includes an exact path.
- `-path` force-excludes an exact path.
- Filters layer on top of the manifest. They narrow down what is already allowed.

## Enable and Disable Resources

Use `thread config` to enable or disable extensions, skills, and prompt templates from installed packages and local directories. Works for both global (`~/.threadwell/agent`) and project (`.threadwell/`) scopes.

## Scope and Deduplication

Packages can appear in both global and project settings. If the same package appears in both, the project entry wins. Identity is determined by:

- npm: package name
- git: repository URL without ref
- local: resolved absolute path
