feat(autodev): cwd guard — .clawtool/autodev.toml as project opt-in marker#16
Merged
Conversation
… marker `runAutodevHook` now exits 0 silently when the working directory does not resolve upward to a project containing `.clawtool/autodev.toml`. The marker file is the canonical per-project opt-in for the autodev Stop-hook self-trigger loop, replacing the previous behavior where a globally-armed flag fired in every Claude Code session on the host. This is the smallest-valid first commit from the autodev hook redesign: one new helper, one early-return at the top of the hook, one project marker in this repo. No schema changes, no new subcommands, no daemon changes. Resolution order in `findAutodevTOML`: 1. `$CLAWTOOL_AUTODEV_REPO` if set is authoritative — returns the marker at `<envRoot>/.clawtool/autodev.toml` when present, !ok when absent. Stale env var does NOT fall through to the cwd walk. 2. Otherwise upward walk from `$PWD` until marker found or filesystem root. Tests cover four cases: no-marker exits 0 without incrementing the counter, marker-present respects the existing flag-check, deep-subdirectory walk finds upward marker, env-override is authoritative when set. Verified clean under `go test -race ./internal/cli/`. Stops the cross-project nuisance from the 2026-05-03 incident (operator's ~100 Claude terminals all firing the autodev loop because the install was written to user-global `~/.claude/settings.json`). The legacy hook still present in any operator's settings.json becomes a no-op outside this repo; inside the repo, the new `.clawtool/autodev.toml` keeps the loop firing as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Smallest-valid first commit from the autodev hook redesign (ADR-037). Adds a cwd guard at the top of
runAutodevHookthat exits 0 silently when the working directory does not resolve upward to a project containing.clawtool/autodev.toml.The marker file is the canonical per-project opt-in for the autodev Stop-hook self-trigger loop, replacing the previous behavior where a globally-armed flag fired in every Claude Code session on the host.
What this fixes
The 2026-05-03 incident: a
clawtool autodev starthad been written to~/.claude/settings.json(user-global). The Stop hook then fired in every Claude Code session on the operator's host (~100 projects), with a clawtool-flavored prompt that was nonsensical outside the clawtool project. Hot-fix at the time was to manually strip the entry from settings.json. This commit makes the legacy install a permanent no-op outside the clawtool repo: the hook still loads, but exits 0 silently when the cwd guard fails.Resolution order in
findAutodevTOML$CLAWTOOL_AUTODEV_REPOif set is authoritative — returns the marker at<envRoot>/.clawtool/autodev.tomlwhen present,!okwhen absent. A stale env var does NOT fall through to the cwd walk; falling through would silently pin a different project's marker, which is exactly the cross-project leakage the cwd guard is built to prevent.$PWDuntil either the marker is found or the filesystem root is reached. Symlinks are not followed.Files
internal/cli/autodev.go(+60 lines) —findAutodevTOMLhelper, doc updates, cwd guard at the top ofrunAutodevHookinternal/cli/autodev_hook_cwd_test.go(+221 lines) — five new tests:TestRunAutodevHook_NoProjectMarker_ExitsZero— proves the active-bleeding fix: legacy flag + counter present, no marker, hook exits 0 without emitting decision:block, counter does NOT incrementTestRunAutodevHook_ProjectMarkerPresent_FlagRespected— proves the legitimate path still works: marker + flag together fire as beforeTestFindAutodevTOML_WalksUpward— deep subdirectory finds upward markerTestFindAutodevTOML_NotFound— graceful !ok when no marker exists upwardTestFindAutodevTOML_EnvOverride— authoritative env var, no fall-through on stale value.clawtool/autodev.toml(+26 lines) — project-opt-in marker for the clawtool repo itself, so this repo's autodev session keeps firing after the cwd guard landsVerification
Forward compatibility
The
.clawtool/autodev.tomlschema is forward-looking — fields (name,enabled,cap_per_session,[loop] steps,stop_command) are documented and ready for the v1 reader (Phase 5 of the autodev redesign), but today only the file's presence is checked. Existing operators upgrading to this binary need to either:clawtool autodev initonce in each project where they want the loop (forthcoming subcommand from Phase 4), or.clawtool/autodev.tomlmanually (template above).This deliberate friction is the design — implicit per-project opt-in via the marker file is the whole point of the redesign.
Wiki context
ADR-037 (
wiki/decisions/037-autodev-hook-redesign.md, gitignored local knowledge base) documents the full four-axis redesign. This PR ships axis 1's smallest valid subset; axes 2-4 (autodev.toml schema reader, prompt parameterization, firing-decision pipeline with quiet-state gate + substrate probe + lock format) land in follow-up PRs.Hygiene note
Commit ran via
mcp__clawtool__Commit(Conventional Commits + pre_commit rules.toml gate). gofmt-clean and race-clean rules trigger on this changeset (Go files touched) — both verified clean above. No internal-doc-id leakage in user-facing surfaces.