Skip to content

[BUG] Shell snapshot drops __-prefixed functions, breaking cd when used with mise #25824

@rafal-krypa

Description

@rafal-krypa

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

When Claude Code is launched from a shell where mise is activated (https://mise.jdx.dev/), every command that uses cd fails with:

bash: command not found: __zsh_like_cd

mise activate bash defines a helper function __zsh_like_cd() and wraps cd, pushd, and popd to call it (this is how mise detects directory changes to switch tool versions).

Claude Code's shell snapshot mechanism (~/.claude/shell-snapshots/snapshot-bash-*.sh) captures the cd(), pushd(), and popd() wrapper functions but does not capture __zsh_like_cd(). The snapshot also drops _mise_hook() and the chpwd_functions array.

It appears the snapshot logic filters out functions whose names start with __ (double underscore), but it keeps the functions that depend on them, leaving the shell in a broken state.

What Should Happen?

cd should work normally. The snapshot should either:

  1. Include all functions regardless of naming convention (including __-prefixed ones), or
  2. Exclude functions that depend on other functions it filters out, or
  3. Not snapshot shell functions that wrap builtins like cd/pushd/popd

Error Messages/Logs

bash: command not found: __zsh_like_cd

Steps to Reproduce

  1. Install mise and add eval "$(mise activate bash)" to ~/.bashrc
  2. Open a terminal (so mise is activated)
  3. Launch claude
  4. Run any command that uses cd, e.g. ask Claude to run cd /tmp && ls
  5. Observe the __zsh_like_cd: command not found error

Evidence from the snapshot file:

The snapshot contains the cd wrapper (base64-encoded):

eval "$(echo 'Y2QgKCkgCnsgCiAgICBfX3pzaF9saWtlX2NkIGNkICIkQCIKfQo=' | base64 -d)"
# Decodes to: cd () { __zsh_like_cd cd "$@" }

But __zsh_like_cd is completely absent from the snapshot file.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.42

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

Workaround: Add this to the end of ~/.profile:

# Workaround: Claude Code's shell snapshot captures cd/pushd/popd
# wrappers from mise but drops __zsh_like_cd. Provide a minimal fallback.
if ! declare -f __zsh_like_cd >/dev/null 2>&1; then
    __zsh_like_cd() { builtin "$@"; }
fi

This issue likely affects any tool that defines __-prefixed helper functions in bash (not just mise). The snapshot's function filtering is too aggressive - it breaks the dependency chain between captured and filtered functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingplatform:linuxIssue specifically occurs on Linux

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions