# `ClaudeAgentSDK.TaskSupervisor`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/task_supervisor.ex#L1)

Optional Task.Supervisor for supervised callback execution.

This module provides a supervised environment for async callback execution
in the Claude Agent SDK. Using supervised tasks ensures that:

- Callback process crashes are detected and handled gracefully
- No orphaned processes accumulate over time
- Resource cleanup happens automatically on failure

## Usage

Add to your application's supervision tree:

    children = [
      ClaudeAgentSDK.TaskSupervisor,
      # ... other children
    ]

The SDK will automatically detect and use this supervisor when available.
If the supervisor is not started, the SDK falls back to `Task.start/1`.

## Configuration

You can customize the supervisor name if needed:

    {ClaudeAgentSDK.TaskSupervisor, name: MyApp.ClaudeTaskSupervisor}

Then configure the SDK to use it:

    config :claude_agent_sdk, task_supervisor: MyApp.ClaudeTaskSupervisor

If a custom supervisor is configured but not running, the SDK logs a warning.
You can enforce stricter behavior in dev/test:

    config :claude_agent_sdk, task_supervisor_strict: true

## Direct Usage

    {:ok, pid} = ClaudeAgentSDK.TaskSupervisor.start_child(fn ->
      # Your async work here
    end)

## OTP Notes

Tasks are started with `restart: :temporary` by default (no automatic restarts).

# `available?`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/task_supervisor.ex#L105)

```elixir
@spec available?() :: boolean()
```

Checks if the task supervisor is available and running.

# `child_spec`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/task_supervisor.ex#L71)

```elixir
@spec child_spec(keyword()) :: Supervisor.child_spec()
```

Returns the child specification for supervision tree inclusion.

# `start_child`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/task_supervisor.ex#L94)

```elixir
@spec start_child(
  (-&gt; any()),
  keyword()
) :: {:ok, pid()}
```

Starts a supervised child task.

The caller should monitor the returned pid if it needs crash signals.

## Parameters

- `fun` - Zero-arity function to execute
- `opts` - Options passed to Task.Supervisor.start_child/3

## Returns

- `{:ok, pid}` - Task started successfully (falls back to `Task.start/1` if needed)

# `start_link`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/task_supervisor.ex#L62)

```elixir
@spec start_link(keyword()) :: Supervisor.on_start()
```

Starts the task supervisor.

## Options

- `:name` - The supervisor name (default: `ClaudeAgentSDK.TaskSupervisor`)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
