# Packaging and distribution

When you build custom tools, channel plugins, or workflow-specific skills on top of Bub—or want to ship a branded CLI of your own—you can package them as a standard Python wheel and publish them to PyPI or a private index for your team and users to install.

Common distribution patterns:

| Pattern | Contents | Use case |
| --- | --- | --- |
| **Extension package** | Plugin entry point + skills directory | Add tools, channels, or skills to an existing Bub install |
| **Custom CLI** | Custom script entry point (e.g. `my-bub`) | Ship a branded command name or pin a default workspace |
| **All-in-one package** | Custom CLI + plugins + skills | Deliver a ready-to-run domain-specific agent in one package |

:::note
This page covers building **standalone installable Python packages**. To embed Bub inside an existing web service or backend, see [Reuse Bub in a service](/docs/integrations/reuse-app/).
:::

## Publish a custom CLI command {#publish-a-command}

A package can expose its own command name and delegate to Bub's CLI entrypoint, letting you brand the agent or pin default behavior:

```python title="src/my_bub/cli.py"
import os
from pathlib import Path
from bub.__main__ import main as bub_main

def main() -> None:
    # Optional: set a default workspace (overridable via --workspace)
    if workspace := os.getenv("MY_BUB_WORKSPACE"):
        os.chdir(Path(workspace).expanduser())

    bub_main()
```

Declare the script in `pyproject.toml`:

```toml title="pyproject.toml"
[project.scripts]
my-bub = "my_bub.cli:main"
```

Once installed, users can run `my-bub chat`, `my-bub run`, and `my-bub gateway` directly, with all native subcommands and flags like `--workspace` intact.

## Bundle plugins and skills together {#bundle-plugins-and-skills}

A single wheel can bundle a custom CLI command, plugin entry points, and a `skills` namespace package:

- my-bub/
  - **pyproject.toml**
  - src/
    - my_bub/
      - \_\_init\_\_.py
      - **cli.py** # Custom CLI entrypoint
      - **plugin.py** # Plugin and hook implementations
      - tools.py # Custom tools
    - **skills/** # Skill namespace package (do NOT add \_\_init\_\_.py)
      - repo-reviewer/
        - SKILL.md
        - references/
          - guidelines.md

:::caution[Do not add `__init__.py` to `src/skills/`]
`src/skills/` must be packaged as a **PEP 420 implicit namespace package**. **Never** place an `__init__.py` inside `src/skills/`; otherwise its skills cannot merge with Bub's bundled skills and other installed skill packages under `skills.__path__`.
:::

### Configure `pyproject.toml` {#configure-packaging}

```toml title="pyproject.toml" mark={14-15,17-18,20-21}
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "my-bub"
version = "0.1.0"
description = "My Custom Bub Agent Distribution"
requires-python = ">=3.12"
dependencies = [
    "bub[app]>=0.6.0",
]

[project.scripts]
my-bub = "my_bub.cli:main"

[project.entry-points."bub"]
my_plugin = "my_bub.plugin:plugin"

[tool.hatch.build.targets.wheel]
packages = ["src/my_bub", "src/skills"]
```

Key settings:

1. **Depend on `bub[app]`**: the base `bub` package installs only the core kernel; the CLI, plugins, and skill loader require `bub[app]` (see the [0.6.0 upgrade guide](/docs/migration/v0-6/)).
2. **Use the `"bub"` entry-point group**: register plugins under `[project.entry-points."bub"]` (see [entry-point forms](/docs/app/plugins/#entry-point-forms)).
3. **Include `"src/skills"`**: list `"src/skills"` in `packages` under `[tool.hatch.build.targets.wheel]`.

## Build and install {#build-and-distribute}

Build the wheel and sdist with `uv`:

```bash
uv build
```

Artifacts are written to `dist/`. Users can install your package in two ways:

- **As a standalone CLI tool**: `uv tool install my-bub`
- **As a managed Bub plugin**: [`bub install <package>`](/docs/reference/cli/#bub-install)

## Verify before release {#verify-a-release}

Before publishing publicly or rolling out to production, test the built `.whl` file in a clean virtual environment:

1. **Create a clean virtual environment and install the wheel**:
   ```bash
   uv venv .test-env && source .test-env/bin/activate
   uv pip install dist/*.whl
   ```

2. **Verify plugin registration**:
   ```bash
   my-bub hooks
   ```
   Confirm your plugin identifier appears without import errors.

3. **Verify skill discovery**:
   ```bash
   my-bub run ",skill"
   my-bub run ",skill name=repo-reviewer"
   ```
   Confirm bundled skills are listed and expand properly.

4. **Verify chat and tools**:
   ```bash
   my-bub run "Test model and custom tool calls"
   my-bub chat
   ```