anthropics / anthropics/claude-code
[BUG] Bash tool: large-output truncation preview shows stale/unrelated content instead of the actual command output
- Dominant language
- Python
- Stars
- 145k
- Forks
- 23.1k
- PR merge metrics
- PR metrics pending
Description
### Preflight Checklist
- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
### What's Wrong?
## What's Wrong
When a Bash tool call's output exceeds the size threshold that triggers the
"Output too large" truncation behavior, the inline preview block is supposed
to show the first ~2KB of the actual command output (with a note that the
full output was saved to a persisted-output file). Instead, on several
consecutive calls in one session, the preview showed a stale, unrelated
`ls -la` directory listing of the project root — not the output of the
command that was actually run.
The persisted-output file itself was correct: reading it directly (via the
Read tool) returned the real, expected output of each command. So the data
was captured correctly; only the inline preview shown alongside the
truncation notice was wrong. This resolved on its own later in the same
session without any explicit fix.
### What Should Happen?
## What Should Happen
The "Preview (first 2KB)" shown inline should always be the first ~2KB of the
actual stdout/stderr produced by the command that was just run, never
unrelated or cached content from an earlier or different command.
### Error Messages/Logs
```shell
## Error Messages/Logs
Truncation notice format observed:
Output too large (30.7KB). Full output saved to: /tool-results/.txt
Preview (first 2KB):
total 15824
drwxr-xr-x 390 dale.courtney staff 12480 Jul 24 12:14 .
drwxr-x---@ 86 dale.courtney staff 2752 Jul 25 05:47 ..
-rw-r--r--@ 1 dale.courtney staff 57348 Jul 24 05:38 .DS_Store
drwxr-xr-x@ 3 dale.courtney staff 96 Jul 24 13:59 .claude
... (full `ls -la`-style directory listing of the repo root, unrelated to the
git command actually executed)
Reading the same persisted-output file directly at its tail returned the
correct expected content, e.g. for a `git push` call:
To https://gitlab.economicmodeling.com/ltc/it/python-scripts.git
0fa5e158..adca84f8 main -> main
Environment:
- Working directory: /Users/dale.courtney/scripts
- Platform: macOS (Darwin 25.5.0), zsh
- Claude Code CLI (non-interactive/agent SDK session)
```
### Steps to Reproduce
## Steps to Reproduce
1. In a git repo, run a sequence of git commands whose output exceeds the
large-output threshold, e.g.:
- `git status -sb`
- `git diff --stat ...`
- `git commit -m "..."`
- `git push main`
2. Several of these calls return a truncation notice:
`Output too large (XX.XKB). Full output saved to: `
followed by a "Preview (first 2KB)" section.
3. Observe that the preview section shows an `ls -la`-style directory listing
of the repo root (file permissions, sizes, timestamps, filenames) instead
of output related to the command that was run.
4. Read the persisted-output file directly (at or near its tail) and confirm
it contains the correct, expected command output — showing the underlying
data was captured correctly and only the inline preview was wrong.
### Claude Model
Sonnet (default)
### Is this a regression?
I don't know
### Last Working Version
_No response_
### Claude Code Version
Claude 1.24012.9 (03c61d) 2026-07-24T04:59:17.000Z
### Platform
Anthropic API
### Operating System
macOS
### Terminal/Shell
Terminal.app (macOS)
### Additional Information
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the Bash tool's large-output truncation and inline preview path, then compare how the preview is selected with how the persisted-output file is written. Reproduce the sequence of large git commands and confirm that each preview contains the first output from its own command rather than stale content.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, git
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100