A RAM disk on Windows 11 gives Claude Code, VS Code and your test runner a fast, disposable place for scratch files. Set up the way this guide shows, it is created at every boot before anyone signs in, it is reachable at an ordinary folder path, it cleans itself on every restart, and it never holds anything that matters.
An AI coding agent at work produces a steady stream of throwaway files: test temp folders, scratch scripts, staging copies, logs and test output. So does a busy VS Code session with a test suite. This article builds a self-cleaning home for all of it with the free OSFMount driver and two PowerShell scripts, shows how to point Claude Code and VS Code at it, and is honest about what it will and will not speed up. It also covers the Windows pitfalls we hit while building it, which most RAM disk guides skip.
Who this is for: developers and system administrators running Claude Code, VS Code, or both on a Windows 10 or Windows 11 workstation. Nothing here depends on a server or a hosting plan.
- Why use a RAM disk on Windows 11 for scratch and testing
- How the setup fits together
- Pros and cons of a RAM disk for scratch work
- What you need
- Step 1: Install OSFMount
- Step 2: Create the RAM disk with RamDisk.ps1
- Step 3: Create it at every startup
- Step 4: Point Claude Code and VS Code at it
- Windows pitfalls we hit while building it
- Verify it after a restart
- Undo it
- FAQ
Why use a RAM disk on Windows 11 for scratch and testing
A RAM disk is a drive that lives in memory instead of on an SSD. Windows sees an ordinary NTFS volume with a drive letter, but every file on it sits in RAM, and the whole volume disappears when the machine restarts. For most data that is a fatal flaw. For scratch data it is the point.
Agents and test runners create files nobody needs tomorrow. Left on the project drive they pile up in temp folders, show up in searches, clutter the repository, and quietly eat disk space (if you have ever wondered why a dev folder is far larger than its source, our guide to checking folder size in Windows Explorer shows where to look). Giving that output its own volatile drive solves the clean-up problem by design: a restart is the clean-up.
The scripts in this article make that drive dependable rather than a one-off experiment:
- It is created at every boot by a scheduled task running as SYSTEM, before anyone signs in.
- It is reachable at a normal folder path,
C:\Claude\RamDisk, through a directory junction, so any tool that wants a folder can use it. - It is wiped on every restart, so scratch never accumulates.
- It is clearly labelled and documented as disposable, so nobody (human or agent) mistakes it for real storage.
What it will and will not speed up
Set expectations before you start. On a modern NVMe SSD, the speed gain from a RAM disk is modest. It shows up mostly in small-file-heavy steps: creating and deleting temp folders, writing many small files, unpacking and throwing away staging copies. Work that is bound by CPU or by process start-up, such as a large test suite, does not get noticeably faster, because the disk was never the bottleneck.
The clearer wins are elsewhere: scratch that disappears on every restart, fewer writes to the SSD, and no scratch build-up on the project drive. We have deliberately not published benchmark figures here; if you want numbers, measure your own workload before and after, on your own hardware.
One more factor: Microsoft Defender still scans files written to the RAM disk. Excluding the RAM disk from scanning would be the single biggest speed-up for small files, but it is a security trade-off. That decision is yours, and it is covered in the FAQ rather than recommended here.
How the setup fits together
Two scripts do the work. RamDisk.ps1 creates, checks or removes the RAM disk. Install-RamDiskStartup.ps1 registers a scheduled task that runs RamDisk.ps1 at every startup. The figure shows what happens between power-on and the moment Claude Code or VS Code writes its first scratch file.
From power-on to a ready scratch folder
The startup task builds the RAM disk before anyone signs in, so every tool finds the same folder waiting.
- Windows startsNo one needs to sign in.
- Scheduled task firesRuns as SYSTEM 30 seconds after boot; retries 3 times, a minute apart.
- RamDisk.ps1 -IfMissingChecks memory headroom, then asks OSFMount for a RAM-backed disk.
- R: is mountedNTFS, labelled Scratch, with four folders and a README.
- Junction is linkedC:\Claude\RamDisk points at R:\ for Claude Code, VS Code and pytest.
Pros and cons of a RAM disk for scratch work
A RAM disk is a good fit for some files and a dangerous one for others. Weigh both columns before you set one up.
RAM disk for scratch and testing: pros and cons
The strongest arguments are hygiene and SSD wear, not raw speed.
Pros
- Self-cleaningEvery restart wipes it, so temp folders and stale test output never pile up.
- Fewer SSD writesChurn from temp files, staging copies and logs stays off the SSD.
- Cleaner project driveScratch has one obvious home outside the repository.
- Faster small-file workCreating and deleting many small files is quicker, though the gain over NVMe is modest.
- Works with any toolThe junction gives it a normal folder path; no tool needs to know about R:.
Cons
- VolatileRestart, removal or a stopped driver loses everything on it, instantly.
- Uses memoryUp to 4 or 8 GB of RAM is unavailable to everything else once it fills.
- Limited speed-upCPU-bound and process-start-bound work, like a big test suite, barely changes.
- Defender still scansExcluding it is faster but widens your attack surface.
- Another moving partA third-party driver, admin rights and a startup task to maintain.
The rule that follows from the cons is simple: the RAM disk holds only files you would be happy to lose at any moment.
| File type | On the RAM disk? | Why |
|---|---|---|
| Scratch scripts and one-off experiments | Yes | Disposable by nature |
Test temp folders (pytest --basetemp) | Yes | Recreated on every run |
| Test output and logs you only read once | Yes | Copy out anything you need to keep |
| Staging and mutation copies | Yes | Rebuilt from the source on demand |
| Uncommitted work | Never | A restart deletes it with no recovery |
| Git worktrees or clones | Never | Easy to forget work-in-progress inside them |
| The only copy of anything | Never | RAM is not storage |
If your agents and test runs regularly push a workstation out of memory, the RAM disk is a sign you have outgrown it. A dedicated machine with memory to spare, such as one of our bare metal servers, provisioned automatically from live inventory, gives long-running agents and CI jobs room without competing with your desktop.
What you need
- Windows 10 or Windows 11, 64-bit.
- Administrator rights, to install OSFMount and to create or remove the RAM disk.
- Spare memory: the script refuses to create the disk unless at least 8 GB of physical memory would still be free after it fills. That means 12 GB free for a 4 GB disk and 16 GB free for an 8 GB disk, which is comfortable on a 32 GB workstation and tight on a 16 GB one.
- Windows PowerShell 5.1 (built into Windows). The scripts are written for it.
- A folder for the scripts. This guide uses
C:\Claude\tools.
Step 1: Install OSFMount
OSFMount is a free tool from PassMark Software. Download it from the official OSFMount page and install it with the defaults. The current release supports Windows 10 and 11, is 64-bit only, and needs administrator privileges. It was originally based on the ImDisk driver.
The installer adds a command-line tool, OSFMount.com, in C:\Program Files\OSFMount. It refuses to run without elevation, even just to list mounts or show its help. The switches the script uses come from its built-in help:
-a -t vm -s <size> -m <drive>: -o <options>creates a RAM-backed disk.-o logical,rw,format:ntfs:<label>formats the new disk as NTFS with that label.-d -m <drive>:dismounts it, and-Dforces the dismount.-llists mounts.
A RAM disk created from an elevated window or by SYSTEM appears in normal, non-elevated sessions too: the drive letter is global. That is what lets a startup task running as SYSTEM create a drive your everyday account can use.
Step 2: Create the RAM disk with RamDisk.ps1
Save the script below as C:\Claude\tools\RamDisk.ps1. Run without switches from an elevated PowerShell, it:
- creates an NTFS RAM disk labelled Scratch at
R:(4 GB by default, or 8 GB with-SizeGB 8); - adds the folders
Scratchpads,Temp,TestOutputandpytest, plus a README that warns the contents are disposable; - links
C:\Claude\RamDisktoR:\with a directory junction.
Its other switches:
-Statusshows what is mounted and linked, and works in a normal, non-elevated window.-Removerefuses while files are on the disk unless you add-Force, and removes only the link, never the files behind it.-IfMissingmakes it safe to run again: if the RAM disk is already mounted it only checks the link.-LogPathappends the run’s output to a log, and any error ends the run with exit code 1.-DriveLetterand-LinkPathchangeRandC:\Claude\RamDiskif they clash with something on your machine.
<#
.SYNOPSIS
Create, check or remove a RAM disk for scratch work, reachable at C:\Claude\RamDisk.
.DESCRIPTION
Mounts an NTFS RAM disk with OSFMount at a drive letter (R: by default). It then links
C:\Claude\RamDisk to it with a directory junction, so anything that wants a folder path can
use it.
EVERYTHING ON IT IS LOST when it is removed, when Windows restarts, or if OSFMount stops. Keep
only scratch files, test output and caches there, never the only copy of any work.
Creating and removing need an elevated PowerShell (OSFMount's driver). -Status does not, and
neither does -IfMissing when the RAM disk is already mounted (it only checks the link).
.EXAMPLE
.\RamDisk.ps1 # create a 4 GB RAM disk
.EXAMPLE
.\RamDisk.ps1 -SizeGB 8 # create an 8 GB RAM disk
.EXAMPLE
.\RamDisk.ps1 -SizeGB 8 -IfMissing -LogPath C:\Claude\tools\RamDisk.log
# what the startup task runs: create it unless it is there
.EXAMPLE
.\RamDisk.ps1 -Status # show what is mounted and linked
.EXAMPLE
.\RamDisk.ps1 -Remove # remove it (refuses while it holds files; add -Force to discard them)
#>
[CmdletBinding(DefaultParameterSetName = 'Create')]
param(
[Parameter(ParameterSetName = 'Create')]
[ValidateSet(4, 8)]
[int] $SizeGB = 4,
# Succeed without changing anything when this RAM disk is already mounted (checking the link).
[Parameter(ParameterSetName = 'Create')]
[switch] $IfMissing,
[Parameter(ParameterSetName = 'Remove', Mandatory = $true)]
[switch] $Remove,
[Parameter(ParameterSetName = 'Remove')]
[switch] $Force,
[Parameter(ParameterSetName = 'Status', Mandatory = $true)]
[switch] $Status,
[ValidatePattern('^[D-Z]$')]
[string] $DriveLetter = 'R',
[string] $LinkPath = 'C:\Claude\RamDisk',
# Append this run's output to a log file (started over once it passes 1 MB).
[string] $LogPath
)
$ErrorActionPreference = 'Stop'
$Root = "${DriveLetter}:\"
$Label = 'Scratch'
$Folders = 'Scratchpads', 'Temp', 'TestOutput', 'pytest'
# Free physical memory that must remain after the RAM disk is filled.
$HeadroomGB = 8
if ($LogPath) {
if ((Test-Path -LiteralPath $LogPath) -and (Get-Item -LiteralPath $LogPath).Length -gt 1MB) {
Remove-Item -LiteralPath $LogPath -Force
}
Start-Transcript -LiteralPath $LogPath -Append | Out-Null
}
# Any error ends the run with exit code 1 (a scheduled task shows it as its last result).
trap {
Write-Host ('ERROR: ' + $_.Exception.Message)
if ($LogPath) { Stop-Transcript | Out-Null }
exit 1
}
function Get-OsfMountExe {
$candidates = @(
(Join-Path $env:ProgramFiles 'OSFMount\OSFMount.com'),
(Join-Path ${env:ProgramFiles(x86)} 'OSFMount\OSFMount.com')
)
foreach ($path in $candidates) {
if ($path -and (Test-Path -LiteralPath $path)) { return $path }
}
throw 'OSFMount is not installed (looked in Program Files\OSFMount). Install it from PassMark, then run this again.'
}
function Test-Elevated {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Assert-Elevated {
if (-not (Test-Elevated)) {
throw 'Run this from an elevated PowerShell (Run as administrator): the RAM disk driver needs it.'
}
}
function Test-Junction([string] $Path) {
if (-not (Test-Path -LiteralPath $Path)) {
# A junction whose target is gone tests as missing; look at the entry itself.
$entry = Get-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue
if (-not $entry) { return $false }
return [bool]($entry.Attributes -band [IO.FileAttributes]::ReparsePoint)
}
$item = Get-Item -LiteralPath $Path -Force
return [bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint)
}
function Remove-JunctionOnly([string] $Path) {
# A non-recursive directory delete on a junction removes the link itself and never touches
# what it points to. (Remove-Item -Recurse in Windows PowerShell 5.1 can follow a junction
# and delete the target's files, so it is not used here.)
[IO.Directory]::Delete($Path)
if (Test-Junction $Path) { throw "Could not remove the link $Path." }
}
function Test-OurRamDisk {
# This script's RAM disk: the drive exists, carries our label and our README.
if (-not (Test-Path -LiteralPath $Root)) { return $false }
$drive = New-Object IO.DriveInfo($DriveLetter)
return ($drive.VolumeLabel -eq $Label) -and (Test-Path -LiteralPath (Join-Path $Root 'README.txt'))
}
function Set-RamDiskLink {
# Point $LinkPath at the RAM disk. A link left from an earlier RAM disk (gone after a restart)
# or an empty folder is replaced; a real folder with files in it is never touched.
if (Test-Junction $LinkPath) {
$target = (Get-Item -LiteralPath $LinkPath -Force).Target -join ''
if ($target.TrimEnd('\') -eq $Root.TrimEnd('\') -and (Test-Path -LiteralPath $LinkPath)) {
return
}
Remove-JunctionOnly $LinkPath
} elseif (Test-Path -LiteralPath $LinkPath) {
if (@(Get-ChildItem -LiteralPath $LinkPath -Force).Count -ne 0) {
throw "$LinkPath is a real folder with files in it. Move them, then run again: it is never deleted."
}
Remove-Item -LiteralPath $LinkPath -Force
}
$parent = Split-Path -Parent $LinkPath
if (-not (Test-Path -LiteralPath $parent)) {
New-Item -ItemType Directory -Force -Path $parent | Out-Null
}
New-Item -ItemType Junction -Path $LinkPath -Value $Root | Out-Null
if (-not (Test-Junction $LinkPath)) {
throw "The RAM disk is mounted at ${DriveLetter}:, but the link $LinkPath could not be created."
}
}
function Get-RamDiskContent {
# Every file on the RAM disk except the README this script writes.
if (-not (Test-Path -LiteralPath $Root)) { return @() }
$readme = Join-Path $Root 'README.txt'
return @(Get-ChildItem -LiteralPath $Root -Recurse -Force -File -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -ne $readme })
}
function Show-Status {
if (Test-Path -LiteralPath $Root) {
$drive = New-Object IO.DriveInfo($DriveLetter)
'RAM disk {0}: label "{1}", {2}, {3:N1} GB, {4:N1} GB free' -f $DriveLetter, $drive.VolumeLabel, $drive.DriveFormat, ($drive.TotalSize / 1GB), ($drive.AvailableFreeSpace / 1GB)
$files = Get-RamDiskContent
'{0} file(s), {1:N1} MB in use (the README not counted)' -f $files.Count, (($files | Measure-Object Length -Sum).Sum / 1MB)
} else {
"No drive at ${DriveLetter}:"
}
if (Test-Junction $LinkPath) {
$target = (Get-Item -LiteralPath $LinkPath -Force).Target -join ''
if (Test-Path -LiteralPath $Root) {
"$LinkPath -> $target"
} else {
"$LinkPath -> $target (dangling: the RAM disk is gone; creating it again relinks it)"
}
} elseif (Test-Path -LiteralPath $LinkPath) {
"$LinkPath exists but is a real folder, not a link"
} else {
"$LinkPath does not exist"
}
if (Test-Elevated) {
'--- OSFMount mounts:'
& (Get-OsfMountExe) -l
} else {
'(OSFMount lists its mounts only in an elevated window.)'
}
}
Write-Host ('=== {0} RamDisk.ps1 {1}' -f (Get-Date -Format 's'), $PSCmdlet.ParameterSetName)
if ($Status) {
Show-Status
return
}
if ($Remove) {
Assert-Elevated
$exe = Get-OsfMountExe
if (-not (Test-Path -LiteralPath $Root)) {
Write-Host "No drive at ${DriveLetter}:; nothing to dismount."
} else {
$files = Get-RamDiskContent
if ($files.Count -gt 0 -and -not $Force) {
$mb = ($files | Measure-Object Length -Sum).Sum / 1MB
throw ("${DriveLetter}: still holds {0} file(s) ({1:N1} MB), which would be lost. Copy out what you need, then run again with -Force." -f $files.Count, $mb)
}
}
if (Test-Junction $LinkPath) {
Remove-JunctionOnly $LinkPath
Write-Host "Removed the link $LinkPath."
}
if (Test-Path -LiteralPath $Root) {
# -d dismounts; -D forces it when a program still has a file open there.
$flag = if ($Force) { '-D' } else { '-d' }
& $exe $flag -m "${DriveLetter}:"
if ($LASTEXITCODE -ne 0) {
throw "OSFMount could not dismount ${DriveLetter}: (exit $LASTEXITCODE). Close programs using it, or use -Force."
}
Write-Host "Dismounted ${DriveLetter}:."
}
return
}
# --- Create -------------------------------------------------------------------------------------
if ($IfMissing -and (Test-OurRamDisk)) {
Set-RamDiskLink
Write-Host "Already mounted at $Root; $LinkPath points to it."
return
}
Assert-Elevated
$exe = Get-OsfMountExe
$os = Get-CimInstance Win32_OperatingSystem
$freeGB = $os.FreePhysicalMemory / 1MB
if ($freeGB -lt ($SizeGB + $HeadroomGB)) {
throw ('Only {0:N1} GB of memory is free; a {1} GB RAM disk needs at least {2} GB free.' -f $freeGB, $SizeGB, ($SizeGB + $HeadroomGB))
}
if (Test-Path -LiteralPath $Root) {
throw "${DriveLetter}: is already in use. Run with -Status to see it, or choose another letter with -DriveLetter."
}
# Check the link's place before mounting, so a real folder with files stops the run early.
if ((-not (Test-Junction $LinkPath)) -and (Test-Path -LiteralPath $LinkPath) -and
@(Get-ChildItem -LiteralPath $LinkPath -Force).Count -ne 0) {
throw "$LinkPath is a real folder with files in it. Move them, then run again: it is never deleted."
}
& $exe -a -t vm -s "${SizeGB}G" -m "${DriveLetter}:" -o "logical,rw,format:ntfs:$Label"
if ($LASTEXITCODE -ne 0) {
throw "OSFMount failed (exit $LASTEXITCODE). Check its message above."
}
$deadline = (Get-Date).AddSeconds(15)
while (-not (Test-Path -LiteralPath $Root)) {
if ((Get-Date) -gt $deadline) { throw "The RAM disk did not appear at ${DriveLetter}:." }
Start-Sleep -Milliseconds 250
}
foreach ($folder in $Folders) {
New-Item -ItemType Directory -Force -Path (Join-Path $Root $folder) | Out-Null
}
Set-Content -LiteralPath (Join-Path $Root 'README.txt') -Encoding ascii -Value @(
'RAM disk: everything here is lost when it is removed or Windows restarts.',
'Scratch files, test output and caches only. Never the only copy of any work.'
)
Set-RamDiskLink
Write-Host ("Ready: {0} GB RAM disk at {1}, linked from {2}" -f $SizeGB, $Root, $LinkPath)
foreach ($folder in $Folders) { Write-Host (" {0}\{1}" -f $LinkPath, $folder) }To try it once by hand, open PowerShell as administrator and run:
powershell -ExecutionPolicy Bypass -File C:\Claude\tools\RamDisk.ps1 -SizeGB 8Step 3: Create it at every startup
A RAM disk you have to remember to create is a RAM disk your tools will one day find missing. Save the second script as C:\Claude\tools\Install-RamDiskStartup.ps1, in the same folder as RamDisk.ps1. It registers a scheduled task, \Claude\Claude RAM Disk, that:
- runs
RamDisk.ps1 -IfMissingas SYSTEM, 30 seconds after boot and before anyone signs in; - retries 3 times, a minute apart, if a run fails;
- stops a run after 5 minutes;
- logs every run to
RamDisk-startup.lognext to the scripts.
Add -RunNow to run the task once immediately and print the end of the log, which proves it works without a restart. -Uninstall removes the task. The cmdlets it uses are documented in Microsoft’s Register-ScheduledTask reference.
<#
.SYNOPSIS
Register (or remove) a scheduled task that creates the RAM disk at every Windows startup.
.DESCRIPTION
Registers the task "\Claude\Claude RAM Disk". It runs RamDisk.ps1 -IfMissing as SYSTEM, 30
seconds after Windows starts and before anyone signs in, so the RAM disk and its link are
ready at sign-in. It retries 3 times, a minute apart, if a run fails. Each run's output is
appended to RamDisk-startup.log next to the scripts.
Run it once from an elevated PowerShell. RamDisk.ps1 must be in the same folder.
.EXAMPLE
.\Install-RamDiskStartup.ps1 -SizeGB 8 -RunNow # register, then run it once now to prove it
.EXAMPLE
.\Install-RamDiskStartup.ps1 -Uninstall # remove the task (the RAM disk stays until restart)
#>
param(
[ValidateSet(4, 8)]
[int] $SizeGB = 8,
# Run the task once right after registering it and show the result.
[switch] $RunNow,
[switch] $Uninstall
)
$ErrorActionPreference = 'Stop'
$TaskName = 'Claude RAM Disk'
$TaskPath = '\Claude\'
$Script = Join-Path $PSScriptRoot 'RamDisk.ps1'
$Log = Join-Path $PSScriptRoot 'RamDisk-startup.log'
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principalCheck = New-Object Security.Principal.WindowsPrincipal($identity)
if (-not $principalCheck.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
throw 'Run this from an elevated PowerShell (Run as administrator): registering a startup task needs it.'
}
$existing = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue
if ($Uninstall) {
if ($existing) {
Unregister-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Confirm:$false
Write-Host 'Removed the startup task. The RAM disk stays mounted until the next restart (or RamDisk.ps1 -Remove).'
} else {
Write-Host 'There is no startup task to remove.'
}
return
}
if (-not (Test-Path -LiteralPath $Script)) {
throw "RamDisk.ps1 was not found next to this script ($Script)."
}
if (-not (Test-Path -LiteralPath (Join-Path $env:ProgramFiles 'OSFMount\OSFMount.com'))) {
throw 'Install OSFMount (PassMark) first.'
}
$powershell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
$arguments = '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File "{0}" -SizeGB {1} -IfMissing -LogPath "{2}"' -f $Script, $SizeGB, $Log
$action = New-ScheduledTaskAction -Execute $powershell -Argument $arguments
$trigger = New-ScheduledTaskTrigger -AtStartup
$trigger.Delay = 'PT30S'
$principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
-StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Minutes 5) `
-RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
Register-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Action $action -Trigger $trigger `
-Principal $principal -Settings $settings -Force `
-Description "Creates the $SizeGB GB scratch RAM disk (RamDisk.ps1 -IfMissing) at startup. Log: $Log" | Out-Null
Write-Host ("Registered {0}{1}: {2} GB RAM disk at every startup (30 s after boot, as SYSTEM)." -f $TaskPath, $TaskName, $SizeGB)
Write-Host "Log: $Log"
if ($RunNow) {
Start-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath
$deadline = (Get-Date).AddSeconds(90)
do {
Start-Sleep -Seconds 2
$state = (Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath).State
} while ($state -eq 'Running' -and (Get-Date) -lt $deadline)
$info = Get-ScheduledTaskInfo -TaskName $TaskName -TaskPath $TaskPath
Write-Host ("Run now: last result {0} (0 means success)" -f $info.LastTaskResult)
if (Test-Path -LiteralPath $Log) {
Write-Host '--- end of the log:'
Get-Content -LiteralPath $Log -Tail 12
}
}Run it once from an elevated PowerShell after installing OSFMount. These commands can be copied as they are:
# One time, in an elevated PowerShell, after installing OSFMount:
powershell -ExecutionPolicy Bypass -File C:\Claude\tools\Install-RamDiskStartup.ps1 -SizeGB 8 -RunNow
# Any time, in a normal window:
powershell -ExecutionPolicy Bypass -File C:\Claude\tools\RamDisk.ps1 -StatusA result of 0 on the “Run now” line means the task succeeded. Anything else is explained at the end of the log the script prints.
Step 4: Point Claude Code and VS Code at it
The RAM disk only helps if your tools write to it. Neither Claude Code nor VS Code needs a plugin for this; they just need to be told where scratch belongs.
Claude Code: add an instruction to CLAUDE.md
Claude Code reads a project’s CLAUDE.md file at the start of every session (see Anthropic’s Claude Code memory documentation). Add a short instruction such as:
Use C:\Claude\RamDisk\Scratchpads for scratch files and C:\Claude\RamDisk\pytest as pytest's --basetemp. Never keep the only copy of any work there; it is wiped at every restart.Claude Code chooses its own location for its internal scratch data. This folder is for the scratch files you and the agent create: throwaway scripts, staging copies, test runs and logs.
VS Code: pytest and the integrated terminal
In VS Code, two settings cover most scratch traffic. python.testing.pytestArgs passes arguments to pytest when you run tests from the Testing view (see Python testing in VS Code). terminal.integrated.env.windows sets environment variables for the integrated terminal (see Terminal Profiles), so tools you start there, including Claude Code if you launch it from that terminal, use the RAM disk for TEMP and TMP. Add both to the workspace’s .vscode\settings.json:
{
"python.testing.pytestArgs": ["--basetemp=C:\\Claude\\RamDisk\\pytest"],
"terminal.integrated.env.windows": {
"TEMP": "C:\\Claude\\RamDisk\\Temp",
"TMP": "C:\\Claude\\RamDisk\\Temp"
}
}Point --basetemp only at the dedicated pytest folder: pytest clears the base temporary directory at the start of each run, as the pytest documentation explains.
For a single test run
To send one run’s temp files to the RAM disk without changing any settings, set TEMP and TMP for that PowerShell session only:
$env:TEMP = 'C:\Claude\RamDisk\Temp'
$env:TMP = 'C:\Claude\RamDisk\Temp'
python -m pytest --basetemp=C:\Claude\RamDisk\pytestClose the window and TEMP returns to its usual location. Pointing the system-wide TEMP at the RAM disk is possible, but installers and updates also use TEMP and may expect it to survive a restart, so we keep the change per tool or per session.
Windows pitfalls we hit while building it
These are the problems that cost the most time. The scripts above already handle all of them, but they are worth knowing if you adapt the scripts or write your own.
mklink /J through cmd /c silently failed
Calling cmd /c mklink /J from Windows PowerShell 5.1 passed the quotes around the paths on wrongly. The RAM disk was created but the folder link was not, and nothing reported an error. The fix is the native cmdlet, which needs no administrator rights (see New-Item):
New-Item -ItemType Junction -Path C:\Claude\RamDisk -Value R:\Remove-Item -Recurse can delete the target, not just the link
Never remove a junction with Remove-Item -Recurse in Windows PowerShell 5.1. It can follow the link and delete the files it points to. A non-recursive .NET directory delete removes only the link; we tested that the target’s files survive:
[IO.Directory]::Delete('C:\Claude\RamDisk')Get-Volume does not list the OSFMount drive
Get-Volume does not show the RAM disk. Read its size, label and free space through .NET instead:
New-Object IO.DriveInfo('R')The execution policy blocks the script
By default Windows will not run a downloaded or unsigned script. Either run it with powershell -ExecutionPolicy Bypass -File ..., as every command in this guide does, or run the following once. Local scripts then run, while downloaded ones still need a signature (see about_Execution_Policies):
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedA link left from before a restart points at nothing
After a restart the junction still exists, but its target is gone until the RAM disk is created again, and Test-Path reports it as missing. The script inspects the entry itself, detects the dangling link and replaces it. It never deletes a real folder that has files in it; if it finds one at the link path, it stops and asks you to move the files.
Verify it after a restart
- In a normal (non-elevated) PowerShell window, run
RamDisk.ps1 -Status. You should seeR:labelled Scratch, NTFS, with the size you chose, andC:\Claude\RamDisk -> R:\. - Drop a test file into
C:\Claude\RamDisk\Scratchpads, then restart Windows. - After signing in, check that
R:exists, the test file is gone, the four folders and the README are back, andC:\Claude\RamDiskopens. - Open
C:\Claude\tools\RamDisk-startup.logand confirm the latest run ended with “Ready” and no ERROR line. In Task Scheduler,\Claude\Claude RAM Diskshould show a last run result of 0.
powershell -ExecutionPolicy Bypass -File C:\Claude\tools\RamDisk.ps1 -StatusUndo it
Remove the startup task first, then the disk, from an elevated PowerShell. -Remove refuses while the RAM disk still holds files; copy out anything you need, then add -Force to discard the rest. Uninstall OSFMount from Settings afterwards if you no longer need it.
# Remove it (elevated): the task, then the disk
powershell -ExecutionPolicy Bypass -File C:\Claude\tools\Install-RamDiskStartup.ps1 -Uninstall
powershell -ExecutionPolicy Bypass -File C:\Claude\tools\RamDisk.ps1 -RemoveFAQ
Will a RAM disk make Claude Code faster?
Partly. Steps that create and delete many small files, such as temp folders and staging copies, get quicker. Work bound by CPU or process start-up, such as a large test suite, barely changes on a modern NVMe SSD. The bigger benefits are scratch that cleans itself on every restart and fewer writes to the SSD.
Can I use the RAM disk with VS Code without Claude Code?
Yes. Nothing in the setup depends on Claude Code. Point pytest at it with python.testing.pytestArgs and set TEMP and TMP for the integrated terminal with terminal.integrated.env.windows, and any tool you run from VS Code can use it.
Should I exclude the RAM disk from Microsoft Defender?
That is your decision. Excluding the RAM disk from real-time scanning is the biggest speed-up for small files, but it means code and files written there are not scanned. If you choose to, Microsoft documents how to configure custom exclusions for Microsoft Defender Antivirus; we do not recommend it by default.
How big should the RAM disk be?
4 GB covers scratch scripts and most test temp folders; 8 GB suits larger staging copies. The script only creates the disk if at least 8 GB of physical memory would still be free afterwards, so a 4 GB disk needs 12 GB free and an 8 GB disk needs 16 GB free.
What happens to the files when Windows restarts?
They are gone. The startup task creates a fresh, empty RAM disk about 30 seconds after boot and relinks C:\Claude\RamDisk to it. Never keep uncommitted work, git worktrees or the only copy of anything there.
Wrapping up
A RAM disk will not turn a slow test suite into a fast one, but it gives Claude Code, VS Code and your test runner a scratch space that is always there at boot, always empty after a restart, and never mixed up with work that matters. Keep only disposable files on it, decide deliberately about Defender, and let the startup task do the rest.
When agents, builds and test runs need more memory and uptime than a desktop can give, run them on hardware that is not also your workstation. Our guide to bare metal versus dedicated servers explains the options, and ARPHost bare metal servers are provisioned automatically from live inventory when you are ready.

Leave a Reply
You must be logged in to post a comment.