Agent environment
Bishop sets the variables below in the agent's environment. They replace any variable of the same name from Bishop's environment or agent.env. Bishop's own BISHOP_ variables, like its interface credentials, are never passed to the agent.
| Variable | Value | Set |
|---|---|---|
BISHOP_VERSION | The running version of Bishop | Always |
BISHOP_THREAD_SCRATCH_DIR | The conversation's scratch directory | Always |
BISHOP_THREAD_STATE_DIR | The directory holding the conversation's turn file | Always |
BISHOP_INTERFACE | slack, teams or gmail. A scheduled prompt gets the interface its report goes to. | Always |
BISHOP_THREAD_ID | Bishop's id for the conversation, like t_…, as the transcript tools return it | Always |
BISHOP_THREAD_PERMISSION_LEVEL | read, write or admin. See permission levels. | Always |
BISHOP_THREAD_VISIBILITY | Who can read the conversation: one-to-one, group, public (anyone in the Slack workspace or the Teams organization can join) or unknown | Always |
BISHOP_THREAD_AUDIENCE | Whether anyone outside the organization can read the conversation: internal, external or unknown | Always |
BISHOP_LOCATION_ID | Bishop's id for the channel or chat, like loc_…, as the transcript tools return it | When the conversation has a location |
BISHOP_LOCATION_EXTERNAL_ID | The platform's id for the channel or chat: the workspace and channel ids in Slack, like T0123:C0456, and the conversation id in Teams | When the conversation has a location |
BISHOP_LOCATION_KIND | The kind of place, in the platform's terms: in Slack channel, group (a private channel) or im (a DM); in Teams channel, groupChat or personal (a one-to-one chat) | When the conversation has a location |
BISHOP_LOCATION_NAME | The channel's name | When the location has a name |
An email has no location, and neither does a Slack group DM. A scheduled prompt gets the values of the channel or chat its report goes to. When the report goes to an email address, it has no location and its visibility and audience are unknown. A reply to its report runs in the report's channel and gets that channel's values.
Changing one of these variables in the agent's shell has no effect on Bishop, which decides what the agent may do from its own records.
unknown means Bishop couldn't work the value out. Some conversations always have unknown values: a Slack group DM has unknown visibility and audience, and a channel too large for Bishop to check every member has an unknown audience.
On the first message of a new conversation, the audience can be unknown. Before it starts the agent, Bishop waits up to five seconds to look up the channel, but doesn't wait for its member list. It keeps what it learns for 24 hours. If the lookup is slow or fails, the location variables come from the channel's id and what Bishop last recorded about the channel, and visibility is unknown until a later lookup succeeds. After a failure, that can take a few minutes. A Slack channel Bishop has never seen has no location variables in that case.
The codex harness gets current values on every message. The claude harness keeps one Claude Code process per conversation between messages, and that process keeps the values it started with until it closes. An audience that was unknown on the first message stays unknown, and a renamed channel keeps its old name, until the process closes.
The turn file
The variables above describe the conversation. To find out who the agent is working for in the current turn, a hook or script reads turn.env in BISHOP_THREAD_STATE_DIR. Bishop rewrites it before the agent receives each turn's messages and leaves it in place until the next turn. It always names the latest turn's senders. Background work the agent started in an earlier turn and is still running sees the newer turn's senders, not the ones who started it.
The file is KEY='value' lines, which a shell loads with set -a; . "$BISHOP_THREAD_STATE_DIR/turn.env"; set +a. A single quote in a value is written the way a shell expects, as '\'', which most dotenv readers don't understand.
| Variable | Value | Set |
|---|---|---|
BISHOP_TURN_ID | Bishop's id for the turn, like trn_… | Always |
BISHOP_TURN_PRINCIPAL_COUNT | How many people or bots sent the messages this turn answers | Always |
BISHOP_TURN_PRINCIPAL_ID__N | Bishop's id for sender N, like p_… | For each sender |
BISHOP_TURN_PRINCIPAL_EXTERNAL_ID__N | The platform's id for the sender: a Slack user id, a Teams user id, an email address | For each sender |
BISHOP_TURN_PRINCIPAL_EMAIL__N | The sender's email address | When the platform gives it |
BISHOP_TURN_PRINCIPAL_KIND__N | person, bot, system or unknown | For each sender |
BISHOP_TURN_PRINCIPAL_AFFILIATION__N | internal, external or unknown | For each sender |
BISHOP_TURN_PRINCIPAL_PERMISSION_LEVEL__N | The sender's permission level | When Bishop knows it |
The file also holds every variable in the table at the top of this page except BISHOP_VERSION. The claude harness keeps a process's environment from when it started, and the file is always current.
A turn can answer several messages, from different senders. Each sender appears once, numbered from 0 in the order they first spoke, and __0 is always set. A scheduled prompt has one sender, Bishop itself, with id p_0 and kind system.
Trusting it
With agent.sandbox on, the agent can read the file but can't change it. Without the sandbox, the agent can change it.
The file is meant for tooling that shouldn't depend on the agent to pass along who asked, like a hook that blocks an action unless a particular person sent the turn. It assumes the agent isn't working against that tooling. A script the agent runs still gets its environment from the agent, so the agent could point BISHOP_THREAD_STATE_DIR somewhere else. For a script that should also check the file is Bishop's, compare its real path with the threads directory, set by the script's author:
threads=/srv/agent/.bishop/threads
file=$(realpath "$BISHOP_THREAD_STATE_DIR/turn.env") || exit 1
state=$(dirname "$file")
[ "$(basename "$file")" = turn.env ] && [ "$(basename "$state")" = state ] &&
[ "$(dirname "$(dirname "$state")")" = "$threads" ] || exit 1Check the exact depth, since the scratch directory is also inside .bishop/threads. A decision that has to hold even against the agent belongs outside the agent's sandbox, the way Bishop runs the API key script.