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

# Tutorial 03 - Sessions

> See agent output, interact directly with agents, and learn the difference between on-demand and always-on sessions.

Slinging work to agents creates **sessions** — live agent processes you
haven't seen yet. This tutorial shows you how to watch and talk to them. A
session comes in two flavors:

| Flavor | Lifecycle | Declared by |
| - | - | - |
| **On-demand** | Spun up to handle slung work, shut down when idle | nothing — the default |
| **Always-on** | Kept alive so you can chat anytime | `[[named_session]] mode="always"` in the local pack |

A pack might give these flavors its own role names, but those are pack
configuration, not Gas City concepts. The underlying primitive is the session.

This tutorial continues from the city the last two left off with: `pack.toml`
and `city.toml` at the root, plus the reviewer Tutorial 02 added under
`agents/reviewer/`. The listings below are abbreviated to the parts this
tutorial uses; your files have more in them.

```shell theme={"dark"}
~/my-city
$ cat pack.toml
[pack]
name = "my-city"
schema = 2

# ... yours also has an [imports] table for the packs gc init pulled in

[[named_session]]
template = "mayor"
mode = "always"

~/my-city
$ cat city.toml
[workspace]
provider = "claude"

# ... yours also has [providers], [defaults.rig.imports] and [storage] tables

[[rigs]]
name = "hello-world"   # from the Quickstart
# ...

[[rigs]]
name = "my-project"    # from Tutorial 01
# ...

~/my-city
$ cat agents/reviewer/agent.toml
dir = "my-project"
provider = "codex"     # or whichever provider you chose in Tutorial 02
```

The city's machine-local identity and each rig's path binding live in
`.gc/site.toml` instead, with paths under your own home directory:

```toml theme={"dark"}
workspace_name = "my-city"

[[rig]]
name = "my-project"
path = "/home/you/my-project"   # your absolute path to ~/my-project
```

The reviewer's prompt lives at `agents/reviewer/prompt.template.md`. This is the
standard city shape: root config files plus per-agent directories under
`agents/`.

## Looking in on an on-demand session

Every provider — Claude, Codex, Gemini — manages conversations its own way. Gas
City normalizes all of that behind the **session**: a live process with its own
terminal, state, and conversation history.

Slinging a bead to an agent that isn't running creates a session. To inspect a
live one, look up its ID with `gc session list`, then pass that to `gc session
peek`. (If the reviewer already finished Tutorial 02's review and its session
was cleaned up, the list comes back empty; sling the same review work again for
a fresh live session to watch.)

```shell theme={"dark"}
~/my-project
$ gc session list --template my-project/reviewer
ID       TEMPLATE             STATE     REASON  TARGET        TITLE     WORKDIR                AGE  LAST ACTIVE
gcg-14   my-project/reviewer  creating  create  reviewer-a1b  reviewer  /Users/you/my-project  1s   -

~/my-project
$ gc session peek gcg-14   # use the ID your list printed
› [my-city] my-project/reviewer • 2026-04-07T11:56:59

  # Code Reviewer Agent
  You are an agent in a Gas City workspace. Claim available work and execute it.

  ## Your tools
  - `gc hook --claim --json` — find and atomically claim one work item
  - `bd show <id>` — see details of a work item
  - `bd close <id>` — mark work as done

  ## How to work
  1. Claim work: `gc hook --claim --json`
  2. Read the claimed bead and execute the work described in its title
  3. When done, close it: `bd close <id>`
  4. Check for more work. Repeat until the queue is empty.

  ## Reviewing Code
  Read the code and provide feedback on bugs, security issues, and style.

... # content elided

• Ran gc hook --claim --json
  └ warning: beads.role not configured (GH#2950).
      Fix: git config beads.role maintainer
    … +282 lines
      }
    ]

• The hook claimed one task that is explicitly routed to the reviewer agent:
  mp-p956, “Review hello.py and write review.md with feedback.” I’m pulling the
  bead details and the target file now, then I’ll write the review and close
  that item.

• Explored
  └ List rg --files -g hello.py -g review.md

• Ran bd show mp-p956 --json
  └ [
      {
    … +27 lines
      }
    ]

• Working (43s • esc to interrupt)
```

This sample comes from a reviewer running Codex; with Claude or another
provider you see that provider's interface instead, and the exact text always
varies. Either way, the peek shows the reviewer's prompt — the output of `gc
prime` — landing as the first input to the provider's CLI. That's how Gas City
tells the provider how to act. The agent then claims a ready bead, executes it,
and produces `review.md`.

When the work runs out, the agent goes idle and the GC supervisor shuts its
session down. That's the on-demand default: an agent with no always-on
declaration executes beads, goes idle, and is cleaned up. You could chat with
one while it's alive, but it won't stick around for you.

For an agent that's always there to talk to, you want an always-on session,
declared by the local pack.

## Chatting over an always-on session

`gc session list` shows both flavors side by side — here, the reviewer mid-work
and the mayor up for ten hours (your IDs, ages, and states will differ):

```shell theme={"dark"}
~/my-project
$ gc session list
ID       TEMPLATE             STATE     REASON          TARGET        TITLE     WORKDIR                AGE  LAST ACTIVE
gcg-14   my-project/reviewer  creating  create          reviewer-a1b  reviewer  /Users/you/my-project  1s   -
gcg-2    mayor                active    session,config  mayor         mayor     /Users/you/my-city     10h  14m ago
```

The reviewer will go idle and be shut down once its work is done. The mayor has
been up since the city started, yet nobody has chatted with it — is it burning
tokens? Peek says no:

```shell theme={"dark"}
~/my-project
$ gc session peek mayor --lines 3
...
City is up and idle. No pending work, no agents running besides me. What would
  you like to do?
...
```

Peek captures the session's terminal, not its conversation. `--lines N` reaches
N lines back into the terminal's scrollback and always includes the whole
visible screen, so even `--lines 3` prints a screenful — the tail of the
mayor's last reply plus the provider's input box and footer. Your mayor's words
will differ; what matters is that it's waiting for input, not working.

Idle but not shut down. The mayor survives because the local pack — your
`pack.toml`, the root pack that imports the others — declares an always-on
named session for it:

```toml theme={"dark"}
[[named_session]]
template = "mayor"
mode = "always"
```

That `mode="always"` keeps the session running so the mayor is always around to
chat, plan, or receive work. Any agent the local pack (or a pack it imports)
declares this way gets the same treatment; everything else runs on demand.

To talk to the mayor — or any agent in a running session — attach to it from
an interactive terminal (attach fails with `not a terminal` when run from a
script or another non-interactive shell):

```shell theme={"dark"}
~/my-project
$ gc session attach mayor
Attaching to session gcg-2 (mayor)...
```

And as soon as you do, you'll be dropped into [a tmux
session](https://github.com/tmux/tmux/wiki/Getting-Started):

![mayor session screenshot](https://mintcdn.com/gascityinc-5c0069dd/nVs1BR-I28rczSmX/tutorials/mayor-session.png?fit=max\&auto=format\&n=nVs1BR-I28rczSmX\&q=85\&s=d91f8afce78c337b263d8a162223eed9)

You're in a live conversation. The agent responds just like any chat-based
coding assistant, but with the full context of its prompt template.

To detach without killing the session, press `Ctrl-b d` (the standard tmux
detach). The session keeps running in the background. You can reattach anytime.

You can also reach a running session without attaching. Besides peeking, you
can **nudge** it — type a new message into its terminal:

```shell theme={"dark"}
~/my-city
$ gc session nudge mayor "What's the current city status?"
Nudged mayor   # or a "Queued nudge for mayor ..." line if the session isn't ready yet
```

![mayor nudge screenshot](https://mintcdn.com/gascityinc-5c0069dd/nVs1BR-I28rczSmX/tutorials/mayor-nudge.png?fit=max\&auto=format\&n=nVs1BR-I28rczSmX\&q=85\&s=7a5d517c105a5a1da917c8cd0768aa45)

Confirm the session remains available after the nudge:

```shell theme={"dark"}
~/my-city
$ gc session list
ID      TEMPLATE  STATE   REASON          TARGET  TITLE  WORKDIR             AGE  LAST ACTIVE
gcg-2   mayor     active  session,config  mayor   mayor  /Users/you/my-city  10h  5s ago
```

## Session logs

Peek shows the terminal screen. Logs show the conversation history:

```shell theme={"dark"}
~/my-city
$ gc session logs mayor --tail 5
22:07:29 [USER] <system-reminder> ... [session] What's the current city status?
22:07:32 [ASSISTANT] tool_use: Bash
22:07:34 [USER] tool_result: ok
22:07:35 [ASSISTANT] (no displayable content)
22:07:38 [ASSISTANT] City is up and idle. No pending work, no agents running besides me.
```

This sample is illustrative; your entries, timestamps, and wording will differ.
A few things to recognize:

* A nudge arrives as a `[USER]` entry wrapped in the context Gas City injects
  on each turn, with your text at the end after `[session]`.
* Tool calls (`tool_use`) and their results (`tool_result`) are transcript
  entries too, as are entries with nothing printable, shown as `(no
  displayable content)`.

`--tail N` prints the last N transcript entries (same convention as `tail -n`;
the default is 10), and those tool and empty entries count toward N. If the
agent ran tools while answering, the prompt can fall outside a small window, so
raise N until you see it. Use `--tail 0` for the whole conversation. Follow
live output with `-f`:

```shell theme={"dark"}
~/my-city
$ gc session logs mayor -f
```

Now nudge the mayor from another terminal:

```shell theme={"dark"}
~/my-city
$ gc session nudge mayor "What's the current city status?"
```

The follow stream first prints the most recent entries (the same window
`--tail` would show), then prints the new exchange as it arrives — handy for
watching a background agent without attaching and risking an interruption.
Press `Ctrl-C` to stop following.

> [accordion] Edge: how --tail counts entries
>
> A compact-boundary divider counts as an entry if one lands inside the final
> window. `--tail` counts displayed transcript entries; the HTTP API's `tail`
> query parameter counts compaction segments.

## What's next

You've created sessions on demand, kept the mayor alive with an always-on
`[[named_session]]`, and used peek, attach, nudge, and logs to watch and talk to
agents. From here:

* **[The six primitives](https://docs.gascity.com/getting-started/how-gas-city-works.md)** — the canonical model the
  session and these mechanisms build on
* **[Agent-to-Agent Communication](https://docs.gascity.com/tutorials/04-communication.md)** — how agents
  coordinate through mail, slung work, and hooks
* **[Formulas](https://docs.gascity.com/tutorials/05-formulas.md)** — how multi-step work should be
  done: steps, dependencies, and variables
* **[Beads](https://docs.gascity.com/tutorials/06-beads.md)** — the work tracking system underneath it all


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