All symptoms日本語

T13

A log that is being written shows 0 bytes

Symptom

A log written by a running process shows 0 bytes in Get-ChildItem. You conclude nothing was written; in fact it holds megabytes.

Check it in 30 seconds

Paste into Windows PowerShell 5.1. It only creates files under your %TEMP% folder. If the last line says REPRODUCED, it happens on your machine. It takes about 25 seconds.

$d = Join-Path $env:TEMP ('cc-trap-' + (Get-Date -Format 'yyyyMMddHHmmss')); New-Item -ItemType Directory $d -Force | Out-Null
$pyv = & python -c "import sys; print('%d.%d.%d' % sys.version_info[:3])" 2>$null
if (-not $pyv) { 'CANNOT CHECK (python not found, or only the Microsoft Store stub: install Python from python.org)' } else {
"python $pyv"
$ad = Join-Path $env:LOCALAPPDATA ('cc-trap-' + (Get-Date -Format 'yyyyMMddHHmmss')); New-Item -ItemType Directory $ad -Force | Out-Null
$log = Join-Path $ad 'w.log'; [IO.File]::WriteAllText($log, '')
[IO.File]::WriteAllText("$d\writer.py", "import sys,time`nf=open(sys.argv[1],'a')`nf.write('x'*5000000)`nf.flush()`ntime.sleep(20)`nf.close()`n")
$p = Start-Process python -ArgumentList "`"$d\writer.py`"", "`"$log`"" -PassThru -WindowStyle Hidden
Start-Sleep -Seconds 5
$listed = (Get-ChildItem -LiteralPath $ad -Filter 'w.log').Length
$fs = [IO.File]::Open($log, 'Open', 'Read', 'ReadWrite'); $real = $fs.Length; $fs.Close()
$p.WaitForExit(); Remove-Item -LiteralPath $ad -Recurse -Force
"listed=$listed real=$real"
if ($listed -ne $real) { 'REPRODUCED' } else { 'NOT REPRODUCED' }
}

Why it happens

Windows may not update the listed size of a file that is still open for writing (reproduced under AppData on the author's machine).

Fix

Open the file and read its length before concluding it is empty.

$fs = [IO.File]::Open($log, 'Open', 'Read', 'ReadWrite')
$fs.Length; $fs.Close()

On the author's machine

listed 0, actual 5,000,000 bytes

Author's machine: Windows 11 / Windows PowerShell 5.1.26100 / Python 3.13.7 / Claude Code 2.1.304, Japanese Windows (code page 932). Checked 2026-10-20 to 22.

If you searched for

Related

cc-win-kit bundles the parts that avoid these traps from the start: a write guard (with onFailure: block), an unattended runner, a doctor that scans your files and hook settings, CLAUDE.md templates and the full test suite.

cc-win-kit ($19 on Payhip)

Other symptoms