# NousResearch/hermes-agent · macOS terminal declare -x output leak fixes

## Open now

- Nothing open on GitHub.

Multiple fixes and a bug report addressing a macOS-specific issue where 'declare -x' environment variable output leaks into terminal tool stdout. Approaches include suppressing the output at source and stripping it defensively from terminal output.

## TL;DR

- 6 member(s): 0 open issue(s), 1 closed issue(s), 0 open PR(s), 1 merged PR(s), 4 PR(s) closed without merging.
- A fix was merged to main in PR #16384. Verify it addresses your case.
- **Recommended:** read PR #16384 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `unresolved`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_SPANNING`): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
- Pairwise link density `0.33`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

- #15459: \[Bug\]: \[Bug\]: terminal() tool leaks "declare -x" state-sync output into LLM context window (macOS)

## Prior & competing PRs

- **#16384: fix: strip leaked declare-x env dump from terminal output on macOS (#15459)**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`; implication `superseded`
  - files: `tools/environments/base.py`, `tools/terminal_tool.py`
  - fix hunks:
  - `tools/environments/base.py`

    ```diff
    @@ -386,9 +386,16 @@ def _wrap_command(self, command: str, cwd: str) -> str:
     
             parts = []
     
    -        # Source snapshot (env vars from previous commands)
    +        # Source snapshot (env vars from previous commands).
    +        # Redirect stdout to /dev/null: on macOS (bash 3.2 and certain
    +        # Homebrew bash builds) sourcing a file containing ``declare -x``
    +        # can emit the declarations to stdout, leaking ~60 lines of env
    +        # vars into every tool response (issue #15459).  Linux bash is
    +        # silent here, but the redirect is harmless.
             if self._snapshot_ready:
    -            parts.append(f"source {self._snapshot_path} 2>/dev/null || true")
    +            parts.append(
    +                f"source {self._snapshot_path} >/dev/null 2>&1 || true"
    +            )
     
             # Preserve bare ``~`` expansion, but rewrite ``~/...`` through
             # ``$HOME`` so suffixes with spaces remain a single shell word.
    ```
  - `tools/terminal_tool.py`

    ```diff
    @@ -1851,7 +1851,7 @@ def terminal_tool(
                 # Extract output
                 output = result.get("output", "")
                 returncode = result.get("returncode", 0)
    -            
    +
                 # Add helpful message for sudo failures in messaging context
                 output = _handle_sudo_failure(output, env_type)
     
    ```
- **#15469: fix: strip leaked state-sync output from terminal (defense-in-depth for #15459)**. closed without merge
  - maintainer direction: category `silent_close`; implication `active`
- **#15472: fix: strip leaked declare-x env dump from terminal output on macOS (#15459)**. closed without merge
  - maintainer direction: category `merged_via`; implication `superseded`; refs `#16384`
- **#15474: fix: suppress declare -x stdout leak when sourcing snapshot on macOS**. closed without merge
  - maintainer direction: category `merged_via`; implication `superseded`; refs `#16384`, `#15472`
- **#16385: fix(terminal): suppress declare -x stdout leak when sourcing snapshot on macOS**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `2e6699b31`, `#15472`

## Fix status

- Merged to main in PR #16384 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-04-27`.
