rtk-ai / rtk-ai/rtk

`rtk stats` exits 127 with opaque "No such file or directory (os error 2)" and produces no output

Open
#3,263 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area:cli bug priority:high
Dominant language
Rust
Stars
81.1k
Forks
5.1k
Avg merge
4d 21h
Merged PRs (30d)
35

Description

rtk stats exits 127 with opaque "No such file or directory (os error 2)" and produces no output

Summary

rtk stats (all flags) exits 127 immediately, emitting only [rtk: No such file or directory (os error 2)] to stderr and zero stdout — no info line, no partial table. This reproduces on both 0.43.0 and the just-released 0.44.0. The sibling rtk gain command works perfectly and appears to cover every output dimension stats is documented to provide.

This looks like a spawn failure at stats startup (it dies before any output, even before the [info]/[warn] lines other commands emit). The binary's error strings include Child process missing / Failed to capture child stdout / Failed to capture child stderr / failed to spawn thread, and the error message does not name the program it failed to spawn — which makes this hard to self-diagnose (cf. #2634, #2843 for the same "unattributed spawn failure" class).

Environment

rtk 0.43.0, reproduced again on 0.44.0 (Homebrew, homebrew-core formula)
OS macOS 26.5.2 (Darwin 25.5.0), Apple Silicon
node v26.4.0
npx / npm present (/opt/homebrew/bin/npx, /opt/homebrew/bin/npm)
ccusage not installed globally (rtk falls back to npx ccusage, which resolves ccusage 20.0.18)
shell zsh

Reproduction

$ cd /tmp            # neutral cwd, no project filters involved
$ rtk stats
[rtk: No such file or directory (os error 2)]
$ echo $?            # 127

Captured streams — both empty except the one stderr line:

$ rtk stats >/tmp/stats.out 2>/tmp/stats.err ; echo "rc=$?"
rc=127
$ cat /tmp/stats.out     # (empty)
$ cat /tmp/stats.err
[rtk: No such file or directory (os error 2)]

Every flag fails identically (the crash is upstream of flag handling):

--daily      rc=127
--weekly     rc=127
--monthly    rc=127
--graph      rc=127
--history    rc=127
--quota      rc=127
--all        rc=127
--format json rc=127

What works (so the data + DB are fine)

rtk gain reads the same history.db and succeeds across all dimensions, so this is not a database-path or permissions problem:

$ rtk gain              # rc=0 — Tokens saved: 1.3M (88.2%), 640 commands
$ rtk gain --graph      # rc=0
$ rtk gain --daily      # rc=0
$ rtk gain --weekly     # rc=0
$ rtk gain --monthly    # rc=0
$ rtk gain --history    # rc=0
$ rtk verify            # 154/154 tests passed

Notably, rtk cc-economics — which does shell out to ccusage — also succeeds on 0.44.0 (prints the $ Spent (ccusage) breakdown). On 0.43.0 cc-economics did fail with a ccusage JSON-schema error (missing field 'month'), which 0.44.0 fixed. stats, however, fails on both versions and never even reaches a ccusage info line, so its failure is a different, earlier bug than the (now-fixed) ccusage schema mismatch.

Expected behavior

Either:

  • rtk stats works and prints the savings summary, or
  • if a required external binary is genuinely missing, it fails with an actionable, attributed error (e.g. rtk stats: required program 'X' not found on PATH — install via …) instead of the opaque os error 2.

Suggested root-cause / fix direction

stats appears to Command::new(...) some helper at startup that isn't present on this machine, and the spawn error is propagated without naming the program. Two asks:

  1. Name the program in the spawn-failure error (same fix as proposed in #2634), so users can tell what is missing.
  2. Make the ccusage/economics dependency lazy or optional for statsstats should degrade gracefully (or skip the cost-comparison section) when ccusage can't be fetched/parsed, rather than exiting 127 with no output. rtk gain already proves the core savings table can be produced from history.db alone.

Workaround (confirmed)

Use rtk gain (+ --graph/--daily/--weekly/--monthly/--history). It covers the documented stats output and is fully functional.


Reported from a real Gr.kivm install; happy to run any debug build / RTK_VERBOSE / RUST_LOG trace if a maintainer points me at the right env flag — I couldn't find a documented verbose/trace toggle for stats.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing rtk stats with the listed flags and comparing its startup behavior with the working rtk gain command, using the issue's history.db and ccusage details as context. Trace which external spawn occurs before output and how its error is propagated. Done means stats either produces its savings output or reports the missing program by name and handles unavailable ccusage gracefully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.