> ## Documentation Index
> Fetch the complete documentation index at: https://aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# aspect worktree inspect

> Report a slot, named or the one the working directory is in: its Bazel output base, whether a server holds it, how many worktrees it has held, who has had them, and its checkout.

<Warning>
  New and experimental. File bugs and suggestions to [aspect-build/aspect-cli/issues](https://github.com/aspect-build/aspect-cli/issues).
</Warning>

Report one slot — everything [`aspect worktree list --verbose`](/docs/cli/worktrees/list) says about it, plus its checkout. Name it, or run it from inside the slot to get the one you are standing in.

```shell theme={null}
aspect worktree inspect            # the slot this directory is in
aspect worktree inspect fix/login  # the slot holding fix/login, from anywhere in the clone
```

```
~/.aspect/worktrees/github.com/acme/web/aspect-worktree-<slot>

taken
  slot          state   warmth  age  leases  branch     agent        session                               notes
  18a11aa20e8d  in use  warm    12d       7  fix/login  claude-code  b22fe20c-1111-4000-8000-00000000b22f  session resumable

  18a11aa20e8d
    branch:      fix/login
    path:        ~/.aspect/worktrees/github.com/acme/web/aspect-worktree-18a11aa20e8d
    output base: ~/Library/Caches/bazel/_bazel_you/c84887dbc6585633e5acf6a25179882c
    leases:      7, slot created 12d ago, the last 2 shown
      branch      held  status            agent        session                               project
      fix/login   1h    still holding it  claude-code  b22fe20c-1111-4000-8000-00000000b22f  ~/src/web
      fix/logout  1h    ended 1h 6m ago   claude-code  b22fe20c-1111-4000-8000-00000000b22f  ~/src/web
    checkout:    c60f25fe (on no remote), clean

  session b22fe20c-1111-4000-8000-00000000b22f
    agent:   claude-code
    project: ~/src/web
    resume:  claude --resume b22fe20c-1111-4000-8000-00000000b22f
    leases:
      repo                 slot          branch      held  status
      github.com/acme/web  18a11aa20e8d  fix/login   1h    still holding it
      github.com/acme/web  18a11aa20e8d  fix/logout  1h    ended 1h 6m ago
```

The block is headed by the slot, the same string the table above is keyed on. Every holder the slot remembers carries its project, and the session section under it gives the command that returns to each — including the ones that let go of the slot earlier.

`checkout:` is what deciding whether to release needs: the commit the worktree is at, whether any remote has it, and whether the tree is clean, Bazel's own leavings aside.

Without it, finding this out means listing the whole pool and matching a path by eye — which is the work a slot id exists to save.

## Naming a slot

A name resolves as it does for [`path`](/docs/cli/worktrees/path): the branch checked out in the slot, the branch a free slot last held, the slot id or a unique prefix of it of four or more characters, or the slot's directory. Any slot of this clone answers, free or held by anyone — another session's included — since reading one acts on nothing. A free slot has no `checkout:` line. Another clone's slot is refused, as `release` refuses it, because only that clone's git can answer for its checkout.

## Not naming one

Unnamed, it answers from **any subdirectory** of a slot, not just its root, because the worktree root comes from git rather than from the working directory. A slot is recognised by the name of its directory rather than by comparing paths: git canonicalises what it reports, so `/var` becomes `/private/var` on macOS and symlinks resolve, and two spellings of one directory would not compare equal — while `aspect-worktree-<slot>` is the same string either way.

Wherever it runs, `inspect` by a resumed session from a new process moves every lease of that session, its subagents' included, off a recorded process that has stopped onto the caller's, so they read as running; see [agent detection](/docs/cli/worktrees/agents#what-makes-a-session-resumable-and-what-makes-a-slot-reclaimable).

## When you are not in a slot

Unnamed, that is an answer rather than an error, and exits **0**. It is the expected result in the clone itself, and the two shapes of it are distinguished because they lead different places. Either way it lists the slots this session holds, which is what an agent that has lost its place is asking — run as the session itself, its subagents' too, each named — and then the leases of this session that ended in the last day: released, taken over, or taken back while its process had stopped. Their commits are on their branches. A held slot whose checkout directory is gone is marked ``(checkout gone: `aspect worktree release` says why)``.

In the clone:

```
INFO: not in a pooled worktree — this is the clone itself

  this session holds:
    fix/login  ~/.aspect/worktrees/github.com/acme/web/aspect-worktree-18a11aa20e8d
    fix/perf   ~/.aspect/worktrees/github.com/acme/web/aspect-worktree-b2697ff9b4e3  (subagent worker-a)

  ended in the last day — released, taken over, or taken back while this session's process had stopped; the commits are on the branch:
    fix/logout  slot f066bb8445cc, 3h 12m ago

  aspect worktree list --all                         every pool on this machine
  aspect worktree add <branch> --create=origin/main  new work in a pooled worktree
```

In a worktree somebody made with `git worktree add` by hand:

```
INFO: this is a git worktree, but not one managed by aspect worktree

  aspect worktree list --all                         every pool on this machine
  aspect worktree add <branch> --create=origin/main  new work in a pooled worktree
```

Outside a repository altogether is a refusal, exit 1, because then there is no pool to be in a slot of:

```
ERROR: not inside a git repository, so not inside a pooled worktree either — `aspect worktree list --all` shows every pool on this machine from anywhere
```

## Using it from a script

The exit code does not distinguish the three cases — two of them are 0 — so a script reads `location`:

```shell theme={null}
aspect worktree inspect --output=json
```

```json theme={null}
{
  "schema_version": 1,
  "in_worktree": true,
  "location": "slot",
  "output_user_root": "/Users/you/Library/Caches/bazel/_bazel_you",
  "pool": "github.com/acme/web",
  "remote": "git@github.com:acme/web.git",
  "slot": { "...": "the same object `list` reports per slot" },
  "held_by_this_session": true,
  "branch": "fix/login",
  "head": "c60f25fe41561431c515bdf847c0c2070f18f55e",
  "head_on_remote": false,
  "uncommitted": [],
  "base": "origin/main",
  "base_sha": "e567ac6b2a18bed22ddf9e220a7e35a62f04e024",
  "upstream": ""
}
```

`base` and `base_sha` are where a branch `add --create` made started — the ref as given and the commit it was, which is the start of a `git bundle` range that a later fetch does not move. `upstream` is what the branch tracks, empty for none. `head`, `head_on_remote` and `uncommitted` are the `checkout:` line as data, `head_on_remote` null where there is no commit checked out; `uncommitted` lists `git status --porcelain` entries, Bazel's own leavings excluded, each `path` named as the file is rather than as git quotes it, and a rename's origin in `from`.

`location` is one of:

| | |
| - | - |
| `slot` | A pooled worktree. `slot` carries the full record |
| `clone` | The clone itself, holding no slot |
| `unmanaged_worktree` | A git worktree this pool does not manage |

`in_worktree` says whether the working directory is in the slot reported: for an unnamed call, true only for `slot`, and for a named one, whether you happen to be standing in it. It cannot distinguish `clone` from `unmanaged_worktree`, which is why `location` exists. For a slot, `held_by_this_session` says whether the lease is yours — subagents sharing their parent's session count as that session, and one given its own `--agent-id` is told a sibling's slot is not. Outside a slot the document also carries `held`: `{slot, branch, path, agent_id, gone}` for each slot this session holds, `agent_id` naming a subagent's and empty for the caller's own, and `gone` true when the slot's checkout directory is gone — `aspect worktree release` of it says why the lease is kept and how to recover the work. And `ended`: `{branch, slot, ended_ms, agent_id}` for each lease of this session, its subagents' included, that ended in the last day — released, taken over, or taken back — on a slot the session no longer holds, `agent_id` naming the subagent and empty for the session's own lease.

## Arguments

<ParamField path="slot" type="string">
  The branch checked out in the slot, the branch a free slot last held, the slot id `aspect worktree list` shows in its first column or a unique prefix of it of four or more characters, or the slot's directory. Omitted, the slot the working directory is in.
</ParamField>

## Flags

<ParamField path="--agent-kind" type="string">
  The agent harness asking, as given to `add` with the same flag. Needed only when the lease was taken with `--agent-kind`; detected otherwise.
</ParamField>

<ParamField path="--agent-id" type="string">
  The session or subagent asking, as given to `add` with the same flag. Needed only when the lease was taken with `--agent-id`; detected otherwise.
</ParamField>

<ParamField path="--output" type="text | json" default="text">
  `text` writes the report to stderr and leaves stdout empty. `json` writes one document to stdout.
</ParamField>

## Refusals

| `error` | Exit | Meaning |
| - | - | - |
| `not_a_repository` | 1 | The working directory is not inside a repository, so no pool applies |
| `no_such_worktree` | 1 | Nothing in the pool answers to the name; the closest name is suggested. `retryable: true` when the slot was released or pruned while being read |
| `invalid_agent` | 1 | `--agent-kind` or `--agent-id` holds characters an id cannot |
| `owned_elsewhere` | 1 | The slot named belongs to another clone of the repository, which is where to run this |
| `slot_stranded` | 1 | The slot named belongs to a clone that is gone; `prune` is all that applies to it |

Unnamed, holding no slot is not a refusal. It exits 0 with `in_worktree: false`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.