Skip to content

bug: hook rewrite of pnpm lint discards package.json script body — same false-green as #185 at the hook layer #2094

Closed as duplicate

Description

@ron332

Summary

The PreToolUse hook rewrites pnpm lint → rtk lint, discarding the body of the project's package.json lint script. For projects whose script enforces flags eslint doesn't default to (e.g. --max-warnings 0) or chains commands (e.g. pnpm check:foo && eslint ...), the rewritten rtk lint invokes eslint with defaults and exits 0 even when the original pnpm lint would have exited 1.

This is the same false-green symptom as #185 (closed) but originates at the hook-rewrite layer, not inside rtk lint. rtk lint --max-warnings 0 exits 1 correctly — #185's fix still holds for explicit invocations.

Affected version

  • rtk 0.42.0 (Homebrew, macOS arm64)
  • Confirmed in both the legacy shell-script hook (~/.claude/hooks/rtk-rewrite.sh produced by older rtk init) and the current in-binary hook (rtk hook claude).

Reproduction

package.json:

{ "scripts": { "lint": "eslint --max-warnings 0" } }

a.ts (one unused-import warning):

import { randomUUID } from 'node:crypto';
export const x = 1;
# What CI runs (raw pnpm script):
pnpm lint a.ts; echo "raw=$?"
# raw=1   ← eslint --max-warnings 0 fails the run

# What Claude Code runs (hook rewrites pnpm lint → rtk lint):
rtk hook check "pnpm lint a.ts"
# → rtk lint a.ts
rtk lint a.ts; echo "hooked=$?"
# hooked=0  ← false green; --max-warnings 0 was dropped

For confirmation that rtk lint itself is fine when flags are explicit:

rtk lint --max-warnings 0 a.ts; echo $?
# 1   ← propagation is correct when the flag is passed

Impact

Reaches every user who hasn't typed rtk lint themselves. The hook makes pnpm lint the de facto path through which agentic CLI tools (Claude Code, Cursor, etc.) validate before pushing. Local pre-push reports green; CI fails on the dropped flag.

In our team this caused a hotfix PR after a clean local check (keryx#2824 — "Local lint reported the same warning but the wrapper masked the non-zero exit code"). Net cost: ~15 minutes per occurrence plus an additional PR to unblock the deploy.

Affects any project whose lint script:

  • chains commands (pnpm check:foo && eslint ...), or
  • enforces flags eslint doesn't default to (--max-warnings 0, --report-unused-disable-directives, etc.).

Suggested fixes (any one resolves)

  1. Stop rewriting pnpm lint / pnpm tsc / pnpm test / npm run <X>. These names point at project-defined script bodies whose contents the hook can't see. Substituting rtk <subcommand> discards user intent. Users can still type rtk lint explicitly when they want it. Smallest possible diff — a registry edit.

  2. Resolve the script body before rewriting. When the hook matches pnpm lint, read package.json's scripts.lint, then rewrite as rtk lint <resolved-script> so the user's chain runs faithfully with rtk summarizing on top. Retains rtk's value; more code.

  3. Default rtk lint to --max-warnings 0 when no explicit --max-warnings is given. Matches the de facto CI convention; documents itself in rtk lint --help. Minor behavior change for users with permissive eslint setups.

Option 1 is the cheapest and matches the principle of least surprise — pnpm lint is project-defined, not a known shape rtk can transform safely.

Local workaround

For users hitting this today, a 15-line shell shim around rtk hook claude resolves it without touching rtk:

#!/bin/bash
# rtk-hook-shim.sh — short-circuits the `pnpm lint` rewrite, delegates
# everything else to `rtk hook claude`.

if ! command -v rtk &>/dev/null || ! command -v jq &>/dev/null; then
  exit 0
fi

INPUT=$(cat)
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')

case "$CMD" in
  "pnpm lint"|"pnpm lint "*|"pnpm run lint"|"pnpm run lint "*|"npm run lint"|"npm run lint "*)
    exit 0
    ;;
esac

echo "$INPUT" | rtk hook claude

Point ~/.claude/settings.json PreToolUse:Bash hook at this shim instead of rtk hook claude.

Related

Same class of bug recurring at the wrapper layer:

There may be value in a wrapper-level invariant test: for every command in the rewrite registry, assert rtk <cmd> exit code matches the raw invocation across documented flag combinations. Happy to contribute that test pattern if welcome.

Activity

  1. ron332 commented on May 26, 2026

    @ron332
    Author

    Addendum: pnpm test has the same class of bug

    After filing this, auditing the project's package.json turned up a second affected script:

    { "scripts": { "test": "NODE_OPTIONS='--max-old-space-size=4096' vitest run" } }

    The hook rewrites pnpm test → rtk vitest run, dropping the NODE_OPTIONS env var. Any project relying on a heap-size bump for large test suites will silently lose it. The failure mode here is OOM during test runs rather than a false-green, but it's the same root cause: the hook can't see the script body so it substitutes a known shape that may not match.

    General pattern: any pnpm <script-name> / npm run <script-name> rewrite is unsafe by construction, because package.json scripts are project-defined strings that can prefix env vars, chain with &&, pipe, or compose in ways the hook registry can't anticipate.

    The local workaround shim in the original report has been extended to cover pnpm test / npm test / npm run test as well.

  2. added
    bug
    help wanted
    on May 27, 2026
  3. pszymkowiak commented on May 27, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 93%

    Summary

    PreToolUse hook rewrites pnpm lint → rtk lint, silently dropping package.json script flags (e.g. --max-warnings 0), producing false-green lint results; fix by removing npm/pnpm script names from the rewrite registry

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.


    Triaged automatically by wshm · This is an automated analysis, not a human review.

  4. wilmerdooley commented on Jul 1, 2026

    @wilmerdooley

    I opened #2776 to address this. The details are in the PR; happy to adjust based on what you'd prefer.

  5. added 2 commits that reference this issue on Jul 22, 2026
    3bb0ff3
    e9093be
  6. added a commit that references this issue on Aug 14, 2026
    54542e9
  7. added 2 commits that reference this issue on Sep 21, 2026
    2f342a0
    5f42886
  8. KuSh commented on Oct 3, 2026

    @KuSh
    Collaborator

    Closing as a duplicate of #1489, which tracks the same rule: package scripts named lint (npm run lint, pnpm lint) are rewritten to rtk lint and lose the script body. The fix there covers pnpm lint too, and PR #2860 is linked from here. Please add anything further on #1489.

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

    area:clibughelp wantedpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions