Free space on my C drive kept shrinking every time I looked. The culprits were .codex and .claude in my user folder, where Codex and Claude Code keep their chat logs: about 41GB together. They grew by about 22GB in October and by about 20GB in just the first 8 days of November. At that rate my 512GB SSD would fill up within months.
Short answer: copy the chat log folders to drive D and leave a “junction” in the original place, a folder entry that points somewhere else. The apps keep their settings, the data leaves C.
I tripped up four times along the way. The least obvious one: even with its window closed, Codex starts in the background as soon as you sign in, and keeps .codex in use. Below is the script I actually used, with those four problems fixed.
After the move, C:\Users\<user>\.codex is just a junction (an entry point) and the contents (about 33GB of chat logs and more) live in D:\ai-home\.codex. The path the apps see doesn’t change.
What was using the space
Breakdown on November 8 (C drive 476GB, 142GB free):
| Folder | Size | Contents |
|---|---|---|
.codex |
37.9GB | Codex chat logs, working files and more |
of which visualizations |
18.1GB | Files Codex produced while working. Every version of my Live2D working files (about 400MB each) was kept |
of which sessions |
14.6GB | Conversation records. The largest single conversation alone was several GB |
.claude |
3.4GB | Claude Code settings and conversation records |
Claude Code stays small because it clears out old transcripts after 30 days by default. Its documentation says transcripts in ~/.claude/projects/ are kept for 30 days by default, adjustable with cleanupPeriodDays (Data usage - Claude Code Docs). My .codex\sessions, on the other hand, still had conversations from September, when I started. Keep a long task going in one conversation and its record grows to several GB.
Why a junction instead of environment variables
There are official ways to move these folders. Codex reads CODEX_HOME to relocate its settings, logs and conversations (the folder has to exist first). Claude Code stores settings and history under CLAUDE_CONFIG_DIR when it’s set (Environment variables - Codex, Settings - Claude Code Docs).
I still went with a junction, for two reasons:
- Codex starts in many ways: the desktop app, the CLI, the VS Code extension, plus background processes. With an environment variable you have to make sure every one of them picks up the new value. With a junction they all use the same path, so there’s nothing to worry about
- Easy to undo: remove the junction, put the kept original folder back under its old name, done
You can make a junction with mklink /J or PowerShell’s New-Item -ItemType Junction (mklink - Microsoft Learn, New-Item - Microsoft Learn). The destination drive must be NTFS. My drive D used to be exFAT, so I reformatted it as NTFS first.
Four things that tripped me up
The script below already handles all four. Here they are, so you don’t hit them.
1. robocopy stopped right away with exit code 16
My first run wrote the robocopy log into D:\ai-home before that folder existed. robocopy then has nowhere to write its log, so it quits with exit code 16 without copying anything. The script now makes the folder first. More on exit codes: robocopy exit codes explained.
2. File counts didn’t match
After copying, PowerShell’s Get-ChildItem counted 18,990 files on C but 19,368 on D. I never fully worked out why. robocopy’s list mode (/L, which only reports differences without copying) found zero differences. robocopy compares with the same rules it copies with, so verification is now its job.
3. “The folder is in use” when moving it aside
Copy and verification passed, then moving .codex aside failed. The Codex window was closed and nothing obvious showed in Task Manager.
It turned out Codex starts by itself in the background when you sign in, and its background processes (such as the codex.exe app-server) were holding .codex. On my PC these were running: several codex.exe, codex-computer-use-swift.exe, codex-windows-sandbox-service.exe (a service), plus the node.exe of the Codex runtime. With them stopped, moving the folder aside worked. Once the move was done, I started the service again.
4. One empty file existed only on D
On a retry after an interrupted run, a 0-byte .codex-provisioning-….guard file existed only on D, and verification reported a difference. It seems to be a marker Codex makes only while running. I changed the copy from /E to /MIR (make D exactly match C), which removes extra files on D. Because /MIR deletes extra files at the destination, always use a brand-new, dedicated destination folder.
Before moving: back up and check
The script keeps the originals on C under a new name (for example .codex_C-old) instead of removing them. Still, it copies all your chat logs, so take a backup first: a copy of .codex, .claude on an external disk is enough.
First see how big they are. Paste this into PowerShell for sizes in GB (on PCs without long path support it may undercount, so treat it as a rough figure):
foreach ($n in '.codex','.claude') { $s = (Get-ChildItem "$env:USERPROFILE\$n" -Recurse -Force -File -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum; "{0}: {1:N1} GB" -f $n, ($s / 1GB) }
Also check that the destination drive is NTFS: FileSystemType should be NTFS.
Get-Volume -DriveLetter D
Script to move the chat logs to D
This is the script I arrived at by trial and error on a PC where I use AI tools every day. Feel free to use it. It does this:
- Checks that the destination is NTFS and isn’t a folder already used for something else
- Finds Codex, Claude and VS Code processes and the Codex service, lists them, and stops them when you press
y(this catches background Codex too) - Copies to D with robocopy
/MIR, then checks with/Lthat D matches C exactly - Moves the original folder on C aside (for example
.codex_C-old) and puts a junction in its place - Restarts the services it stopped
If any step fails, it stops and C stays as it was. Before publishing, I ran it end to end on dummy folders, including a rerun plus the undo steps. With a file in use, or with an existing folder as the destination, it stopped without touching C.
What to change
| Where | Default | Change to |
|---|---|---|
$destRoot (near the top) |
D:\ai-home |
The destination. Use a new folder name that doesn’t exist yet; an existing folder’s contents would be deleted |
$names (right below it) |
.codex, .claude |
To move just one, leave out the other |
Paste it into Notepad and save it as move-chatlogs-to-d.ps1.
# Move chat logs (.codex / .claude) from C to D and leave a junction in the original place
# Run in PowerShell opened as administrator, not from a terminal inside VS Code, Claude Code, Codex
$ErrorActionPreference = "Stop"
# Destination (a new folder that does not exist yet)
$destRoot = "D:\ai-home"
# Folders to move
$names = @(".codex", ".claude")
$marker = Join-Path $destRoot "_chatlog-move-marker.txt"
function Stop-WithMessage($msg) {
Write-Host $msg -ForegroundColor Red
Read-Host "Press the Enter key"
exit 1
}
# --- 1. Check the destination
$v = Get-Volume -DriveLetter $destRoot[0] -ErrorAction SilentlyContinue
if (-not $v -or $v.FileSystem -ne "NTFS") { Stop-WithMessage "The destination drive is not NTFS. Stopping." }
if ((Test-Path -LiteralPath $destRoot) -and -not (Test-Path -LiteralPath $marker) -and @(Get-ChildItem -LiteralPath $destRoot -Force).Count -gt 0) {
Stop-WithMessage "$destRoot is already in use for something else. Its contents would be deleted, so choose a new folder name."
}
# Make the log folder first; without it robocopy stops with exit code 16
New-Item -ItemType Directory -Path $destRoot -Force | Out-Null
Set-Content -LiteralPath $marker -Value "Destination folder for moved chat logs" -Encoding UTF8
# --- 2. Stop Codex, Claude, VS Code (including Codex running in the background with its window closed)
$procs = @(Get-Process -ErrorAction SilentlyContinue | Where-Object {
$_.ProcessName -match '^(codex.*|claude|Code)$' -or ($_.Path -and $_.Path -match "\\OpenAI\.Codex") -or ($_.Path -and $_.Path -match "\\Claude-NativeHost\\")
})
$svcs = @(Get-Service -ErrorAction SilentlyContinue | Where-Object { $_.Name -match "codex" -and $_.Status -eq "Running" })
if (($procs.Count + $svcs.Count) -gt 0) {
$procs | Format-Table Id, ProcessName, Path -AutoSize | Out-Host
$svcs | Format-Table Name, DisplayName -AutoSize | Out-Host
if ((Read-Host "Stop the processes/services above, then continue? (y/n)") -ne "y") { Stop-WithMessage "Cancelled. C is unchanged." }
$svcs | Stop-Service -Force
$procs | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 3
}
# --- 3-4. Copy, verify, swap in the junction
$moved = 0
foreach ($n in $names) {
$src = Join-Path $env:USERPROFILE $n
$dst = Join-Path $destRoot $n
$old = Join-Path $env:USERPROFILE ($n + "_C-old")
Write-Host "== $n" -ForegroundColor Cyan
$item = Get-Item -LiteralPath $src -Force -ErrorAction SilentlyContinue
if (-not $item) { Write-Host " Not found, skipping."; continue }
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) { Write-Host " Already moved, skipping."; continue }
if (Test-Path -LiteralPath $old) { Stop-WithMessage " $old already exists. Look inside it before going further." }
# Copy: /MIR makes D identical to C. Extra files on D go away, C stays untouched.
Write-Host " Copying files to D..."
robocopy $src $dst /MIR /COPY:DAT /DCOPY:DAT /R:1 /W:1 /NP /NFL /NDL /LOG:"$destRoot\move_$n.log" | Out-Null
if ($LASTEXITCODE -ge 8) { Stop-WithMessage " Copy failed, robocopy exit code $LASTEXITCODE. A file may be in use: close the apps, then retry. C is unchanged. Log: $destRoot\move_$n.log" }
# Verify: run again in list mode (/L) and check that the exit code is 0 (no differences)
# Get-ChildItem counts can miss files without long path support; robocopy is more reliable here
robocopy $src $dst /L /E /COPY:DAT /DCOPY:DAT /R:0 /W:0 /NP /NJH /NDL /LOG:"$destRoot\verify_$n.log" | Out-Null
if ($LASTEXITCODE -ne 0) { Stop-WithMessage " D does not match C, robocopy exit code $LASTEXITCODE. C is unchanged. Log: $destRoot\verify_$n.log" }
Write-Host " Verified: D matches C."
# Keep the original as a backup under a new name; a junction takes its place
try { Move-Item -LiteralPath $src -Destination $old }
catch { Stop-WithMessage " Cannot move $src aside because it is in use. An app is still running. C is unchanged." }
New-Item -ItemType Junction -Path $src -Target $dst | Out-Null
if (-not (Test-Path -LiteralPath (Join-Path $src "."))) {
cmd /c rmdir "$src"
Move-Item -LiteralPath $old -Destination $src
Stop-WithMessage " Could not create the junction, so everything was put back."
}
Write-Host " Done: $src -> $dst" -ForegroundColor Green
$moved++
}
# --- 5. Restart the services that were stopped
$svcs | Start-Service -ErrorAction SilentlyContinue
Write-Host ""
if ($moved -gt 0) {
Write-Host "Finished. Start Codex / Claude Code, then check that your past conversations are there." -ForegroundColor Green
Write-Host "The original folders (.codex_C-old / .claude_C-old) are still on C. Delete them after a few days without problems."
} else {
Write-Host "No folders needed moving."
}
Read-Host "Press the Enter key"
Right-click the Start button, open “Terminal (Admin)”, and run this (change the path to where you saved it). Admin rights are needed to stop the Codex service.
powershell -NoProfile -ExecutionPolicy Bypass -File "D:\move-chatlogs-to-d.ps1"
It lists the processes it will stop; check them and press y. You should see “Verified” then “Done” for both .codex and .claude, then “Finished” at the end. On my PC .codex was 19,368 files / 33.4GB and .claude 3,876 files / 3.9GB, both with zero differences. .claude took 29 seconds to copy.
Checking after the move
Start Codex and Claude Code; if your past conversations are listed, you’re good. To confirm the junctions, run this. LinkType should be Junction and Target the folder on D.
Get-Item "$env:USERPROFILE\.codex", "$env:USERPROFILE\.claude" -Force | Select-Object FullName, LinkType, Target
Clean up the old folders (this is when C gets space back)
Note: moving alone doesn’t free space on C, because the originals are kept as .codex_C-old and .claude_C-old. On my PC those two take about 37GB.
After a few days of normal use, with your conversation list and new conversations working, remove them. This is permanent, so make sure your backup is there. Run this in PowerShell. Codex sometimes puts junctions inside .codex, so use rmdir /s /q, which doesn’t follow junctions inside the folder (my .codex_C-old had one).
cmd /c rmdir /s /q "%USERPROFILE%\.codex_C-old" cmd /c rmdir /s /q "%USERPROFILE%\.claude_C-old"
One side effect: robocopy follows a junction it finds inside .codex, so on D that spot becomes a normal folder holding a copy of the contents. Verification still passes, and the original junction stays in .codex_C-old.
Be careful not to target .codex itself (the junction). I’m still keeping my old folders for now, just in case.
To go back, remove the junction, then give the old folder its original name again. rmdir only removes the junction itself; the contents on D stay as they are.
cmd /c rmdir "%USERPROFILE%\.codex" Move-Item "$env:USERPROFILE\.codex_C-old" "$env:USERPROFILE\.codex"
A word about backups
Chat logs also don’t mix well with File History. If .codex and .claude are included, multi-gigabyte files get saved in full every hour and fill the backup drive. My roughly 42GB of logs had become about 444GB inside File History: see File History filled my backup drive: Claude Code and Codex logs.
Now that they live on D, the chat logs are included in my daily backup of drive D to the NAS. Other C drive cleanup (tracking down space that folder sizes don’t show) is in C drive full but folders don’t add up? Find the hidden space.
Summary
- Codex and Claude Code chat logs (
.codex,.claude) pile up in your user folder. On my PC they reached about 41GB and grew by over 20GB a month - Copying them to D with a junction at the old path frees C, with no app settings to change
- Codex runs in the background once you sign in, even with its window closed, and keeps
.codexin use. Stop it before moving the folder - Verify with robocopy
/L(counting withGet-ChildItemgave different totals on C and D) - C only gets space back once the kept old folders are gone. Only clear them out after a few days of normal use

コメント