Example

Inspect the shell prefix and session environment

Check shellCommandPrefix in both command paths, then inspect the session variables only the model-facing shell receives.

Use Pi 1.0.4 and its built-in Bash tool. You will compare the model’s command with your own ! command. The configuration and manual commands below are an educational adaptation of the existing Chapter 9 tests; the tests remain the canonical executable evidence.

Configure a visible prefix

Merge this fragment into <project>/.pi/settings.json, then run /reload:

{
  "shellCommandPrefix": "export FROM_PREFIX=yes"
}

Pi prepends this prefix to both its built-in bash tool and user-entered ! or !! commands. It runs again before every command. On native Windows, use Git Bash; if needed set shellPath to C:\Program Files\Git\bin\bash.exe with escaped backslashes in JSON. Do not set it to an interactive profile.

Ask the model to run the inspection

Copy the entire command below and ask Pi: Run this with the built-in bash tool and show the output unchanged.

echo "prefix=$FROM_PREFIX"
echo "id=[$PI_SESSION_ID] provider=[$PI_PROVIDER] model=[$PI_MODEL]"
echo "level=[$PI_REASONING_LEVEL] file=[$PI_SESSION_FILE]"

Compare your own command

Enter this in Pi’s editor (the leading ! belongs to Pi, not a shell script):

!echo "prefix=$FROM_PREFIX id=[$PI_SESSION_ID]"

Expected outcome

Path Prefix Session variables
Model invokes built-in bash prefix=yes Pi injects the current session and selected model values
You enter ! or !! prefix=yes Pi does not inject the five session variables

For a clean parent environment, the user-entered command is expected to print:

prefix=yes id=[]

The model-facing output includes a non-empty session ID. Provider, model, reasoning level and persisted session path depend on your session; an ephemeral session has no session-file value. These are expected reader results, not a transcript of your machine. If your parent environment already exports a PI_* variable, a user command may inherit it; non-injection does not promise that inherited variables are absent.

Mechanism and limitations

Documented: pinned shell-aliases.md specifies the prefix and fresh non-interactive shell. environment-variables.md specifies the five variables and the distinction between tool calls and ! / !!. Observed: the canonical ch09-shell/shell.test.ts drives the real Bash tool and executeBash with a scripted provider; its assertions cover the prefix in both paths, model-facing injection, ephemeral sessions and live reasoning-level changes. These tests use Git Bash on Windows in the current verification environment.

An extension that replaces Bash controls its own setup and may bypass this prefix. Selecting PowerShell for the model does not make your ! commands use PowerShell. This example does not demonstrate real-model compliance with your request to run the inspection.

Canonical tests .

Understand this example

Copy this prompt into your AI tool. No code runs here.

Apply this example

Copy this prompt into your AI tool. No code runs here.