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 server::execute).

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.
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.