Back to blog
IAHomelabSeguridad

Pi 1.7.0 keeps resumed sessions from gaining permissions

Terminal resume keeps the session context and the restrictions Pi started with.

By Isma4 min read

The real issue is not losing the chat

When I close a terminal while working with an agent, losing the conversation is annoying, but it is not the biggest risk. What matters more is avoiding a resumed session with different tools, different instructions, or authentication that was not part of the original setup. That becomes relevant when I move between a local Laravel project, a remote host, and homelab services.

Pi 1.7.0 adds session resume support for terminals that implement the Program Resume Protocol. When such a terminal restarts, it can bring back the active Pi session through a command Pi provides to the terminal. The useful part is that the command carries more than a session identifier.

Resume without widening the boundary

The resume command contains the session ID along with the restriction and resource options used when Pi started. The documentation lists tools, extensions, skills, prompt templates, themes, context files, system prompts, project trust, and --models. In practical terms, a read-only diagnostic session does not come back with a different tool set just because the terminal was restarted.

A basic example is using Pi to inspect a deployment without giving it permission to change anything. If the session is resumed in a compatible terminal, it keeps the tool restriction used at launch. This does not replace operating-system permissions, but it prevents resume itself from quietly changing the working boundary.

pi -t read,grep,find,ls

That is the same restricted tool combination shown in the documentation. It gives me a clean separation between an investigation task and a session where editing code, running migrations, or changing containers is actually intended. The boundary needs to be chosen before the work starts, not left to memory when another terminal opens.

Separate profiles with --agent-dir

Version 1.7.0 introduces --agent-dir <dir>, the command-line equivalent of PI_CODING_AGENT_DIR. It makes it possible to keep independent agent directories instead of putting configuration and authentication under one default location. For work spread across clients, repositories, and personal servers, that separation is more useful than a convenient global profile that is hard to inspect.

Pi includes --agent-dir in the resume command when the directory differs from the default. It also includes --session-dir when sessions live outside the default directory. This matters because a terminal may run the resume command without inheriting the environment that was present when Pi originally started.

pi --agent-dir "$HOME/.pi/homelab/agent" \
  --session-dir "$HOME/.pi/homelab/agent/sessions" \
  -t read,grep,find,ls

With that layout, I can reserve one profile for the homelab and another for a Laravel project without relying on exported variables surviving a restart. Separation does not secure credentials by itself, but it makes the chosen profile and directory visible. That makes it easier to check the setup before the agent connects to a server.

The terminal must trust the command too

Resume is not enabled by wishful thinking. The terminal decides whether it accepts the command, and Pi documents that each flag combination needs its own trust rule. In Rex, for example, the rules must define the full command and keep the flags in the same order in which they were typed.

local id = rex.match.uuid
trust_pi("readonly", "--session", id, "-t", "read,grep,find,ls")
trust_pi("readonly_noext", "--session", id, "-t", "read,grep,find,ls", "--no-extensions")

This may feel strict, but it is the right trade-off. An explicit list of approved combinations is easier to verify than accepting every variation presented by the terminal. When Pi started with a combination that has no matching rule, the terminal does not restore it with weaker restrictions; it falls back to a normal shell.

The fine print

This feature does not preserve everything as though the terminal had never closed. The model, thinking level, and session name remain part of the session, so they are not repeated in the resume command. Pi also removes the resume command after an explicit exit, and it may remove it when a session is opened from another directory while flags contain relative paths.

It also does not work in every terminal emulator. A compatible terminal needs to set OSC7577_TOKEN; Pi only reports resume information when that variable is present. tmux and screen do not forward program-status reports either, so I would test the whole terminal chain before making this part of an operational workflow.

There is one limit worth keeping in mind: repeated flags are not a replacement for system controls. An agent with SSH access, a valid token, or Docker permissions still has whatever capabilities the environment grants it. Pi 1.7.0 improves continuity for the restrictions declared at startup, while real security still depends on separate accounts, narrowly scoped keys, and least-privilege permissions on every server.


Source: Pi v1.7.0 Official documentation: terminal setup and Program Resume

Newsletter

What I learn coding with AI, every two weeks in your inbox.

Real numbers, mistakes included. No spam, unsubscribe in one click.

No spam, unsubscribe in one click. I only use your email to send you this and the newsletter. More in the privacy policy.