I recently published a two-part guide on AI-driven development (AIDD): part 1 covers the building blocks – project instructions, skills, hooks, MCP, memory –, part 2 sets it all up step by step in VS Code on Windows, including PowerShell hooks and a runner that works through a queue of work packages in the background.
Guides like that get copied line by line. So before publishing, I had every script from part 2 run in an isolated test repository – by Claude Code itself, in real sessions rather than dry runs: hooks firing on real tool calls, memory being written, the runner implementing actual work packages and opening (fake) pull requests. Most of it worked. Seven things didn't, or didn't work the way I had assumed.
1. The hook that "blocks" – but doesn't
Claude Code hooks can veto a tool call. The rule is simple: exit code 2 blocks, and whatever the script writes to stderr goes back to the agent as the reason. Any other non-zero code, including 1, is just a non-blocking error – the agent carries on.
My protection hook for generated EF Core migrations ended with exit 2. Registered like this, it never blocked anything:
{ "type": "command", "shell": "powershell",
"command": "& \"$env:CLAUDE_PROJECT_DIR/.claude/hooks/protect.ps1\"" }
The reason is PowerShell, not Claude Code. When you run a script via -Command and it exits with 2, the PowerShell process still exits with 1 – $LASTEXITCODE inside is 2, but that is not what the caller sees. I checked both Windows PowerShell 5.1 and PowerShell 7.7: exit code 1 in both. The fix is one statement at the end of the command:
"command": "& \"$env:CLAUDE_PROJECT_DIR/.claude/hooks/protect.ps1\"; exit $LASTEXITCODE"
With that, the hook returns 2, the write to Migrations/ is blocked, and the agent receives the message from stderr. If you write hooks in PowerShell, test the exit code from the outside – a hook that silently doesn't block is worse than no hook, because you think you're protected.
2. Mojibake in the agent's context
A SessionStart hook prints the last session handoff, so a new session starts where the previous one stopped. Whatever such a hook writes to stdout goes straight into the context. My handoffs are in German, and the session transcript showed what the agent actually received:
SessionStart:startup hook success: Letzte Sitzungs�bergabe …
A probe hook made it obvious. It printed äöü ß and its own console encoding – the transcript recorded ��� � and ibm850. Claude Code reads hook output as UTF-8; PowerShell on Windows writes in the old console code page. Any non-ASCII character is affected – German umlauts, accented names, typographic dashes. The fix goes at the top of every hook script:
$utf8 = [Text.UTF8Encoding]::new($false)
[Console]::InputEncoding = $utf8 # paths in the JSON on stdin
[Console]::OutputEncoding = $utf8 # what the agent reads
And when the script reads files, Get-Content -Encoding UTF8 – Windows PowerShell 5.1 otherwise assumes ANSI for files without a BOM. A side finding from the same probe: with "shell": "powershell", Claude Code ran the hook in PowerShell 7 because it was installed, not in Windows PowerShell 5.1. Write hooks that work in both.
3. Your allow rules don't apply in a folder you haven't trusted
The project's .claude/settings.json allowed dotnet build, dotnet test and dotnet format without prompting. In my headless runs, Claude Code printed this instead:
Ignoring 3 permissions.allow entries from .claude/settings.json: this workspace
has not been trusted. Run Claude Code interactively here once and accept the
trust dialog …
That is a deliberate safety feature – a cloned repository must not be able to grant itself permissions. Deny rules and hooks still apply in an untrusted folder; allow rules don't.
Update: the first version of this section claimed that every new git worktree is untrusted. That was wrong – a reader's question in the comments made me check. According to the docs, a worktree inherits trust from the main checkout. My test repository was a fresh copy nobody had ever trusted, which is why the warning appeared there. Checked against my real, trusted repository, though, the worktree still ignored the allow rules. The warning names the key it looks up:
… or set projects["C:/Entwicklung/…/mitterbucher-website"].hasTrustDialogAccepted: true in …\.claude.json.
My trust entry is stored under c:/Entwicklung/… – only the case of the drive letter differs, so on Windows the inheritance can silently fail. My runner creates one worktree per work package and passes the tool list on the command line. That works regardless of trust and keeps the permissions for unattended runs in the runner script rather than in a file inside the repository the agent works on:
claude -p 'Implement the work package from the input completely. Commit in small steps.' `
--permission-mode acceptEdits `
--allowedTools 'Read,Edit,Write,Grep,Glob,Bash(dotnet build *),Bash(dotnet test *),Bash(git add *),Bash(git commit *)' `
--max-turns 80 --max-budget-usd 5 --output-format json
4. Path-scoped rules are lazy – and my first test was wrong
Rules in .claude/rules/ can carry a paths filter in their front matter:
---
paths:
- "tests/**/*.cs"
---
# Tests
- Test names: Method_Situation_Expectation.
My first test said they didn't work at all: after reading a test file, the agent knew nothing about the naming convention. Even an unconditional rule without paths was missing. The debug log (claude --debug) explained it – one line per file: "not loading … CLAUDE.md: it … is in a session's scratchpad". I had built the test repository inside Claude Code's own temporary scratch folder, and Claude Code deliberately doesn't load project instructions from there.
Moved to a normal folder, everything behaved as documented:
| Session | CLAUDE.md |
rule without paths
|
rule with paths
|
|---|---|---|---|
| no file read | loaded | loaded | not loaded |
after reading tests/…/SmokeTests.cs
|
loaded | loaded | loaded |
Two lessons: path-scoped rules only appear when the agent reads or edits a matching file – so "the agent ignores my rule" may just mean it hasn't touched such a file yet. And when a test of your harness fails, read the debug log before you believe the result.
5. One character that silently disabled a permission rule
This one wasn't in the guide but in my own settings. I had allowed ssh commands to my server with a rule like this (host and key changed here):
"allow": [ "Bash(ssh -i * deploy@203.0.113.10:*)" ]
It never matched. The :* suffix is an alternative spelling of a trailing wildcard – but only at the very end and only if it is the rule's only wildcard. With a * in the middle, the colon is taken literally, so the rule required deploy@203.0.113.10: followed by something. Claude Code does log a warning about it at startup – I only found it in the debug log.
Fixing the syntax exposed a second problem: the * in the middle matches any text, including extra ssh options such as -o ProxyCommand=… – which makes ssh run an arbitrary local program. So the key path is now pinned, the wildcard sits only at the end, and two deny rules close the remaining gap:
"allow": [ "Bash(ssh -i ~/.ssh/id_deploy deploy@203.0.113.10 *)" ],
"deny": [ "Bash(ssh *ProxyCommand*)", "Bash(ssh *proxycommand*)",
"Bash(ssh *LocalCommand*)", "Bash(ssh *localcommand*)" ]
Both spellings are there because ssh treats option names case-insensitively, while permission rules are case-sensitive text patterns. I tested it without touching the server: -o ProxyCommand=echo is denied in both spellings, while ssh … -V (prints the version, opens no connection) still runs – proof that the allow rule matches and the denials come from the deny rules.
6. Two Claude Code installations on one machine
claude --version in the terminal said 2.1.202. The VS Code extension was running 2.1.331. An old global npm installation was on the PATH, while the extension ships its own binary – so terminal and editor were running different versions with different fixes and behaviour, and nothing told me.
The fix: remove the npm package and use the native installer, which updates itself:
npm uninstall -g @anthropic-ai/claude-code
irm https://claude.ai/install.ps1 | iex
The installer put claude.exe into ~\.local\bin – and warned that this folder was not on the PATH. Without that step, the terminal has no claude at all:
$bin = Join-Path $HOME '.local\bin'
$user = [Environment]::GetEnvironmentVariable('Path', 'User')
if (($user -split ';') -notcontains $bin) {
[Environment]::SetEnvironmentVariable('Path', $user.TrimEnd(';') + ";$bin", 'User')
}
Open terminals – including VS Code's integrated one – only see the change after a restart.
7. One from the docs: shortcuts Windows keeps for itself
Not a test failure, but something I noticed while checking every detail against the documentation: the VS Code extension's shortcuts for "Focus Input" (Ctrl+Esc) and "Open in New Tab" (Ctrl+Shift+Esc) collide with the Windows shortcuts for the Start menu and Task Manager. On Windows, rebind those two commands in VS Code's keyboard shortcuts. Alt+K – insert the current selection as an @file#lines reference – works fine and is the one I use most.
What worked: the background runner
The part I was most curious about worked on the first run. The runner is a PowerShell loop that takes Markdown work packages from an inbox folder, creates a git worktree per package, lets claude -p implement it, runs dotnet test itself and opens a draft pull request only if the tests are green. The test had two packages – a real one (volume discounts with a fixed interface and permitted paths) and a control package with a deliberately failing test:
| Check | Result |
|---|---|
| discount package implemented | 3 commits, 3 policy classes + tests, only in the permitted paths |
| verdict | independent dotnet test green → pushed, draft PR opened |
| control package with red test | moved to failed, not pushed, worktree kept for analysis |
| time | about 3 minutes for both |
cost from total_cost_usd
|
about 0.80 US dollars for the real package, 0.30–0.35 for the control package, at API prices |
| all checks | 11 of 11, for the German and the English version of the script |
The one design decision I'd recommend regardless of tooling: the agent never decides whether it is done. It may build, test and commit – pushing, the test verdict and the pull request belong to the script, and the merge belongs to a human.
Takeaway
None of these issues would have shown up by reading the scripts. Each one needed a real run and a look at what actually arrived – the exit code seen from outside, the bytes in the transcript, the debug log. Treat your AI harness like any other code: version it, test it, and don't trust a check you haven't seen fail.
The complete setup – directory layout for rules and memory, all hook scripts, the runner, VS Code tasks and the security notes – is in the guide:
- Part 1: AIDD in practice: harness, skills, MCP and memory
- Part 2: Setting up the AI development environment in VS Code
I'd like to hear which gotchas you ran into with your own agent setup – especially on Windows.
Top comments (8)
Gotcha 3 is the one with the widest blast radius for anyone copying the runner: every new worktree is an untrusted folder, so the allow rules in .claude/settings.json are effectively dead for exactly the flow the runner exists to automate. How do you handle that in practice — trust each worktree folder from the runner, or pass the tool list on the command line every time? Trusting programmatically feels like it quietly defeats the safety feature you describe (a cloned repo must not grant itself permissions), so I'm curious where you landed. And on gotcha 5, the ProxyCommand escape is a nasty one — does your deny rule also catch the no-space form, ssh -oProxyCommand=..., or does the permission matcher need the space to match?
Good questions, and the first one made me dig further, so thanks.
Trust: According to the docs, trust for a worktree is keyed on the main checkout's root, so worktrees of a repo you've trusted shouldn't need trusting on their own. In my runner test the main checkout was a fresh copy nobody had ever trusted, so "every new worktree is untrusted" was an overgeneralisation on my part. I'll correct it. There is a Windows catch, though: checked against my real, trusted repo, the worktree still ignored the allow rules. The warning asks for projects["C:/…/repo"], while my trust entry is stored under c:/…/repo. Only the case of the drive letter differs.
In practice I keep passing the tool list on the command line. It works regardless of trust, and the permissions for unattended runs live in the runner script rather than in a file inside the repo the agent works on. Trusting folders programmatically is what I'd avoid, for exactly the reason you give.
ssh: The rule is Bash(ssh ProxyCommand), so no space is needed before the option. I tested -oProxyCommand=echo, -oproxycommand=echo and -o "ProxyCommand echo", and all three were denied. Not covered: other casings such as PROXYCOMMAND, and a config file passed with -F.
"The agent never decides whether it is done" is the rule we built Halfcycle on too. Seven gotchas from testing one guide is the real cost of a hand-built harness: every hook and rule is code you now maintain. Halfcycle is that harness ready made inside Claude Code or Codex, with reviewers that didn't write the code and a person signing off each phase, and it keeps improving without you chasing the next guide. Try npx halfcycle on one of your work packages and compare it with the runner.
The exit code 2 vs 1 finding is the one worth copying: a hook that fails open looks identical to one that works until you test it from outside. Running the hook with a deliberately bad input and checking that the tool call is actually blocked seems like a good smoke test to keep for any guard hook, and it also catches the same failure in other shells.
Thanks! That's exactly how the bug showed up: pipe a tool call for a protected path into the hook the same way Claude Code runs it, then check for exit code 2 and the message on stderr. Worth keeping as a smoke test next to every guard hook.
One more for the worktree-per-package runner, since it bit me twice. To skip the install step, my worktrees had their node_modules as a junction pointing at the main checkout. On Windows,
git worktree remove --forcefollows the junction and deletes the target. The first time the main checkout lost 175 of 557 packages, the second time a whole node_modules was empty. Now each junction is removed on its own first (cmd /c rmdirtakes only the link), the script checks that the path is gone, and only then runsgit worktree remove.Thanks for sharing, that's a nasty one, and removing the junction first, checking, then removing the worktree is a sound order. I tried to reproduce it with Git 2.54.0.windows.1: git worktree remove, with and without --force, didn't follow the junction, and the target stayed intact. It didn't remove the worktree either, though: it unregistered it, left the folder with only the junction inside and still exited with 0. Deleting that leftover with Remove-Item -Recurse (PowerShell 5.1 and 7) or rmdir /s /q didn't touch the target in my test. Which Git version were you on? Either way, checking that the folder is really gone, as you do, catches both cases.
The terminal on 2.1.202 and the extension on 2.1.331 with nothing telling you is the gotcha I'd worry about most, since a hook test that passed in one says little about the other. With the extension still shipping its own binary next to the native installer's claude.exe, can the two drift apart again, or do they update together now?