# Koshi 0.2.0 — Session commands (/docs/v0.2/cli/sessions)



A session runs in its own process. These commands start one, join one, leave
one, and end one. The concepts are on
[Attach and detach](/docs/v0.2/using/attach-and-detach).

## Start [#start]

```bash
koshi                        # start and attach this terminal
koshi --profile dev          # start from profile/dev.kdl
koshi --headless             # start with nothing attached
```

`--headless` prints the session id and returns to the shell. Nothing is drawn.

```text
koshi --headless
[SESSION ID]: session-3f2a…
```

## `attach` [#attach]

```bash
koshi attach                 # pick from the running sessions
koshi attach S-amber-fox       # by name
koshi attach session-3f2a…   # by id
```

Run outside koshi, `attach` opens that session in this terminal. Run inside a
koshi pane, it **moves** this terminal to the named session instead.

With no argument and several sessions running, koshi numbers them and reads
your answer:

```text
koshi attach
1) S-amber-fox session-3f2a…
2) S-quiet-heron session-91c4…
attach to which session? [1-2]
```

## `detach` [#detach]

```bash
koshi detach                       # inside a pane: this terminal
koshi detach client-0e5a…          # a client id
koshi detach session-3f2a…         # that session's client, by id
koshi detach S-amber-fox             # the same, by session name
koshi detach --all S-amber-fox       # every terminal of that session
```

Detaching leaves the session running with its panes untouched. Bare
`koshi detach` works only inside a koshi pane. Outside one, name the target: a
client id, a session id, or a session name.

A session left with no terminal keeps running, unless `auto-close-session` is
`#true` in the `koshi.kdl` the session read when it started.

## `kill-session` [#kill-session]

```bash
koshi kill-session                 # the only running session
koshi kill-session S-amber-fox       # by name
koshi kill-session session-3f2a…   # by id
```

Ends the session and everything in it, whatever is attached. An id goes
straight to that session with no lookup. With no argument it works only when
exactly one session is running.

`kill-session` skips the wait that `auto-close-session` gives programs to stop.

| Exit code | Meaning                                 |
| --------- | --------------------------------------- |
| `3`       | Unknown session name or id              |
| `4`       | The control socket could not be reached |

## `list-sessions` [#list-sessions]

```bash
koshi list-sessions
koshi list-sessions --format json
```

Prints session ids and names. See
[Discovery](/docs/v0.2/cli/discovery) for tabs, panes, and clients.

## Summary [#summary]

| Command                            | Result                                                 |
| ---------------------------------- | ------------------------------------------------------ |
| `koshi --headless`                 | Start a session with nothing attached and print its id |
| `koshi list-sessions`              | List session ids and names                             |
| `koshi attach [NAME_OR_ID]`        | Attach this terminal to that session                   |
| `koshi detach [CLIENT_OR_SESSION]` | Detach one terminal; the session keeps running         |
| `koshi detach --all [NAME_OR_ID]`  | Detach every terminal of that session                  |
| `koshi kill-session [NAME_OR_ID]`  | End that session, or the only running one              |
