One Space in a Path, and Nine Commands Reported Success While Counting the Wrong Place
A single space in a workspace name sends agent-written commands somewhere else, quietly. Measurements across eleven unquoted-path forms, and the entry-point script that closes the boundary in one cd.
I asked an agent to count the articles in my workspace. It came back with 0 files.
There are several hundred MDX files in there. Typing the same command by hand returns the right number, every time.
No error. The command succeeded. It just counted somewhere else.
The culprit was the workspace name: My Workspace. That one space in the middle.
As an indie developer I get to pick where my workspace lives, which is exactly how it ends up somewhere convenient rather than somewhere safe. Mine sits inside a Dropbox sync folder, and I never thought twice about the space in the folder name. Names are for humans to read, and a space reads better.
Handing the keyboard to an agent is what finally sent me the bill for that decision.
The space is in the prefix, not the leaf
The first thing I measured was how much of the tree was even affected.
Same workspace, same files. Change how you count and you get 100% or 0.3%.
The space almost never lives in a filename. It lives in exactly one place — the My Workspace segment of the prefix. And every absolute path you build carries that one segment along with it.
A tidily named file buried deep in node_modules picks up a space the instant you address it absolutely.
That was the fork in the road. The problem wasn't the filenames. It was how paths get assembled.
Eleven unquoted forms, and what each one actually returns
An agent writing shell won't reliably type "$WS" with the quotes. So I measured what happens when it writes plain $WS, across eleven forms.
Setting up a workspace with a space in it:
BASE="$HOME/pathprobe"WS="$BASE/My Workspace"mkdir -p "$WS/content/articles/ja/tips" "$WS/out"for i in 1 2 3 4 5; do echo "# a$i" > "$WS/content/articles/ja/tips/a$i.mdx"; donemkdir -p "$BASE/sandbox" && cd "$BASE/sandbox"
Five .mdx files. Now touch them without quoting $WS.
Command form
Exit code
Returned
Correct
find $WS -name "*.mdx" | wc -l
0
0
5
ls $WS | wc -l
0
0
4
grep -rl "a1" $WS | wc -l
0
0
1
[ -d $WS ] && echo yes || echo no
0
no
yes
mkdir -p $WS/out/gen
0
created
created in 2 wrong places
for f in $(find "$WS" -name "*.mdx")
0
10 iterations
5 iterations
find "$WS" ... | xargs wc -l
0
0 total
5 total
python3 script.py $WS (argv count)
0
2
1
du -sh $WS
0
12K (of something else)
real size
cat $WS/.../a1.mdx
1
—
# a1
cp $WS/.../a1.mdx ./c.mdx
1
—
copied
Two forms failed out loud: cat and cp. The other nine — 82% of them — returned exit code 0 while handing back the wrong answer.
The failure modes aren't uniform, and the differences matter.
find and grepsucceed with zero results. $WS splits into /path/to/My and Workspace, neither exists, so there's nothing to search and the walk finishes normally. The complaint goes to stderr, but pipe it into wc -l and the exit code belongs to wc. The scream never reaches the caller.
[ -d $WS ]says a directory that exists doesn't. Split into two words, [ receives -d plus two paths, and the expression doesn't parse. On bash 5.1 it prints one line, binary operator expected, to stderr and exits with 2. But || echo no is bolted on the end, so what lands on screen is just no. Any branch keyed on an existence check quietly takes the other road.
for f in $(find "$WS" ...)turns 5 files into 10 iterations. find is quoted here and returns the right 5 paths — then command substitution word-splits each one at the space. The loop runs ten times and grabs a broken path every time. This is the sneakiest form of all: you quoted it, and it broke anyway.
python3 script.py $WSlands 2 items in argv. If the script reads sys.argv[1] and gets on with it, it starts working on /path/to/My in good faith.
And mkdir -p $WS/out/gen returned 0 while creating directories in two places that weren't the workspace:
$ ls -A "$BASE/sandbox" # current directoryWorkspace$ ls -A "$BASE"My My Workspace sandbox
mkdir -p /path/to/My Workspace/out/gen parses as two arguments: /path/to/My and Workspace/out/gen. The first is absolute, so it lands next to the workspace. The second is relative, so it lands wherever you happened to be standing.
Reads come back empty. Writes land somewhere you weren't looking. That asymmetry defines the whole problem.
Rewriting the table taught me one more thing. The "12K" in the du -sh $WS row only exists because the mkdir -p $WS/out/gen row above it had already scattered directories around. Run alone, on a clean slate, du prints two cannot access lines and exits with 1. So "nine forms exit 0" is true when you run them top to bottom, and the count shifts with the order. The same space makes one command's side effect rewrite the next command's result.
An empty read is at worst nothing happening. A write that succeeded in the wrong place means the agent reports "done" and the output exists nowhere you'll think to check. That's the one I hit first.
The absence of an error proved nothing at all.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦Measured across 11 unquoted-path forms: 9 return exit 0 with wrong results (find says 0, for loops 10 times, argv holds 2)
✦Full implementation of ws.sh, an entry point that closes the boundary at a single cd (write probe, exit code 78, exec handoff)
✦Where the symlink alias breaks down: find refuses to follow it, and readlink -f hands the space right back
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
When an agent's report feels off, the left column is where I start now. These are the symptoms I actually ran into, in the order I'd check them. (Measured on Linux with bash 5.1.16 and GNU findutils 4.8.0, re-run in November 2026. BSD find on macOS and zsh word their errors differently and differ on a few exit codes.)
Symptom
Likely cause
How to confirm
Fix
A count of 0, and no error anywhere
Unquoted find $WS searching two paths that don't exist
Drop the | wc -l and look for two No such file or directory lines on stderr
cd inside first, then find .
A folder that exists is treated as missing, and the script takes the other branch
[ -d $WS ] fails with binary operator expected and status 2, so the || side runs
Run [ -d $WS ]; echo $? on its own and look for 2
Check once at the entry point and never again downstream
Counts come back exactly doubled
Word splitting in for f in $(find ...) breaks each path in two
Print printf '[%s]\n' "$f" in the loop and look for [/path/to/My]
Switch to relative paths, or pair -print0 with read -d ''
"Created it," says the agent, and the output is nowhere
mkdir -p $WS/... created two directories, one beside the workspace and one under the current directory
ls -A the current directory and look for an unfamiliar Workspace folder
Clean up the strays; write only through relative paths behind the entry point
A script works on the wrong target
python3 script.py $WS gives argv two entries and sys.argv[1] holds half a path
Print len(sys.argv) at the top of the script
Pass the location through WS_ROOT and the working directory, not as an argument
A plausible count, off by orders of magnitude
The command skipped the entry point and the working directory is some other tree
Have the agent include pwd -P in its output
Let the suite's cwd is WS_ROOT line stop it
The first four rows are the space itself. The last two are a different kind of mix-up that shows up after you build an entry point to dodge the space, which the second half of this piece gets into.
Enforcing quotes doesn't cover the whole surface
My first instinct was to make the agent quote things. Put "always double-quote paths" in AGENTS.md, fail SC2086 in CI with shellcheck.
That gets you halfway. Look back at the table, though, and there are places quoting can't reach.
for f in $(find "$WS" ...) broke with the path properly quoted. What's broken there isn't the quoting of $WS — it's the word-splitting applied to the substitution's output. xargs has the same problem: whitespace is its default delimiter.
-print0, -0, and IFS= read -r -d ''. Correct, all three.
The question I kept circling was whether an agent will actually do this every time. Rules work fine for code I type myself. When something is writing dozens of shell snippets a day, rule compliance is your failure rate — and here, non-compliance exits 0. Miss one gate and there's no second chance to notice.
Designs that depend on rules being followed break when rules aren't followed. I don't much like building that way. I wanted to know whether the thing could be made unbreakable by non-compliance instead.
A symlink alias only covers the doorway
The next attempt was a space-free alias:
ln -sfn "$WS" "$BASE/ws"ALIAS="$BASE/ws"
Forget the quotes around $ALIAS and nothing splits. Several forms did come good:
[ -d $ALIAS ] && echo yes || echo no # yes (correct)mkdir -p $ALIAS/out/gen # rc=0, lands in the real workspace
Writes reached the real directory, nothing leaked into the current one. So far so good.
find won't follow a symlink unless you add a trailing slash or -L. Which means teaching the agent to write find -L — a brand new rule to comply with. Right back where I started.
And then this settled it:
readlink -f $ALIAS# /path/to/My Workspace
The alias is a doorway, nothing more. Any step that resolves the real path pours the space straight back downstream. Tools that call realpath. Scripts that walk up from __file__. Anything that prints an absolute path in an error message. All of them live outside the alias.
A symlink doesn't remove the space. It drapes one layer over it. Underneath, nothing changed.
Three things I believed that turned out half wrong
Each of these is half right, which is why they lasted so long for me. Here is the half that wasn't.
"set -euo pipefail will stop it somewhere." Partly true. With pipefail on, find $WS | wc -l exits 1, ls and grep exit 2, and xargs wc -l exits 123, so those reads do surface as failed pipelines. But for f in $(find "$WS" ...) still loops ten times with status 0, and [ -d $WS ] || echo no is also 0. The bash manual is explicit that -e doesn't fire on the left side of || or inside an if condition, and that's exactly where an existence check lives. The stray mkdir -p succeeds, so nothing stops it either. Some reads get caught; writes and branches don't.
"ShellCheck will find all of it." ShellCheck flags the unquoted expansion as SC2086 and looping over find output as SC2044, and for script files it's reliable. But the one-liners an agent types straight into a terminal are never saved as files, so CI never lints them. Almost every incident I had came from those one-liners.
"Just set IFS to newline." This does work, which surprised me. With IFS=$'\n', even unquoted find $WS and the for loop return 5. The trouble is the blast radius. In the same shell, OPTS="-name *.mdx -type f"; find . $OPTS passes the options as a single word, find complains about an unknown predicate, and with | wc -l on the end you're back to 0 results and exit 0. It quietly breaks every other line that relied on splitting.
Relative paths never had a space to begin with
Stuck, I went back to the first measurement — the one that split 100% and 0.3%.
The space is only in the prefix. It's essentially never in the filenames.
Strip the prefix and there's no space left. Stand inside the workspace with cd, and every relative path from there is clean.
cd "$WS"find . -name '*.mdx' | wc -l # 5for f in $(find . -name '*.mdx'); do echo x; done | wc -l # 5find . -name '*.mdx' | xargs wc -l | tail -1 # 5 total
The three forms that returned 0, 10, and 0 now all return 5. No quoting. No -print0.
The reason is unremarkable: ./content/articles/ja/tips/a1.mdx contains no space. There's nothing to split on.
So instead of demanding the agent quote correctly, give it a world with no spaces in it. That's the version that survives non-compliance.
Exactly one line touches a path with a space in it — the cd. And that line lives in one file I wrote.
ws.sh, the one way in
Here's the script that closes the boundary. It lives at bin/ws.sh in the workspace.
#!/usr/bin/env bash# ws.sh — the only entry point into a workspace whose path contains a space.# This file is the only thing that touches an absolute path.# Everything it calls lives in a world of relative paths.set -euo pipefail# 1) Resolve the real location exactly once. Never rebuild WS_ROOT downstream.WS_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)"# 2) Decide writability by actually writing, not by testing existence._probe() { local t="${WS_ROOT}/.ws-probe.$$" if ( : >"$t" ) 2>/dev/null; then rm -f -- "$t"; return 0; fi return 1}if ! _probe; then printf 'ws.sh: cannot write to: %s\n' "$WS_ROOT" >&2 exit 78 # EX_CONFIG — a dedicated code so "blocked" never reads as "zero results"fi# 3) Close the boundary here. Relative paths from now on contain no spaces.cd -- "$WS_ROOT"# 4) Hand it to children via the environment, never through argument splitting.export WS_ROOTexport LC_ALL="${LC_ALL:-C.UTF-8}"if [ "$#" -eq 0 ]; then printf 'usage: bin/ws.sh <command> [args...]\n' >&2 exit 64fiexec -- "$@"
A few lines are worth explaining.
WS_ROOT derives from the script's own location so that callers never pass a path in. Accept a path as an argument and you've reopened the word-splitting hole. Deriving it from where the file sits means no space-bearing string can enter from outside.
cd -- "$(dirname ...)" && pwd -P stands in for readlink -f. pwd -P resolves symlinks to the physical directory, so even if bin/ws.sh gets invoked through an alias, it lands on the real thing.
The -- markers keep a leading-hyphen path from being read as an option. Different problem from spaces, but an entry point that handles paths may as well close both.
Then exec -- "$@". The argument array passes through intact — no splitting here either. exec replaces the process so exit codes and signals pass through cleanly; a lingering wrapper changes how Ctrl+C behaves and how exit codes propagate.
Testing writability instead of existence
One note on _probe.
[ -d "$WS_ROOT" ] looks sufficient. But readable-yet-unwritable is an ordinary state — permissions shift on a synced folder, ownership changes to another user. The existence check returns true and the write fails one step later.
Creating one byte and deleting it turned out to be the only reliable answer. I use the same reasoning for detecting ownership drift during unattended runs.
Exit code 78 is deliberate. Exit 1 is indistinguishable from "the command failed." A dedicated config-error code lets the caller tell "zero results" apart from "never got in the door."
Verified against a read-only workspace:
$ chmod 555 "$RO_WS"$ "$RO_WS/bin/ws.sh" bash -c 'echo should_not_run'ws.sh: cannot write to: /path/to/Read Only WS$ echo $?78
should_not_run never ran. Stopped at 78.
Three lines of rules for the agent
AGENTS.md here means the rules file in the workspace. Which files Antigravity treats as rules, and which level wins, has shifted between releases, so it's worth checking the Rules and Customization discovery pages in the official docs (as of November 2026) for the version you're on.
If you use the terminal command allow list in Antigravity's agent permissions, the entry point lightens that too: there is one thing to allow, bin/ws.sh. That said, the forum has several bug reports about allow-list matching and entries not sticking, so after adding it, confirm once by hand that the approval prompt actually stops appearing.
This is the whole of what went into AGENTS.md:
## Running commands inside the workspace- Always run shell commands through `bin/ws.sh <command>`- Write every path as a relative path (never assemble an absolute path)- Output paths are relative too (e.g. `out/report/`)
Shorter rules get followed more often. Compared to "quote everything, use -print0 and -0, and never feed command substitution to a for loop," there's one thing to remember now.
The behaviour on non-compliance changed too. If the agent forgets bin/ws.sh and types a bare find . -name '*.mdx', it counts whatever tree it happens to be standing in.
I was about to write "it gets 0 results." Then I tried it, and I was wrong:
$ cd / # outside the workspace$ find . -name '*.mdx' 2>/dev/null | wc -l15552
Not zero. It walks the wrong tree and hands back a plausible-looking number, where 5 was expected (the figure depends on the filesystem of whatever machine you try it on). That may be harder to notice than the space bug itself: you can doubt a 0, but 15,552 sails through as "I guess that's how many there are."
Still, the agent no longer assembles an absolute path and writes somewhere else entirely. Put precisely: I moved the failure from "writes to the wrong place" to "reads from the wrong place." The accident migrated from the write side to the read side.
The read side is what the next suite is for.
Checking that the doorway is doing its job
Rules and implementation weren't enough. You get runs that look like they went through the entry point and didn't.
So there's a suite, written entirely in relative paths:
#!/usr/bin/env bash# tests/path_contract.sh — verify the entry point the same way every timeset -uo pipefailfail=0chk() { if [ "$2" = "$3" ]; then printf ' ok %-28s %s\n' "$1" "$3" else printf ' FAIL %-28s expected=%s actual=%s\n' "$1" "$2" "$3"; fail=1; fi}EXPECT_MDX="$1"chk "cwd is WS_ROOT" "$(pwd -P)" "${WS_ROOT:-unset}"chk "relative find" "$EXPECT_MDX" "$(find . -name '*.mdx' | wc -l | tr -d ' ')"chk "unquoted for" "$EXPECT_MDX" "$(for f in $(find . -name '*.mdx'); do echo x; done | wc -l | tr -d ' ')"chk "xargs (whitespace)" "$EXPECT_MDX" "$(find . -name '*.mdx' | xargs -r wc -l 2>/dev/null | tail -1 | awk '{print $1}')"chk "no debris in cwd" "0" "$(ls -A | grep -cx 'Workspace' || true)"exit "$fail"
The unquoted for and the bare xargs are in there on purpose. The entire point of this entry point is that the sloppy forms work. Testing only the correct forms tells you nothing about whether the doorway is doing anything.
The cwd is WS_ROOT line fails whenever something runs without going through ws.sh.
$ cd /somewhere/else$ "$WS/bin/ws.sh" bash tests/path_contract.sh 5 ok cwd is WS_ROOT /path/to/My Workspace ok relative find 5 ok unquoted for 5 ok xargs (whitespace) 5 ok no debris in cwd 0$ echo $?0
All green. The unquoted for returns 5.
Here is the same suite run straight from /, without ws.sh:
$ cd /$ bash tests/path_contract.sh 5 # really invoked by absolute path FAIL cwd is WS_ROOT expected=/ actual=unset FAIL relative find expected=5 actual=15552 FAIL unquoted for expected=5 actual=18670 FAIL xargs (whitespace) expected=5 actual=252796 ok no debris in cwd 0$ echo $?1
Four of five fail and the exit code is 1. The cwd is WS_ROOT line alone would be enough to fail the run, but the others put absurd numbers on screen, which makes it obvious what happened.
The suite runs inside my unattended schedules too, so a broken entry point announces itself before the run rather than at three in the morning.
Four options side by side
Here is everything I tried, in one table. The column that matters most is how each one fails when it isn't followed.
Option
What it protects
How it fails when not followed
Cost to set up
Where it fits
Rename the folder
Everything (the space is gone)
A missed reference fails loudly with "not found"
Grows with the number of references
Young workspaces with few references
Enforce quoting and run ShellCheck
Scripts saved as files
One-liners that slip through return wrong results with exit 0
Writing the rule
Mostly human-written scripts, few agent one-liners
A space-free symlink
The doorway check and writes
find won't follow it and returns 0; readlink -f brings the space back
One line
A shortcut for your own typing; I wouldn't hand it to an agent
Relative paths behind one entry point (ws.sh)
Every command inside the workspace
Skipping the entry point reads the wrong tree, but the suite stops it
Two scripts and three lines of rules
References too scattered to rename, and an agent running many commands
If I had to put it in one line: rename if you can, ws.sh if you can't, and treat rules as support for either. The symlink is the one I've stopped offering to agents.
What this design does not cover
Being straight about the edges.
Nothing outside the workspace.cd closes the inside only. If the agent needs to touch something like /Users/name/Library/Application Support/..., that's an absolute path with a space again. My own excursions outside were few — an indie project touches fewer machines than a team one — so those paths go into environment variables inside ws.sh — which at least makes the references countable. Countable means I can check the quoting at each one.
Error messages still print absolute paths. No way around it. Tools that echo pwd -P, runtimes that put file paths in stack traces. If the agent copies that message and builds its next command from it, the space walks back in. This happened to me once. The fix was a rule — "don't reuse paths lifted from error output" — which is squarely a compliance-dependent design. That's the one place I've compromised.
Spaces in filenames are a separate problem. 5 of 1,816 in my measurement. Small, not zero. Relative paths don't save ./out/report dir/x.txt. That's what -print0 and -0 are for, and no entry point fixes it. I settled on a naming convention for output paths that sticks to hyphens.
Renaming the folder would also just work. Rename My Workspace to my-workspace and most of this article evaporates. I didn't. Chasing down every reference scattered across Dropbox share links, iOS app bookmarks, and several repositories' worth of config seemed like more work than writing one ws.sh. That trade goes the other way in plenty of setups. With few references so far, renaming is the surer bet.
What you hit next, once the entry point is in
A few days after ws.sh went in, different mix-ups started to show, ones that had nothing to do with spaces. For me there were three, in this order.
Third, macOS versus Linux. These measurements are from Linux, but when an agent types sed -i on my iMac, I get the same "succeeded, but not what I meant" shape as the quoting problem. The sed -i That Worked on Linux and Stalled on My iMac covers that one.
The one thing worth checking
If your workspace path has a space in it, run one line:
[ -d $WS ] && echo yes || echo no
If that says no, you're living in this article. Your agent's branches are treating something that exists as missing.
From there, the order I'd suggest: if references are still few, just rename the folder; it's surer than any script, and the gaps in the previous section never exist. If renaming has become too expensive to chase, start with two files, bin/ws.sh and tests/path_contract.sh. Rules come last. Designs that depend on being followed are what I reach for only after I've run out of designs that don't.
Seeing the same files split into 100% and 0.3% depending on how I counted is what finally showed me the shape of it. Hunting for errors turned up nothing, because there weren't any. Doubting the returned values themselves is what exposed nine forms lying to me.
I hope some of this proves useful in your own setup.
Share
Thank You for Reading
Antigravity 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.