# Context.selection
URL: https://lsd.tools/docs/api-context-selection
Updated: 2026-07-17

## Example

```python
@tool.command("demo/count_selected")
def count_selected(ctx: Context):
    n = len(ctx.selection) if ctx.selection else 0
```

## Notes

A lazily populated slot — `None` when nothing is selected or the invoking surface has no selection.
Guard before iterating.

## See also

**API:** [entity](/docs/api-context-entity) · [ui](/docs/api-context-ui) · [Context](/docs/api-context)

**Guides:** [Commands & actions](/docs/tools-commands-actions)
