rtk-ai/rtk

rtk git diff prepends diffstat, breaking git apply

Open

#1081 opened on Apr 8, 2026

View on GitHub
 (4 comments) (2 reactions) (0 assignees)Rust (48,085 stars) (2,914 forks)batch import
bugeffort-smallfilter-qualitygood first issue

Description

Problem

rtk git diff prepends a diffstat summary before the actual diff output. This breaks git apply because the diffstat lines are not valid patch format.

Example output:

CLAUDE.local.md   | 11 +++++++++++
 src/lib/badges.ts | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/CLAUDE.local.md b/CLAUDE.local.md
index 15f4045..b9901bd 100644
...

The first 3 lines (file stats + summary) are not part of the unified diff format. When piping to git apply, it fails to parse.

Impact

This is particularly problematic when using Claude Code agents in worktrees. The typical workflow is:

  1. Spawn an agent in a worktree
  2. Extract its changes with git diff
  3. Apply the patch to the main worktree with git apply

Step 3 fails because of the prepended diffstat. The current workaround is:

git diff --no-color -U3 2>/dev/null | sed -n '/^diff --git/,$p' > /tmp/patch.patch

Expected behavior

rtk git diff should output a clean unified diff without prepending a diffstat, so the output remains compatible with git apply, git am, and other tools that consume patches.

Alternatively, the diffstat could be sent to stderr instead of stdout.

Environment

  • rtk 0.35.0
  • Hook version: 3 (freshly updated via rtk init -g)
  • macOS (Apple Silicon)
  • Claude Code

Contributor guide