{"record":{"id":"09ceedc39cba670d","repo":"rtk-ai/rtk","slug":"tree-command-not-found-install-it-first-macos","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/system/tree.rs","lineNumber":16,"sourceCode":"//! tree command - proxy to native tree with token-optimized output\n//!\n//! This module proxies to the native `tree` command and filters the output\n//! to reduce token usage while preserving structure visibility.\n//!\n//! Token optimization: automatically excludes noise directories via -I pattern\n//! unless -a flag is present (respecting user intent).\n\nuse super::constants::NOISE_DIRS;\nuse crate::core::runner::{self, RunOptions};\nuse crate::core::utils::{resolved_command, tool_exists};\nuse anyhow::Result;\n\npub fn run(args: &[String], verbose: u8) -> Result<i32> {\n    if !tool_exists(\"tree\") {\n        anyhow::bail!(\n            \"tree command not found. Install it first:\\n\\\n             - macOS: brew install tree\\n\\\n             - Ubuntu/Debian: sudo apt install tree\\n\\\n             - Fedora/RHEL: sudo dnf install tree\\n\\\n             - Arch: sudo pacman -S tree\"\n        );\n    }\n\n    let mut cmd = resolved_command(\"tree\");\n\n    let show_all = args.iter().any(|a| a == \"-a\" || a == \"--all\");\n    let has_ignore = args.iter().any(|a| a == \"-I\" || a.starts_with(\"--ignore=\"));\n\n    if !show_all && !has_ignore {\n        let ignore_pattern = NOISE_DIRS.join(\"|\");\n        cmd.arg(\"-I\").arg(&ignore_pattern);\n    }\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/rtk-ai/rtk/blob/d977e1c31621fe8704e6500ceeb9c7a0de2b6836/src/cmds/system/tree.rs#L1-L34","documentation":"rtk tree does not reimplement tree in Rust — it shells out to the external `tree` binary via resolved_command(\"tree\") and first checks tool_exists(\"tree\"). If no tree is on PATH it bails with per-distro install instructions before touching anything else.","triggerScenarios":"`rtk tree` (or hook-rewritten `tree`) where tree is not installed: slim Docker images (node:slim, alpine, distroless), minimal CI runners, fresh macOS without brew, or a Nix/devshell that omits the package.","commonSituations":"Containerized dev/CI environments; ephemeral CI agents; hook-rewritten shells where plain `tree` from an agent silently becomes `rtk tree` and fails; portable dotfiles moved to a new machine.","solutions":["Install tree: `brew install tree` (macOS), `sudo apt install tree` (Debian/Ubuntu), `sudo dnf install tree` (Fedora/RHEL), `sudo pacman -S tree` (Arch)","In containers, bake it into the image: `RUN apt-get update && apt-get install -y --no-install-recommends tree`","Without tree, approximate the overview: `rtk proxy fd --type d` or `rtk proxy ls -R | head -100`"],"exampleFix":"# before\nrtk tree\n# tree command not found. Install it first: ...\n\n# after (Ubuntu/Debian)\nsudo apt install tree && rtk tree\n# Dockerfile\nRUN apt-get update && apt-get install -y --no-install-recommends tree","handlingStrategy":"validation","validationCode":"bash:\nif ! command -v tree >/dev/null 2>&1; then\n  echo \"tree missing — falling back to fd directory view\" >&2\n  exec rtk proxy fd --type d --max-depth 3\nfi\nrtk tree \"$@\"","typeGuard":"rust:\nfn tree_available() -> bool {\n    which::which(\"tree\").is_ok()\n}","tryCatchPattern":"rust:\nmatch tree_cmd::run(&args, verbose) {\n    Err(e) if e.to_string().contains(\"tree command not found\") => {\n        let st = std::process::Command::new(\"ls\").arg(\"-R\").status()?;\n        std::process::exit(st.code().unwrap_or(1));\n    }\n    r => r?,\n}","preventionTips":["Add tree to container images: apt-get install -y --no-install-recommends tree","Check `command -v tree` in scripts that call rtk tree on shared machines","Keep an fd/ls fallback for environments you don't control","Remember hooks rewrite bare `tree` to `rtk tree` — the failure can appear far from your own command"],"tags":["tree","system","dependency","environment","path"],"backgroundTag":null,"analyzedSha":"d977e1c31621fe8704e6500ceeb9c7a0de2b6836","analyzedAt":"2026-08-16T05:40:46.291Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}