Skip to content

feat(pty): propagate active sessionId and AGENT_TTY_ACTIVE to spawned processes#166

Open
prmartinow wants to merge 1 commit into
coder:mainfrom
prmartinow:feat/propagate-session-id
Open

feat(pty): propagate active sessionId and AGENT_TTY_ACTIVE to spawned processes#166
prmartinow wants to merge 1 commit into
coder:mainfrom
prmartinow:feat/propagate-session-id

Conversation

@prmartinow

@prmartinow prmartinow commented Jul 11, 2026

Copy link
Copy Markdown

This PR exposes the active session state in the environment of all PTY processes spawned by agent-tty.

Specifically, it injects:

  • AGENT_TTY_ACTIVE=true: A simple boolean flag indicating the command is running inside a managed session.
  • AGENT_TTY_SESSION_ID=<sessionId>: The UUID of the current terminal session.

Why this is useful:

It enables scripts, shell profiles, and automation utilities running inside the virtual terminal to:

  1. Detect the active session and avoid infinite recursion or double-wrapping when invoking shell wrappers.
  2. Reference their own session ID programmatically (e.g. to write markers or log annotations).
  3. Allow custom prompts or terminal styling to visibly indicate that a session is actively being recorded.

Code Changes

src/host/hostMain.ts

Passes sessionId from runHost into createPty options.

src/pty/createPty.ts

  1. Extends PtyOptions with an optional sessionId field.
  2. Updates resolvePtyEnv to accept an optional sessionId.
  3. Injects resolved.AGENT_TTY_ACTIVE = 'true' unconditionally.
  4. Injects resolved.AGENT_TTY_SESSION_ID = sessionId when a sessionId is provided.

test/unit/pty/createPty.test.ts

Adds Vitest unit tests verifying:

  • AGENT_TTY_ACTIVE is unconditionally set to 'true'.
  • AGENT_TTY_SESSION_ID is set to the provided value if present.
  • AGENT_TTY_SESSION_ID is undefined when no sessionId is passed.

Verification & Testing

Verify that all repository formats, lints, types, and tests pass:

npm run format:check
npm run lint
npm run typecheck
npm run test
npm run build

… processes

This exposes AGENT_TTY_ACTIVE=true and AGENT_TTY_SESSION_ID=<sessionId> in the child PTY environment, allowing scripts and utilities inside the session to detect and inspect the active agent-tty context.
@prmartinow prmartinow marked this pull request as ready for review July 11, 2026 15:30
@prmartinow prmartinow force-pushed the feat/propagate-session-id branch from 5f6d685 to dc7679d Compare July 11, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant