# session.Session.from_env

- **Module:** session.Session
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/session.rs#L152
- **Page:** https://libtmux.org/reference/rs/session-session-from_env/

```
session.Session.from_env(server: &crate::Server) -> Result<Option<Self>, Error>
```

Find the session this process is running in.

Resolved through the pane, because `TMUX_PANE` names exactly one pane
while a server's `TMUX` value names the session that was current when
the client attached, which may since have changed.

`Ok(None)` means tmux no longer has that pane.

# Errors

Returns an error when `TMUX_PANE` is absent or is not a pane ID, or
when the listing fails.

## Example

```rust
use libtmux::{Pane, Session};

let session = server.new_session("locating-session").await?;
let pane = session.panes().await?.remove(0);

// Standing in for the environment tmux gives a process it starts.
let found = Session::from_env_value(server, Some(pane.id().as_ref())).await?;

assert_eq!(found.expect("the session exists").id(), session.id());
```
