Skip to content

claude-iso: auto-allow main repo in sandbox for -w worktree sessions#157

Merged
potiuk merged 1 commit into
apache:mainfrom
potiuk:feat/claude-iso-worktree-main-repo-allowread
May 14, 2026
Merged

claude-iso: auto-allow main repo in sandbox for -w worktree sessions#157
potiuk merged 1 commit into
apache:mainfrom
potiuk:feat/claude-iso-worktree-main-repo-allowread

Conversation

@potiuk
Copy link
Copy Markdown
Member

@potiuk potiuk commented May 14, 2026

Summary

  • claude -w (and claude --worktree) materialises a new worktree at
    <main>/.claude/worktrees/<name> and chdirs into it before sandbox
    init. The sandbox's relative "." allowRead rule then covers only
    the worktree subtree, not the main repo — so files outside the
    worktree's own working tree (siblings of .claude/worktrees/)
    aren't readable from the session.
  • When -w / --worktree is in the args, claude-iso now resolves
    the main repo via git rev-parse --git-common-dir (works from the
    main checkout and from nested worktrees) and prepends a one-shot
    --settings '{"sandbox":{"filesystem":{"allowRead":["<main-repo>"]}}}'
    to the claude argv. claude merges this into the loaded settings
    stack at startup, so the path is in scope before the sandbox
    initialises — same session, no on-disk edits, nothing to clean up
    when the worktree is abandoned.
  • A short dimmed stderr banner reports the path added. No prompt.
  • Skipped silently when not inside a git repo, or when -w isn't
    passed.

Test plan

  • bash -n and zsh -n both accept the script
  • prek run --files tools/agent-isolation/claude-iso.sh passes
  • -w detection covers -w, --worktree, -w <name>,
    --worktree=<name>, and -w mixed with other flags
  • JSON-escaping holds for paths containing " and \ (validated
    with python3 -c 'import json,sys; json.load(sys.stdin)')
  • Manual end-to-end: claude-iso -w from /path/to/repo,
    confirm the main-repo path is readable inside the worktree
    session

When `claude-iso -w` is launched from inside a git repo, prepend a
one-shot `--settings` JSON to the claude argv that adds the main
repo's path to sandbox.filesystem.allowRead. The main repo is
resolved via `git rev-parse --git-common-dir` so it works from the
main checkout as well as nested worktrees.

This fixes the visibility gap that `-w` creates: the worktree is
materialised mid-launch, and once Claude chdirs into it the
sandbox's relative `"."` rule no longer covers the original main
repo. The injection merges with the settings stack before sandbox
init, so it takes effect for the same session without any on-disk
edit (no settings.local.json bootstrap, no per-worktree cleanup).

A short stderr banner reports the path added; no prompt.

Generated-by: Claude Code (Claude Opus 4.7)
@potiuk potiuk merged commit ab66c57 into apache:main May 14, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant