✨ feat(kavach): a hosted session's plain clone can be its own checkout
Slice: #98
kavach gains worktree.ownCheckout. A cloud session works in a plain clone with no linked worktree, so the worktree guard refused every write there (#98). With this setting that clone counts as the session's own. Alok chose this option (A) on 2026-11-15, and chose to keep the guard files refused inside the clone.
What the setting does
-
The gate. A plain (unlinked) checkout passes the ownership gate in place of a Claude-managed worktree only when:
- the hook's own environment holds one of the listed values for every variable in
env(required); - the checkout is the one
CLAUDE_PROJECT_DIRnames, socdinto another clone gains nothing.
Linked worktrees are judged as before: an unmanaged one stays refused even with the setting.
- the hook's own environment holds one of the listed values for every variable in
-
After the gate, every rule still applies: targets confined to the clone, trusted commands, reviewed CLIs, the push lock.
-
Fences. A worktree session finds these outside its worktree, so they stay refused inside an owned clone:
- the clone's git folder (a write there could plant a hook);
- the guard's settings file (
KAVACH_CONFIG) and kavach's own package folder; - each path in the new
protectedPaths(for veda:.claude/hooks/,.claude/settings.json,.claude/settings.local.json,.claude/kavach.json,.claude/sarathi.json,node_modules/).
A target that holds a fence is refused too, so
rm -rf .claudeandmv .claude .claude-offare refused. Without the hook script, the hook would fail open.Paths compare by file identity as well as by name. On this Mac a Write to
.GIT/hooks/pre-commitgot through a plain path comparison, so a case spelling or a symlink now reaches nothing. -
Known gap: this stops slips, not intent. Targets are judged from the command line. A command whose writes the guard counts as the whole checkout still reaches fenced paths:
git checkout HEAD -- <path>,git restore,git applyof a patch under.tmp/,pnpm install. A session set on changing its guard files in a cloud clone can still do it. The README says so, and a test records each command, so a fix flips them knowingly. Whether that is acceptable before veda turns the setting on is Alok's call (#98). -
Off by default.
ownCheckout: nullis refused rather than read as absent.
Evidence
-
Local
pnpm check. Every package's check passes:- kavach: 648 Python tests OK, 753 node tests pass, coverage 99.91% lines and 97.70% branches (kavach's check, re-run after the last change);
- the other packages' checks,
pnpm lintandpnpm guardspass.
Four
scripts/version-rule.test.mjstests fail on this machine only, as on #95: the shell'stag.gpgSignmakes a lightweightgit tagask for a message ("fatal: no tag message?"). CI runs the full check. -
New tests:
test_config.py:test_own_checkout;test_worktree_guard.py:OwnCheckoutTest, 10 tests, covering owned writes and commits, the trusted script and reviewed CLI after the gate, the git folder, guard files and settings file, targets that hold a fence,clone_fencesandin_fencethemselves, targets outside, env mismatch, the project-dir tie, and linked worktrees.
-
Break-the-check runs: each was made to fail open in turn, and the new tests failed:
- drop the git-folder fence;
- ignore
CLAUDE_PROJECT_DIR; - drop the case-insensitive comparison;
- drop the "holds a fence" check (
rm -rf .claudeandmv .claude …were allowed before it).
-
Not exercised in a cloud session. Two things are still unverified there:
- that the hook sees
CLAUDE_CODE_REMOTE=true; - that
CLAUDE_PROJECT_DIRequals the clone.
The cloud probe on #98 ran before this change, and its env output was not captured.
- that the hook sees
What remains (not here)
-
Release kavach and sarathi, bump the pin, and install in the main checkout.
-
Add to veda's
.claude/kavach.json, after the release (an older kavach refuses every call on the unknown key):"ownCheckout": { "env": { "CLAUDE_CODE_REMOTE": ["true"] }, "reason": "a Claude cloud session clones the repository for itself, with no worktree", "protectedPaths": [".claude/hooks/", ".claude/settings.json", ".claude/settings.local.json", ".claude/kavach.json", ".claude/sarathi.json", "node_modules/"] } -
Re-run the cloud probe, including a commit and a push.
-
Decide whether to close the gap above.
CLAUDE_CODE_REMOTE is unset in a desktop session here, Remote Control included (checked with printenv).
No version bump; the release PR follows the merge.
🤖 Generated with Claude Code
Summary by cubic
Makes a hosted session's plain clone count as its own checkout via the new worktree.ownCheckout setting, so Claude can write there instead of every mutation being refused by the worktree guard.
- The clone only counts as owned while the hook's environment matches every variable in the setting's
env, and only for the clone named byCLAUDE_PROJECT_DIR. - Inside an owned clone, its git folder, kavach's settings file and code, and each configured
protectedPathsentry stay refused, as well as any target that holds one of them. - Paths compare by file identity, so a case spelling or a symlink cannot reach a fence.
- Off by default; an older kavach refuses every call on the unknown key.
- Known gap: commands whose writes count as the whole checkout (
git checkout HEAD -- <path>,git apply,pnpm install) can still change fenced paths; the README and tests record this.