---
title: "alpacon work-session"
description: "Create, inspect, and manage Alpacon work sessions from the CLI. Learn the session lifecycle, operations per scope, session selection, and access error codes."
---

> Full documentation index: https://docs.alpacax.com/llms.txt

# alpacon work-session

Create, inspect, and manage work sessions for server access.

## Usage

`alpacon work-session [flags]`

`alpacon work-session [command]`

## Key facts

- `session` is an alias for `work-session`.
- Request the servers and scopes your work needs with `create`.
- Use `current` to check the workspace’s default session.

## Flags

| Flag | Type | Description | Default |
| --- | --- | --- | --- |
| `-h, --help` | `bool` | help for work-session | `false` |
| `--output` | `string` | Output format: table or json | `table` |

## Examples

Create a session and start work

```bash
# 1. Check whether your authentication requires a work session
alpacon whoami

# 2. Create a session, wait for approval, and set it as your active session
alpacon work-session create --purpose "nginx fix" --scope command,websh \
  --server web-01 --expires-in 2h --wait --use

# 3. Work as usual—gated commands attach to the active session automatically
alpacon exec web-01 systemctl status nginx
alpacon websh web-01
```

For the concepts behind these commands, see [Work sessions](/use/work-sessions/).

## Lifecycle

```
pending → approved → active → completed | expired | revoked
        ↘ rejected | cancelled
```

- A session starts as **pending** and must be approved before use. Superusers' own requests are approved automatically, except sessions an AI agent requests, which by default wait for a person.
- An approved session becomes **active** when its start time arrives, or immediately with [`activate`](/reference/cli/work-session/activate/).
- A session ends when you [`complete`](/reference/cli/work-session/complete/) it, when it expires, or when a superuser runs [`revoke`](/reference/cli/work-session/revoke/).
- A pending request can also be **rejected**, or withdrawn by its requester with [`cancel`](/reference/cli/work-session/cancel/) (**cancelled**). Undecided requests are also canceled when their requested end passes or the pending limit is reached (24 hours by default), whichever comes first.

## Gated operations

When you sign in with browser login, the following operations require an active work session that includes the matching scope. The token exception covers only non-interactive `exec`, `cp`, `edit`, and `websh SERVER "command"`. Tokens cannot open interactive Websh or tunnels; sign in with `alpacon login` without `-t` to use them.

New personal API tokens cannot hold command-execution or file-transfer scopes. Existing tokens with those scopes keep working without a work session. Use a [service token](/use/iam/applications/service-tokens/) for automation and CI.

| Scope | Gated operations |
|-------|------------------|
| `websh` | `alpacon websh` (interactive terminal; tokens refused) |
| `command` | `alpacon exec` (including `exec logs`), `alpacon websh SERVER "command"` |
| `webftp` | `alpacon cp`, `alpacon edit` |
| `tunnel` | `alpacon tunnel` (tokens refused) |
| `sudo` | Privilege elevation; sudo command patterns declared with `--sudo` |
| `editor` | Code editor on the Alpacon web interface (not gated in the CLI) |

Run [`alpacon whoami`](/reference/cli/whoami/) to check whether your authentication requires a work session and which session is active.

## Selecting a session

Gated commands resolve which work session to attach to in this order:

1. The `--work-session` flag on the command
2. The `ALPACON_WORK_SESSION` environment variable
3. The workspace's active session set with [`alpacon work-session use`](/reference/cli/work-session/use/)

## Gate errors

When a gated command is denied, `alpacon exec`, `alpacon websh`, `alpacon cp`, and `alpacon edit` exit with code **3** and print a diagnostic with suggested next steps. With `--output json`, the diagnostic is printed to stderr as machine-readable JSON—fields include `error_code`, `reason`, `context`, and `next_actions`—so scripts and AI agents can recover automatically.

| Error code | Meaning |
|------------|---------|
| `work_session_required` | No work session selected for this shell |
| `work_session_not_active` | Session not yet active (check its start time) |
| `work_session_expired` | Session has expired |
| `work_session_scope_not_allowed` | Operation not in the session's scopes |
| `work_session_server_not_allowed` | Target server not in the session |
| `work_session_assignee_mismatch` | Session assigned to another principal |
| `work_session_not_usable` | Session is no longer usable |
| `work_session_agent_session_required` | The CLI is running under an AI agent; select an agent work session and pass its ID with `--work-session` |
| `work_session_account_not_approved` | The account is not the one approved for the session; use the approved account or request a session for the required account |

## Related commands

  
    Create a new work session
  
  
    List work sessions
  
  
    Show details of a work session
  
  
    Set or clear the active work session
  
  
    Show the active work session
  
  
    Approve in the console or Slack, then track status via CLI
  
  
    Reject in the console or Slack, then track status via CLI
  
  
    Withdraw your own pending session request
  
  
    Activate an approved session
  
  
    Extend a session's expiry
  
  
    Update session fields, or add sudo command patterns
  
  
    Mark an active session as completed
  
  
    Force-terminate a session (superuser only)
  
  
    Show a session's activity timeline
  
  
    Show a Websh session recording

Source: https://docs.alpacax.com/reference/cli/work-session/
