Skip to main content

Module agent_runtime_env

Module agent_runtime_env 

Source
Expand description

Bridge agent runtime/session environment variables across lean-ctx processes.

The lean-ctx MCP server is a long-lived child of the agent host. Some agents (notably Codex) expose runtime/session variables such as CODEX_THREAD_ID only in the native agent shell environment, not in the MCP server process (#370). ctx_shell runs inside the MCP server, so it cannot forward those variables by reading its own std::env.

Short-lived lean-ctx processes that do run inside the agent environment — the hook handlers (lean-ctx hook …) and the lean-ctx -c shell wrapper — capture the relevant variables into a small file in the data dir. The MCP server then loads them when constructing the child environment for ctx_shell (see crate::server::execute).

Constants§

FORWARD_PREFIXES
Env var name prefixes identifying agent runtime/session state worth forwarding to ctx_shell child processes.

Functions§

capture
Capture forwardable variables from the current (agent) environment into the data dir so the MCP server can forward them to ctx_shell children.
collect_from_process
Forwardable variables present in the current process environment.
is_credential_shaped
Whether key looks like a secret/credential that must never be forwarded or persisted, regardless of any matching forwardable prefix.
is_forwardable
Whether key is an agent runtime variable lean-ctx forwards to child shells.
load
Load captured agent runtime variables, honoring the freshness TTL.