Skip to content

A session's leaf fails with "No module named leaf" once Claude Code cleans up the copy it loaded #6562

Closed

Description

@max-sixty

In a long-lived Claude Code session, every bare leaf command starts failing once Claude Code cleans up the copy of Leaf the session loaded:

…/bin/python3.12: No module named leaf

A session keeps the copy it loaded on its PATH. After a newer Leaf is installed, Claude Code marks the older copy orphaned (.orphaned_at) and can delete its files while the session still runs. In the session I saw, the cleanup had removed pyproject.toml and most of the tree, and left bin/leaf.

The launcher runs uv run -q --no-dev --project "$root" python -P -m leaf "$@", and the hand-off to the installed copy (session_runtime.hand_off_command) runs inside that Python. So a copy without its project can't hand the command on: uv finds no project at $root and runs whatever python the caller's environment has, which has no leaf module. The session's hooks run the same launcher and fail the same way.

Expected

The session's leaf keeps working, by running the copy installed_plugins.json records, as it does while the session's own copy is whole. The launcher could check for $root/pyproject.toml before uv run and, without it, exec the installed copy's launcher. Failing that, a refusal that names the cause would let the agent find another launcher.

Repro

I hit this in a session whose copy Claude Code had cleaned up. I know no way to trigger that cleanup on demand, so step 3 stands in for it by deleting one of the files it removed.

  1. Start a Claude Code session with Leaf installed.
  2. Install a newer Leaf.
  3. Delete pyproject.toml from the copy the session loaded, as the cleanup did.
  4. Run leaf --version in the session.

Seen on leaf 7b94945, installed 2026-11-19T18:16:20-08:00.

This was written by Claude Code on behalf of max-sixty

Activity

  1. added
    bug
    on Nov 20, 2026
  2. leaf-agent commented on Nov 20, 2026

    @leaf-agent
    Collaborator

    I reproduced this, and #6567 fixes it. Once pyproject.toml is gone, uv run --project runs the caller's python. From outside a checkout that gives No module named leaf. From inside a Leaf checkout it is worse: it quietly runs that checkout's Leaf. Either way the Python hand-off never gets a chance to run.

    With #6567, bin/leaf checks for the project first. If it is missing, it execs the launcher installed_plugins.json records, which is the rule installed_launcher uses, read with jq. If nothing is recorded, it refuses with a message that points to /reload-plugins. A regression test that fails on the old launcher now passes. CI and landing for the PR are still pending.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions