Skip to main content

Module reentry

Module reentry 

Source
Expand description

Re-entrancy markers that stop nested lean-ctx invocations from double-compressing — decoupled from the user-facing activation flag.

Two distinct signals were historically conflated in LEAN_CTX_ACTIVE (GH #533), which silently disabled compression for any agent that inherited it:

  • LEAN_CTX_ACTIVE: shell-hook re-entry guard. Stops the shell hook from re-firing inside a command lean-ctx already spawned. It is a plain env var an agent’s top-level process can legitimately inherit.
  • WRAP_MARKER (LEAN_CTX_WRAPPED): process-level ownership. Set ONLY by lean-ctx on the children it spawns, so its presence reliably means “a parent lean-ctx already owns compression of this command tree” and a nested lean-ctx -c must pass through. Because lean-ctx is the only writer, an agent cannot trigger it by leaking an env var.

Functions§

is_wrapped
True when a parent lean-ctx already owns this command tree. Nested explicit lean-ctx -c should defer to the ambient shell defaults, not force raw command bytes, so shell-hook compression can still apply when configured.
mark_child
Stamp a child command so nested lean-ctx invocations pass through and the shell hook does not re-fire: sets both the ownership marker (WRAP_MARKER) and the legacy hook guard (LEAN_CTX_ACTIVE).
should_pass_through
True when lean-ctx -c / -t must avoid owning compression itself: either a parent lean-ctx already owns this command tree (WRAP_MARKER) or compression is globally disabled (LEAN_CTX_DISABLED).