◉CLAUDE LABJP
●2.1.337 — Claude Code 2.1.337 lets you pass a git address to /plugin install in the terminal and use the plugin right away●TERRAFORM — A Terraform provider for the Claude Platform entered beta on 12/3, so workspaces and service accounts can live in code●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 48 days from now. The replacement is claude-opus-5-5●SANDBOX — Someone ran tests and lost a real config file. The open question is how to check what a sandbox actually protects●NEW — New: Re-checking "it got worse" with five saved prompts●FOLDERS — Before handing Cowork a folder, three questions help you decide what it should and shouldn't see●2.1.337 — Claude Code 2.1.337 lets you pass a git address to /plugin install in the terminal and use the plugin right away●TERRAFORM — A Terraform provider for the Claude Platform entered beta on 12/3, so workspaces and service accounts can live in code●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 48 days from now. The replacement is claude-opus-5-5●SANDBOX — Someone ran tests and lost a real config file. The open question is how to check what a sandbox actually protects●NEW — New: Re-checking "it got worse" with five saved prompts●FOLDERS — Before handing Cowork a folder, three questions help you decide what it should and shouldn't see
Articles/Cowork
◈ Cowork/2026-12-05Beginner

Before Asking Cowork to Copy or Sync Files, I Check Where They Would Land If the Destination Were Empty

Three questions I ask before letting Cowork copy or sync files: does it stop if the destination variable is empty, can it show me a list before moving anything, and will the overwritten files be kept. Here is a short script that checks all three, plus the wording I now use in the request.

Cowork75folders3rsyncbackupnon-engineers

On a Saturday afternoon I had just finished exporting images for my website and was getting ready to move them into the publishing folder. As usual, I asked Cowork to "sync the exported files into the public folder," and a few seconds later a short draft script came back.

I read it before running it, and stopped. The destination was written as "$OUT/site" — everything depended on one variable. What went into OUT was decided a few lines earlier. If that failed and OUT stayed empty, where would the files go? I couldn't answer right away.

The day before, Claude Code issue #113960 had been filed. Someone on Windows ran a sync script and more than 300GB of data was overwritten. The analysis from the reporter's own session points to a likely cause: if S in "$S/c" is empty, the destination becomes /c — the root of the C drive in Git Bash. (The script itself was lost, so this isn't confirmed.) Different tool, I know. But it had the same shape as the draft on my screen.

Here is the line I ended up drawing: I decide where things go; Cowork carries them. Below are the three questions I now ask before any copy or sync runs, and a small script that checks all three at once.

Question 1: If the destination came out empty, where would it write?

A shell variable with nothing in it doesn't raise an error. It is simply dropped into the line as an empty string.

S=""
echo "$S/c"      # → /c (top of the filesystem)
echo "$S/"       # → / (the root itself)

To a human, "$S/c" reads as "c, under somewhere." With S empty, only the leading / survives, and the destination moves somewhere else entirely.

There are two ways to close this. set -u at the top of a script stops on any variable that was never defined — but S="", defined yet empty, still slips through. ${VAR:?message} stops on both undefined and empty, so that is what I use on the line that receives the destination.

DEST="${2:?destination is empty}"   # exits right here if empty

Question 2: Can it show me what will happen before it moves anything?

The second question is whether I can see what will be added and what will be overwritten before anything is written. rsync has --dry-run, and with --itemize-changes it prints one line per file with a short code.

Line starts withMeaning
>f+++++++++a new file the destination doesn't have yet
>f.s....... and similaran existing file that will be overwritten (s = size differs, t = time differs)
cd+++++++++a new folder

rsync has one quirk worth knowing here: src/ with a trailing slash means "the contents of src," while src without it means "the folder src itself." Forget the slash and you get an extra src level inside the destination. That once left me with the same images split across two levels and no quick way to tell which set was newer. The dry-run list shows the deeper path immediately.

Question 3: Will the overwritten files be kept?

The third question is whether I can undo an overwrite. rsync --backup --backup-dir=<folder> moves each file that is about to be replaced into that folder first.

I also leave --delete out of sync requests. It removes anything in the destination that isn't in the source, and the moment the destination is wrong, it deletes from the side you meant to protect. If the destination needs cleaning, I decide that separately, after reading the list.

A script that checks all three

This is copy_guard.sh, which I run in Cowork's working environment. It stops if the destination is outside a parent folder I allow, only prints the plan by default, and writes only when RUN=yes is set.

#!/usr/bin/env bash
# copy_guard.sh — confirm the destination, keep what gets overwritten, then copy
# usage: bash copy_guard.sh <source> <destination> <allowed parent folder>
#        prints the plan only; prefix with RUN=yes to actually write
set -euo pipefail
 
SRC="${1:?source is empty}"
DEST="${2:?destination is empty}"
ROOT="${3:?allowed parent is empty}"
 
src_abs="$(cd "$SRC" && pwd -P)"
root_abs="$(cd "$ROOT" && pwd -P)"
# the destination itself may not exist yet, but its parent must
dest_parent="$(cd "$(dirname "$DEST")" && pwd -P)"
dest_abs="${dest_parent%/}/$(basename "$DEST")"
 
stop() { echo "Stopped: $1" >&2; exit 2; }
case "$dest_abs/" in "$root_abs"/*) ;; *) stop "destination $dest_abs is outside $root_abs";; esac
[ "$dest_abs" = "$root_abs" ] && stop "won't write into the allowed parent itself"
case "$dest_abs/" in "$src_abs"/*) stop "destination is inside the source";; esac
case "$src_abs/" in "$dest_abs"/*) stop "source is inside the destination";; esac
 
# trailing / means "the contents of"; without it you get one level deeper
plan="$(rsync -a --dry-run --itemize-changes "$src_abs/" "$dest_abs/")"
new=$(printf '%s\n' "$plan" | grep -c '^>f+++++++++' || true)
over=$(printf '%s\n' "$plan" | grep '^>f' | grep -vc '+++++++++' || true)
echo "destination: $dest_abs"
echo "new: ${new} / overwrite: ${over}"
printf '%s\n' "$plan" | grep '^>f' | grep -v '+++++++++' | head -20 || true
 
[ "${RUN:-}" = "yes" ] || { echo "(plan only — set RUN=yes to write)"; exit 0; }
keep="$dest_abs/.before_$(date +%Y%m%d-%H%M%S)"
rsync -a --backup --backup-dir="$keep" "$src_abs/" "$dest_abs/"
echo "Done. Files from before the overwrite are in $keep"

A few notes on why it's written this way:

  • It resolves real paths with pwd -P before comparing. With ../ or a symlink in the way, plain string comparison can mix up inside and outside.
  • It stops if the destination's parent doesn't exist. There is deliberately no mkdir -p; I don't want it creating places I never asked for.
  • The case comparisons add a trailing /. Otherwise site-old would count as "inside" site just because the names start the same.

Here is what it did when I tried it. The call that built the destination from an empty variable stopped before writing anything.

$ S=""; bash copy_guard.sh work/src "$S/c" work/out
Stopped: destination /c is outside /…/work/out
 
$ bash copy_guard.sh work/src work/out/site work/out
new: 1 / overwrite: 1
>f.s....... a.txt
(plan only — set RUN=yes to write)

After running it with RUN=yes, the original contents of the overwritten a.txt were sitting in the .before_<date> folder.

I changed how I phrase the request, too

Even with the script in place, a request that just says "sync it" can lead Cowork to carry files some other way. Now I pin down the destination and the order in plain words:

Move the contents of export/ into public/site/.
Only destinations under public/ are allowed.
First run copy_guard.sh without RUN, show me the new/overwrite counts
and the overwrite list, and stop there.
Don't use --delete. I'll tell you to run it after I've checked the list.

The important part is that stopping after the list is written into the request. When the count looks wrong — hundreds of overwrites where I expected a handful — that's usually where a wrong destination shows up.

What this script can't protect

It isn't a cure-all, so let me be clear about its edges. The analysis in issue #113960 also raised the possibility that a Windows program received a path like /c/Users/… unconverted and wrote under a different drive. How programs outside the shell interpret paths is beyond what these comparisons catch.

It also only covers copies that go through copy_guard.sh. It does nothing when Cowork writes files some other way. That's why, as an indie developer whose source files and exports all pile up on the same machine, I treat the wording of the request as just as important as the script.

Next time you ask Cowork to copy or sync something, try asking one thing first: "If the destination were empty, where would this write?" If the answer hesitates, I'd say that script doesn't need to run yet.

Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

◈ Cowork2026-11-30
Before Asking Cowork to Remove the Files You Don't Need, Pick a Holding Folder
When I hand Cowork a cleanup job, I now spell out that remove means move, not delete. Here is a small script that moves candidates into a holding folder with a log, a second one that walks the log back, and where I draw the line on who actually deletes.
◈ Cowork2026-10-30
Start Cowork's First Week With a Practice Folder: Three I Handed Over, One I Held Back
How to decide which folders to give Cowork first: an empty practice folder, a copy of real files, and an output folder, while keeping the folder with credentials out of reach.
◈ Cowork2026-12-02
When a Scheduled Task Stops on 'denied by the auto mode classifier', I Move the Destructive Step Into Its Own Call
A Cowork scheduled task stopped on 'Permission for this action was denied by the Claude Code auto mode classifier'. How to tell this message apart, the order I narrowed it down in, the split-and-replace fix, and a script that checks task instructions beforehand.