Skip to main content

Crate agentmux_bashwrap

Crate agentmux_bashwrap 

Source
Expand description

agentmux-bashwrap — streaming bash wrapper for AgentMux agents.

Two subcommands:

  • exec — runs a user-supplied command inside an owned PTY, streams stdout/stderr line-by-line to the AgentMux sidecar’s MPS broker (HTTP), and prints the aggregated output on its own stdout for Claude’s native Bash tool to capture as tool_result.

  • hook — reads a PreToolUse JSON payload on stdin. When the CLI’s shell prefix is this binary, it records the call for the prefix process and changes nothing. Otherwise it emits a hook response that rewrites the command so Claude’s native Bash invokes agentmux-bashwrap exec instead, the command base64-encoded into the rewrite argv so quoting + multi-line bodies survive.

  • prefix mode (one argument: the CLI’s script) — Claude Code’s CLAUDE_CODE_SHELL_PREFIX. Runs the script the way exec runs a command, for the call the hook recorded. See prefix.rs and docs/specs/SPEC_BASH_STREAMING_VIA_SHELL_PREFIX_2026_10_10.md.

  • precompact — registered as Claude Code’s PreCompact hook. Fires the instant compaction begins; pings the sidecar’s MPS broker with a compaction_started event so the UI can show live status instead of a silent gap. See precompact.rs and docs/specs/SPEC_COMPACTION_DETECTION_AND_HANDLING_2026_07_31.md.

  • askpass mode (no subcommand) — ssh’s SSH_ASKPASS when AgentMux runs ssh for an agent: shows ssh’s prompt to the user through srv and prints the answer. See askpass.rs.

  • git-credential <op> and github-token -- <gh args> — GitHub tokens for an agent’s git and gh, from srv. See github.rs.

  • github-container -- <gh args> — a container’s gh pr merge (srv does it) and the raw gh api writes its token cannot make (refused, with the command that does the job). See container_verbs.rs.

  • git-hook <name>, git-env -- <git args> and github-owner-tag -- <gh args> — the guards and attribution on an agent’s pushes and commits. See git_hooks.rs, secret_scan.rs.

  • github-text-guard -- <gh args> — the scan of the text an agent’s gh sends (PR, issue and comment text) for credentials. See github_text.rs.

  • sessionstart --part N — registered as Claude Code’s SessionStart hook, once per part. Delivers part N of the agent’s memory as the hook’s additionalContext. See sessionstart.rs and docs/specs/SPEC_GLOBAL_MEMORY_DELIVERY_2026_09_27.md §7 P2.

See docs/specs/SPEC_STREAMING_BASH_RUNNER_2026_05_11.md for the full design rationale (why command rewrite vs. MCP deny-redirect, why a separate binary vs. extending an MCP server, channel correlation by tool_use_id, etc).

Modules§

askpass 🔒
askpass mode: ssh runs $SSH_ASKPASS "<prompt>" and reads the answer on stdout. When AgentMux runs ssh for an agent it points SSH_ASKPASS here and sets AGENTMUX_ASKPASS_SECRET on that ssh only; this asks srv (POST /api/v1/askpass), which shows the prompt to the user, and prints their answer. The secret, not anything here, decides whose prompt it is (srv’s backend::remote::askpass).
aws 🔒
AWS credentials for a container agent’s SDK or CLI, as AWS’s standard credential_process. Spec: docs/specs/SPEC_CONTAINER_AGENT_AWS_CREDENTIALS_2026_10_31.md §12.
bash_timeout 🔒
The timeout of a Bash call, set by the PreToolUse hook so the agent is free after 30 seconds.
bash_wrap 🔒
exec subcommand — runs the user’s bash command and streams chunks.
container_verbs 🔒
The gh commands a container agent cannot run with its own token, and what it does instead.
cwd_state 🔒
Where an agent’s Bash calls start: the working directory a call ends in is kept for the next one, per instance and, for a Claude Code subagent, per subagent (docs/specs/SPEC_BASHWRAP_PER_AGENT_CWD_2026_10_18.md). Moved out of bash_wrap.rs, which runs the calls.
exec_args 🔒
The arguments of agentmux-bashwrap exec, also built by prefix mode for a call it runs (prefix.rs). Moved out of bash_wrap.rs, which runs the call.
gh_shim 🔒
gh as a program, for the callers the gh shell function never reaches.
git_hooks 🔒
What runs around an agent’s git commit and git push when its GitHub access goes through AgentMux.
github 🔒
GitHub tokens for an agent’s git and gh.
github_text 🔒
The text scan: what an agent’s gh is refused for when the text it sends holds a credential.
hook 🔒
hook subcommand.
idle_gate 🔒
Is a command that has printed nothing for the idle timeout stuck, or busy?
mps_client 🔒
Thin HTTP client for publishing MPS events to the AgentMux sidecar.
precompact 🔒
precompact subcommand.
prefix 🔒
Prefix mode: agentmux-bashwrap '<script>' as Claude Code’s CLAUDE_CODE_SHELL_PREFIX.
publish_scan 🔒
A container agent’s push, judged by the host’s publish guard.
secret_scan 🔒
The push scan: what an agent’s git push is refused for.
sessionstart 🔒
sessionstart subcommand — registered as Claude Code’s SessionStart hook, once per part (--part 1 … --part 8). Delivers the agent’s memory (docs/specs/SPEC_GLOBAL_MEMORY_DELIVERY_2026_09_27.md §7 P2).
shim_functions 🔒
Makes the build-slot shims win in the shells this wrapper starts.

Structs§

Cli 🔒

Enums§

Command 🔒

Functions§

init_tracing 🔒
Initialize tracing to write to ~/.agentmux/logs/bashwrap-debug.log at INFO by default. Writing to a file instead of stderr means:
main 🔒