Skip to content

fix: gh run view drops --log-failed, --log, --json flags#159

Merged
pszymkowiak merged 1 commit intortk-ai:masterfrom
shadowofdoom:fix/gh-run-view-passthrough
Feb 17, 2026
Merged

fix: gh run view drops --log-failed, --log, --json flags#159
pszymkowiak merged 1 commit intortk-ai:masterfrom
shadowofdoom:fix/gh-run-view-passthrough

Conversation

@shadowofdoom
Copy link
Contributor

@shadowofdoom shadowofdoom commented Feb 17, 2026

Problem

When the rtk-rewrite hook is active (configured in ~/.claude/settings.json), all gh run commands are transparently rewritten from gh run view <id> --log-failed to rtk gh run view <id> --log-failed.

The view_run() function in gh_cmd.rs only extracts args[0] as the run ID and passes it to gh run viewall subsequent arguments are silently dropped:

// Before (broken)
let run_id = &args[0];
let mut cmd = Command::new("gh");
cmd.args(["run", "view", run_id]);
// ❌ --log-failed, --log, --json never reach gh

This means:

  • gh run view <id> --log-failed → returns only a summary header, not the actual failure logs
  • gh run view <id> --log → same, no logs
  • gh run view <id> --json jobs → no JSON output, just the filtered summary

Users see output like this instead of actual logs:

🏃 Workflow Run #22087167319
  ❌ To see what failed, try: gh run view 22087167319 --log-failed

The irony: rtk tells you to use --log-failed, but rtk itself is the reason it doesn't work.

Root cause

view_run() (line 695) treats args as if it only contains the run ID, ignoring everything after index 0. Unlike list_runs() which does pass extra args through, view_run() was never wired to forward them.

Fix

  1. should_passthrough_run_view(extra_args) — detects when remaining args contain --log-failed, --log, or --json (flags that produce output incompatible with the summary filter)
  2. Early return in view_run() — when passthrough flags are detected, bypass the filter entirely and delegate to a new run_passthrough_with_extra() helper that forwards all args to gh directly
  3. run_passthrough_with_extra() — executes the command with base args + extra args, tracks as passthrough (0% savings, but preserves usage metrics)

When no special flags are present, view_run() continues to use the existing summary filter — no behavior change for the default case.

Test plan

  • 5 new unit tests for passthrough detection logic:
    • --log-failed → passthrough
    • --log → passthrough
    • --json <fields> → passthrough
    • empty args → no passthrough (use filter)
    • --web → no passthrough (use filter)
  • All 12 gh_cmd::tests pass
  • Full cargo test suite passes
  • Manual: rtk gh run view <id> --log-failed shows actual failure logs
  • Manual: rtk gh run view <id> --json jobs returns JSON output

🤖 Generated with Claude Code

view_run() only passed the run ID to `gh run view`, silently
dropping all subsequent args. This made it impossible to inspect
CI failure logs when the rtk-rewrite hook was active.

Add should_passthrough_run_view() to detect flags that produce
output incompatible with the summary filter, and pass through
to gh directly when found.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak pszymkowiak merged commit d196c2d into rtk-ai:master Feb 17, 2026
2 of 3 checks passed
shadowofdoom added a commit to shadowofdoom/rtk that referenced this pull request Feb 18, 2026
view_pr() assumed args[0] was always a PR number, so
`gh pr view --json fields` treated "--json" as the PR identifier
and appended its own --json, causing `Unknown JSON field: "--json"`.

The v0.21.1 fix (should_passthrough_run_view) only covered
`gh run view`. This generalizes it with has_output_format_flags()
and applies it to all handlers that hardcode --json fields:
list_prs, view_pr, pr_status, list_issues, view_issue,
list_runs, and run_repo.

Also fixes view_pr to handle omitted PR number (gh defaults to
current branch).

Closes rtk-ai#159 (broader fix)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
edsai pushed a commit to edsai/rtk that referenced this pull request Feb 19, 2026
view_pr() assumed args[0] was always a PR number, so
`gh pr view --json fields` treated "--json" as the PR identifier
and appended its own --json, causing `Unknown JSON field: "--json"`.

The v0.21.1 fix (should_passthrough_run_view) only covered
`gh run view`. This generalizes it with has_output_format_flags()
and applies it to all handlers that hardcode --json fields:
list_prs, view_pr, pr_status, list_issues, view_issue,
list_runs, and run_repo.

Also fixes view_pr to handle omitted PR number (gh defaults to
current branch).

Closes rtk-ai#159 (broader fix)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
edsai pushed a commit to edsai/rtk that referenced this pull request Feb 19, 2026
view_pr() assumed args[0] was always a PR number, so
`gh pr view --json fields` treated "--json" as the PR identifier
and appended its own --json, causing `Unknown JSON field: "--json"`.

The v0.21.1 fix (should_passthrough_run_view) only covered
`gh run view`. This generalizes it with has_output_format_flags()
and applies it to all handlers that hardcode --json fields:
list_prs, view_pr, pr_status, list_issues, view_issue,
list_runs, and run_repo.

Also fixes view_pr to handle omitted PR number (gh defaults to
current branch).

Closes rtk-ai#159 (broader fix)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
edsai pushed a commit to edsai/rtk that referenced this pull request Feb 19, 2026
view_pr() assumed args[0] was always a PR number, so
`gh pr view --json fields` treated "--json" as the PR identifier
and appended its own --json, causing `Unknown JSON field: "--json"`.

The v0.21.1 fix (should_passthrough_run_view) only covered
`gh run view`. This generalizes it with has_output_format_flags()
and applies it to all handlers that hardcode --json fields:
list_prs, view_pr, pr_status, list_issues, view_issue,
list_runs, and run_repo.

Also fixes view_pr to handle omitted PR number (gh defaults to
current branch).

Closes rtk-ai#159 (broader fix)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
heAdz0r added a commit to heAdz0r/rtk that referenced this pull request Feb 28, 2026
Upstream 0.22.2 sync (all previously missing fixes verified applied):
- fix(lint): propagate linter exit code (rtk-ai#207) — CI false-green fix
- feat: add rtk wc command for compact word/line/byte counts (rtk-ai#175)
- fix(playwright): JSON parser (specs layer) + binary resolution (rtk-ai#215)
- fix(grep): propagate rg exit codes 1/2 (rtk-ai#227)
- fix(git): branch creation not swallowed by list mode (rtk-ai#194)
- fix(git): support multiple -m flags in git commit (rtk-ai#202)
- fix(grep): BRE \| translation + strip -r flag (rtk-ai#206)
- fix(gh): smart markdown body filter for issue/pr view (rtk-ai#214)
- fix(gh): gh run view --log-failed flag passthrough (rtk-ai#159)
- feat(docker): docker compose support (rtk-ai#110)
- feat: hook audit mode (rtk-ai#151)
- feat: tee raw output to file (rtk-ai#134)

Version bump: 0.21.1-fork.19 → 0.22.2-fork.1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants