# `MingaClaudeBridge.Route.PlanUsage`
[🔗](https://github.com/jsmestad/minga-claude-bridge/blob/main/lib/minga_claude_bridge/route/plan_usage.ex#L1)

Converts Claude Code's plan-usage data to Minga's `MingaAgent.InferenceRoute.PlanWindow` values.

Two sources describe the same windows:

  * The `get_usage` control request answers with `rate_limits`, where each window (`five_hour`, `seven_day`, and `seven_day_*` variants such as `seven_day_opus`) is either `null` or an object with `utilization` as a percent from 0 to 100, `resets_at` as an ISO 8601 string, and `locked_reason`. `from_get_usage/1` reads every non-null window. Its status is `:rejected` when `locked_reason` is set or utilization reaches 100%, `:warning` from 80%, and `:allowed` below.
  * A `rate_limit_event` during a turn reports one window's status and reset time, and sometimes its utilization. `apply_rate_limit/2` updates that window's status and reset time, takes the event's utilization when present (a fraction from 0 to 1, or a percent when above 1), and otherwise keeps the last known utilization.

The latest source wins for the fields it carries. `get_usage` refreshes every window; a `rate_limit_event` refreshes one window's status. Account data never passes through this module.

# `windows`

```elixir
@type windows() :: %{required(String.t()) =&gt; MingaAgent.InferenceRoute.PlanWindow.t()}
```

Windows keyed by kind.

# `apply_rate_limit`

```elixir
@spec apply_rate_limit(windows(), MingaClaudeBridge.Wire.RateLimit.t()) :: windows()
```

Updates the window a `rate_limit_event` describes. Events without a window type change nothing.

# `from_get_usage`

```elixir
@spec from_get_usage(map()) :: windows()
```

Reads the plan windows of a `get_usage` answer.

# `plan_label`

```elixir
@spec plan_label(map() | nil) :: String.t() | nil
```

Returns the plan label of a `get_usage` answer, for example "Claude Max" for "max", or `nil`.

# `to_list`

```elixir
@spec to_list(windows()) :: [MingaAgent.InferenceRoute.PlanWindow.t()]
```

Returns the windows in display order: five-hour, seven-day, then the others by kind.

---

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