rtk-ai/rtk · error

tree command not found. Install it first: - macOS: brew…

Error message

tree command not found. Install it first:
- macOS: brew install tree
- Ubuntu/Debian: sudo apt install tree
- Fedora/RHEL: sudo dnf install tree
- Arch: sudo pacman -S tree

What it means

`rtk tree` delegates to the external `tree` binary and compresses its output. If the binary is not present on PATH (checked via tool_exists), rtk fails fast with a per-platform install hint instead of producing degraded output.

Solutions

  1. Install tree per the platform in the message: macOS `brew install tree`, Ubuntu/Debian `sudo apt install tree`, Fedora/RHEL `sudo dnf install tree`, Arch `sudo pacman -S tree`.
  2. Verify it is now reachable: `which tree` / `tree --version` (check PATH if still missing).
  3. Use a built-in fallback if you cannot install: `find . -maxdepth 2 | sort` or `ls -R`, or `rtk proxy find ...` for tracked raw output.
  4. Bake the tree package into your Dockerfile/CI setup script so environments are reproducible.

Example fix

// before
rtk tree .   # fails: tree command not found
// after
brew install tree    # or: sudo apt install tree
rtk tree .
Defensive patterns

Strategy: fallback

Validate before calling

command -v tree >/dev/null 2>&1 || { echo 'tree is required: brew/apt/dnf/pacman install tree' >&2; exit 1; }
rtk tree .

Type guard

fn tree_available() -> bool { std::process::Command::new("tree").arg("--version").output().is_ok() }

Try / catch

match rtk_tree_result {
    Err(e) if e.to_string().contains("tree command not found") => {
        eprintln!("falling back to find-based listing");
        run("find . -maxdepth 2 | sort")?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running `rtk tree <path>` on a machine where the `tree` executable is not installed or not on PATH; calling tree::run in containers/minimal images that lack the package.

Common situations: Fresh macOS (tree removed from default installs since Homebrew best practice), minimal Docker images (alpine/slim Debian) without the tree package, CI runners with a bare toolchain, wrong PATH in nix/venv/custom environments.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/09ceedc39cba670d. Report an issue: GitHub.

Appendix: source

Thrown at src/cmds/system/tree.rs:16

//! tree command - proxy to native tree with token-optimized output
//!
//! This module proxies to the native `tree` command and filters the output
//! to reduce token usage while preserving structure visibility.
//!
//! Token optimization: automatically excludes noise directories via -I pattern
//! unless -a flag is present (respecting user intent).

use super::constants::NOISE_DIRS;
use crate::core::runner::{self, RunOptions};
use crate::core::utils::{ChildArgExt, resolved_command, tool_exists};
use anyhow::Result;

pub fn run(args: &[String], verbose: u8) -> Result<i32> {
    if !tool_exists("tree") {
        anyhow::bail!(
            "tree command not found. Install it first:\n\
             - macOS: brew install tree\n\
             - Ubuntu/Debian: sudo apt install tree\n\
             - Fedora/RHEL: sudo dnf install tree\n\
             - Arch: sudo pacman -S tree"
        );
    }

    let mut cmd = resolved_command("tree");

    let show_all = args.iter().any(|a| a == "-a" || a == "--all");
    let has_ignore = args.iter().any(|a| a == "-I" || a.starts_with("--ignore="));

    if !show_all && !has_ignore {
        let ignore_pattern = NOISE_DIRS.join("|");
        cmd.arg("-I").arg(&ignore_pattern);
    }

View on GitHub (pinned to 0924356b4c)