Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

When mux launches from Applications (not terminal), agent bash commands get a minimal PATH (/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin) missing user tools like Homebrew, nix, direnv, pyenv, etc.

The standard ~/.bashrc isn't sourced because:

  1. bash -c creates a non-interactive shell
  2. Most bashrc files have [[ $- != *i* ]] && return guards that skip content

Solution

Add a dedicated ~/.mux/bashrc file that is always sourced before every bash command, following the existing pattern of:

  • ~/.mux/AGENTS.md — global agent instructions
  • <project>/.mux/init — project initialization hooks

Use Cases

# ~/.mux/bashrc

# Nix + direnv (auto-loads .envrc per workspace)
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
  . "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
eval "$(direnv hook bash)"

# Homebrew (macOS)
eval "$(/opt/homebrew/bin/brew shellenv)"

# Or any version manager: pyenv, rbenv, nvm, asdf

Implementation

  • LocalRuntime.exec() prepends bashrc sourcing to all commands
  • SSHRuntime.exec() prepends bashrc sourcing (uses remote ~/.mux/bashrc)
  • Init hooks also source bashrc for consistency
  • Silently skipped if file doesn't exist

Testing

  • Unit tests for the bashrc snippet
  • Integration test that verifies env vars from bashrc are available

Fixes #797


Generated with mux

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

When mux launches from Applications (not terminal), agent bash commands
get a minimal PATH missing user tools. The standard ~/.bashrc isn't
sourced because:

1. `bash -c` creates a non-interactive shell
2. Most bashrc files have interactivity guards that skip content

This adds a dedicated ~/.mux/bashrc file that is always sourced before
every bash command, allowing users to set up:

- PATH modifications (Homebrew, ~/bin, etc.)
- Nix profile sourcing
- direnv hooks (auto-loads .envrc per directory)
- pyenv/rbenv/nvm/asdf initialization

Implementation:
- LocalBaseRuntime.exec() prepends bashrc sourcing to all commands
- SSHRuntime.exec() prepends bashrc sourcing (uses remote ~/.mux/bashrc)
- Init hooks also source bashrc for consistency

The snippet uses `[ -f $HOME/.mux/bashrc ] && . $HOME/.mux/bashrc || true`
to ensure commands don't fail when the file doesn't exist.

Fixes #797

_Generated with mux_
Copy link

@tko tko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever. I can see this can potentially make all kinds of things convenient if it works.

Comment on lines +55 to +56
# Enable direnv (auto-loads .envrc per directory)
eval "$(direnv hook bash)"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

direnv hook bash sets PROMPT_COMMAND which I believe means that direnv will not be activated until bash prompt is shown, which is never when running commands with bash -c

Assuming bashrc is sourced from the project directory with .envrc file then I guess running direnv export bash instead might work better (it's what direnv hook seems to run.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PATH is missing user folders

2 participants