# client.Client.attached_session

- **Module:** client.Client
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/client.rs#L320
- **Page:** https://libtmux.org/reference/rs/client-client-attached_session/

```
client.Client.attached_session(self) -> Result<Option<crate::Session>, Error>
```

The session this client is attached to.

`None` when the client is attached to nothing, which is an ordinary
state rather than a failure.

Resolved through `#{session_id}` rather than `#{client_session}`. The
latter is what tmux calls the attachment, but it is a *name*, and a
name is not a handle: tmux will create a session called `a:b` and then
refuse to address it, because `:` separates a session from a window in
a target. The ID is unambiguous by construction.

# Errors

Returns an error when tmux cannot be reached, or answers with an ID
this crate cannot parse.

## Example

```rust
let guard = libtmux::test::TestServer::new().await?;
let server = guard.server();
let session = server.new_session("work").await?;

// A control-mode connection is a client, so the server has one to find.
let control = libtmux::control::ControlMode::attach(server, session.id()).await?;
let client = server.clients().await?.into_iter().next().expect("one client");

let attached = client.attached_session().await?.expect("it is attached");
assert_eq!(attached.id(), session.id());
control.shutdown().await?;

guard.shutdown().await?;
```
