Execution and environment integration
fnox turns resolved secret values into controlled process environments and active shell state. The command path gives a child process the values it needs, while shell activation keeps the current session aligned with the selected project and profile. The child pages cover command execution and environment injection, environment inspection and serialization, shell hooks and activation, and secret exposure safeguards.
Runtime model
fnox has two main environment targets: a child process started by fnox and the interactive shell that started fnox. The environment policy on each secret controls which target may receive its resolved value.
Resolved secret destinations
The default policy makes a secret available to both commands and the active shell. A command-only policy keeps the value out of the longer-lived shell session. A disabled policy keeps it out of both environment targets.
| Environment mode | Interactive shell | fnox exec child | Other access |
|---|---|---|---|
true or unset | Injected | Injected | — |
"exec" | Not injected | Injected | — |
false | Not injected | Not injected | Value-oriented commands such as fnox get |
The as_file option changes the consumer-facing value from secret text to a private temporary file path. Command files last for the command. Shell files last until fnox replaces or removes them during refresh or deactivation. References: crates/…/config.rs• L212-247, crates/…/config.rs• L523-546, src/…/exec.rs• L11-24, src/…/hook_env.rs• L294-339
Command process boundary
fnox exec resolves the selected profile before it starts the target command. It combines inherited environment values with permitted secrets, removes values that must not cross the boundary, and then starts the command. Callers can limit resolution to selected secrets or request fresh values for named secrets. Lease flows can add short-lived credentials for the target. Explicit secret and lease values take priority over the ambient cleanup set. References: src/…/exec.rs• L116-137, src/…/exec.rs• L58-94, src/…/exec.rs• L176-210, src/child_env.rs• L431-445
The boundary removes fnox's ambient age identity variables and the Enpass master password from the inherited environment. fnox can use those credentials during its own resolution work, but the target does not inherit them unless an explicit secret supplies a value. References: src/…/exec.rs• L11-24, src/child_env.rs• L44-52
On Unix, --replace makes fnox become the target command. This keeps the process identity and sends signals directly to the target. The mode rejects file-backed secrets, leases, and redaction that needs output filtering because those needs require fnox to remain present after setup. References: src/…/exec.rs• L96-104, src/…/exec.rs• L121-161, src/…/exec.rs• L213-221
Command output and signals
Normal execution forwards interrupt and termination signals to the child and returns the child's exit result. When redaction is enabled, fnox filters only non-terminal output streams so interactive terminal behavior remains unchanged. It treats a filtering error as a command failure when the child otherwise succeeds. References: src/…/exec.rs• L224-283, src/…/exec.rs• L285-365
Shell session model
Shell integration follows the user's movement through a project. Activation installs a shell wrapper and a hook. The hook asks fnox for environment changes, then the wrapper applies them in the parent shell because a child process cannot change its caller's environment.
Activation contract
fnox activate emits integration code for Bash, Zsh, Fish, Nushell, or PowerShell. The generated code marks the session, defines a shell-level fnox wrapper, and registers the environment hook unless hook setup is disabled. Commands that must change the current shell, such as deactivation, run through the wrapper. References: src/…/activate.rs• L5-43, src/…/mod.rs• L28-40, src/…/bash.rs• L7-40, src/…/pwsh.rs• L8-47
Eval-based shells receive commands that set and remove variables. Nushell receives structured JSON because it applies environment changes through native commands. Each shell adapter keeps the common hook result separate from shell-specific syntax. References: src/…/mod.rs• L45-86, src/…/nushell.rs• L13-26, src/…/nushell.rs• L107-137
Hook refresh cycle
The hook runs at prompt time or after a directory change, depending on the shell. It finds the applicable configuration, resolves values allowed in the shell, compares them with the prior session, and emits only the changes needed by the parent shell.
The flow below shows how a directory or configuration change becomes shell state.
flowchart LR
A[Prompt or directory change] --> B[hook-env]
B --> C{Tracked input changed?}
C -- No --> D[Return without shell changes]
C -- Yes --> E[Find configuration and profile]
E --> F[Resolve shell-allowed secrets]
F --> G[Compare with prior session]
G --> H[Set added values and unset removed values]
H --> I[Save session state]
I --> J[Apply output in current shell]
The hook tracks the current directory, configuration file times across the hierarchy, and FNOX_* environment changes. It can therefore refresh after a profile or configuration change without manual reactivation. References: src/…/hook_env.rs• L47-83, src/…/hook_env.rs• L105-132, src/hook_env.rs• L154-210, src/hook_env.rs• L268-289
Session state and cleanup
The shell stores an encoded __FNOX_SESSION value so later hooks can identify the prior directory, configuration inputs, secret names, and temporary file paths. It uses keyed hashes for change checks rather than storing secret text. This state also tells deactivation which values and files belong to the session. References: src/hook_env.rs• L9-43, src/hook_env.rs• L45-53, src/hook_env.rs• L98-126
File-backed shell secrets need cleanup beyond the short hook process. Refresh removes files that are no longer needed. Deactivation removes the remaining session files before it clears the session state. A nested Zsh session gets its own file set instead of reusing the parent marker. References: src/…/hook_env.rs• L105-181, src/…/deactivate.rs• L20-41, src/…/zsh.rs• L14-22
Deactivation boundary
fnox deactivate changes only the current shell session. It checks that activation exists, cleans up session-owned files, and emits commands that remove loaded values and the hook. The shell wrapper applies that output in the parent shell and clears the activation markers. References: src/…/deactivate.rs• L8-41, src/…/bash.rs• L65-89, src/…/fish.rs• L60-87, src/…/nushell.rs• L128-137
Integration boundaries
Command execution and shell integration share profile selection and secret resolution, but they apply different destination rules. This lets a short-lived command use env = "exec" without placing that value in the interactive session.
Resolution handoff
Both consumers request resolved values after configuration builds the effective profile secret set. Each consumer then applies its own environment scope and value form. This separation keeps provider resolution common while keeping shell exposure distinct from process exposure. References: src/…/exec.rs• L126-137, src/…/exec.rs• L181-210, src/…/hook_env.rs• L227-281, src/…/hook_env.rs• L298-333
Shell output boundary
hook-env reports values to add, values to remove, and updated session state. Eval-based shells consume generated shell code. Nushell consumes JSON, while PowerShell packages the change summary for prompt handling. The adapter boundary keeps shell syntax out of secret resolution. References: src/…/mod.rs• L51-71, src/…/pwsh.rs• L97-143, src/…/nushell.rs• L107-125
Change checklist
When these files or sections are changed, remember to consider these:
- Update the environment-mode contract in crates/…/config.rs and both consumers when a new destination or policy is added.
- Keep the
hook-envchange format aligned with eval-based shells and structured Nushell output. - Treat
__FNOX_SESSIONfields and its encoded form as a session contract. Preserve safe refresh and deactivation when tracked inputs or file paths change. - Update command-file cleanup and shell-file cleanup together when changing
as_filebehavior. Their lifetimes differ. - Keep activation wrappers and deactivation output aligned when changing which commands must modify the current shell.
- Preserve the ambient credential boundary when changing command setup. Credentials used by fnox must not pass to the target unless policy supplies them.
- Keep signal forwarding, output filtering, and child exit handling aligned when changing the normal execution path.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
fnox exec receives no command | No target process can start | The command path rejects an empty command before resolution. |
A secret marked env = "exec" is expected after activation | The value is absent from the interactive shell by design | Use fnox exec or change the secret's environment mode. |
--replace is used with a file-backed secret, lease, or redaction that needs output filtering | The command is rejected before it runs | Use normal fnox exec when fnox must manage files, leases, or output. |
| A target expects fnox's ambient age identity | The identity is absent from the child environment | Provide an explicit secret if the target needs that credential. |
A tracked directory, configuration, or FNOX_* input changes without a hook refresh | Shell values can become stale | Session tracking causes the hook to refresh when inputs change. |
| Shell resolution fails | The hook warns and leaves an empty loaded set instead of breaking the prompt | Fix the configuration or provider issue before relying on shell values. |
| Deactivation receives a file path outside the session temp area | Cleanup could affect an unrelated file | Cleanup validates session paths before removal. |
| A redacted output stream fails while the child succeeds | The run fails instead of reporting success with lost output | The execution path reports non-pipe output errors as command failures. |
Key files
| File | Why to read it |
|---|---|
| src/…/exec.rs | Primary process boundary for resolving, injecting, filtering, and running commands. |
| src/child_env.rs | Shared environment selection, removal, file planning, and credential boundary. |
| src/…/hook_env.rs | Shell refresh flow, change calculation, and temporary file lifecycle. |
| src/…/activate.rs | Entry point that selects a shell and emits activation code. |
| src/…/deactivate.rs | Current-session shutdown and cleanup boundary. |
| src/hook_env.rs | Session state, change detection, and configuration lookup for hooks. |
| src/…/mod.rs | Shared shell contract and output boundary. |
| src/…/bash.rs | Representative eval-based activation and hook behavior. |
| src/…/zsh.rs | Nested-session and exit cleanup behavior. |
| src/…/nushell.rs | Structured environment output for a shell without eval. |
| crates/…/config.rs | Environment-mode and file-backed secret policy. |
| crates/…/temp_file_secrets.rs | Shared rules for private temporary secret files. |