Files
magpie/internal/gateway/claude_workdir_owner_windows.go
T
yetoneandyg3415 17363b7e30 claude: Claude Code runs share a folder only the user owns, the caller's system prompt is cached apart, and auto memory is off (#626, yg3415) — main already ran every Claude Code run in one $TMPDIR/magpie-claude so Anthropic's prompt cache is read again; this takes yg3415's version of that: the folder is magpie-claude-work-<uid> (the uid where the temp folder is shared, as /tmp is on Linux), made 0700 and used only when it is a real folder the user owns that no one else can write to (else the run works in a folder of its own, as before), so nobody else can put a CLAUDE.md in front of every run; the caller's system prompt goes to Claude Code as a block of its own with a 1h cache_control breakpoint (CLAUDE_CODE_PROMPT_CACHE_TTL=1h, since Anthropic refuses a 1h breakpoint after a 5m one), so requests with one system prompt and different conversations share its cache entry; and CLAUDE_CODE_DISABLE_AUTO_MEMORY=1, so a memory Claude Code writes in one caller's conversation doesn't show up in every other one in the shared folder. Merged onto main by hand: the run still starts through binary.command/binary.env, so a Claude Code in WSL works in the shared folder too; on Windows the folder is in the user's own %TEMP% and Go reports every folder there as 0777, so the mode check is skipped there (it refused every run before). Tests from the PR (TestClaudeRunsShareAWorkDir with a home kept in git, TestClaudeWorkDirOthersCanWriteIsAvoided, TestClaudeInstructionsCachedApart) pass; go vet (darwin, GOOS=windows), builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
Co-authored-by: yg3415 <115795347+yg3415@users.noreply.github.com>
2026-10-04 18:25:44 +08:00

17 lines
609 B
Go

package gateway
import "os"
// ownedByMe says the file belongs to the user magpie runs as: on Windows
// the folder is in the user's own %TEMP%, which no one else writes.
func ownedByMe(os.FileInfo) bool { return true }
// othersCanWrite is false on Windows: Go reports every folder that isn't
// read-only as 0777 there, ACLs not being mode bits, and the folder is in
// the user's own %TEMP%.
func othersCanWrite(os.FileInfo) bool { return false }
// claudeWorkName is the work folder's name in the temp folder, the user's
// own on Windows.
func claudeWorkName() string { return "magpie-claude-work" }