Shell Function Inheritance Issue - Zoxide and Dynamic Functions Fail in Bash Tool
Claude Code Bug Report: Shell Function Inheritance Issue with Zoxide
Bug Summary
Claude Code's Bash tool execution environment fails to properly inherit/execute shell functions, specifically breaking zoxide functionality that depends on __zoxide_z and related functions.
Environment
- Claude Code Version: 1.0.18
- OS: Linux (WSL2) - Ubuntu on Windows
- Shell: zsh 5.9
- Kernel: Linux 6.6.87.2-microsoft-standard-WSL2
- Zoxide Version: 0.9.8 (installed at ~/.local/bin/zoxide)
Expected Behavior
When zoxide is properly configured in ~/.zshrc with eval "$(zoxide init zsh)", the cd command should work seamlessly using zoxide's smart directory jumping functionality.
Actual Behavior
$ cd /some/path
z:1: command not found: __zoxide_z
Reproduction Steps
- Install zoxide:
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash - Add to ~/.zshrc:
eval "$(zoxide init zsh)" - Source ~/.zshrc:
source ~/.zshrc - In normal terminal:
cd some_pathworks perfectly - In Claude Code Bash tool:
cd some_pathfails with "command not found: __zoxide_z"
Investigation Results
What Works in Normal Shell
$ zoxide --version
zoxide 0.9.8
$ which zoxide
/home/chris/.local/bin/zoxide
$ type __zoxide_z
__zoxide_z is a shell function from ~/.zshrc
What Fails in Claude Code Bash Tool
$ zoxide --version
zoxide 0.9.8
$ type __zoxide_z
z:1: command not found: __zoxide_z
$ eval "$(zoxide init zsh)"
# Appears to execute without error, but functions are not available
Root Cause Analysis
The issue appears to be that Claude Code's Bash tool execution context:
- Does not properly inherit shell functions defined in ~/.zshrc
- Cannot execute
evalstatements that define shell functions dynamically - Persists broken aliases even after unalias/unset attempts
Technical Details
Zoxide Initialization Code
When zoxide init zsh runs, it generates shell functions like:
function __zoxide_z() {
if [[ "$#" -eq 0 ]]; then
__zoxide_cd ~
elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
__zoxide_cd "$1"
else
\builtin local result
result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -- "$@")" && __zoxide_cd "${result}"
fi
}
Failed Workarounds Attempted
- Manual function definition: Functions defined but not accessible
- Re-sourcing ~/.zshrc: No effect in Claude Code context
- Direct eval execution: Appears to succeed but functions unavailable
- Clearing completion cache:
rm ~/.zcompdump*; compinit- no effect - Alternative initialization:
zoxide init zsh --no-cmd- same issue
Impact
This affects any development workflow that relies on:
- Zoxide for smart directory navigation
- Any shell functions defined in user configurations
- Dynamic shell function generation via
eval
Expected Fix
Claude Code's Bash tool should:
- Properly inherit shell functions from the user's shell environment
- Support dynamic function definition via
eval - Maintain function persistence across command executions within the same session
Workaround
Created fix script at /mnt/c/ats/ph1t/fix_zoxide.sh that manually defines functions, but this doesn't address the underlying shell inheritance issue.
Business Impact
This significantly impacts developer productivity in Claude Code, as modern shell productivity tools (zoxide, starship, fzf integration) rely on shell functions that don't work in Claude Code's execution environment.
Supporting Files
- Zoxide fix script:
/mnt/c/ats/ph1t/fix_zoxide.sh - Shell configuration:
~/.zshrc(contains proper zoxide initialization)
Additional Context
This issue was discovered during integration testing of a Neovim plugin (Maxi.nvim) where directory navigation was failing consistently in Claude Code but working perfectly in normal terminal sessions.
This issue has 12 comments on GitHub. Read the full discussion on GitHub ↗