Skip to content

Rewrite grok delegation mechanics around verified behavior - #8

Open
kelchm wants to merge 2 commits into
masterfrom
claude/grok-delegation-mechanics
Open

Rewrite grok delegation mechanics around verified behavior#8
kelchm wants to merge 2 commits into
masterfrom
claude/grok-delegation-mechanics

Conversation

@kelchm

@kelchm kelchm commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Replaces #6, whose guidance was built on two claims that don't survive testing. (Supersedes #7, closed automatically when this branch was renamed — same lineage, same content.)

Why #6 was wrong

Both of its central claims trace back to experiments run inside /tmp:

Claim in #6 Verdict
--sandbox doesn't prevent edits to the working dir False — testing artifact
-w worktree gives "effective read-only protection" False, and unsafe
plan mode cancels on any tool call Partly true — it cancels repo/shell calls
Input ceiling between 119 KB and 140 KB Does not reproduce
  • The sandbox claim. Grok's read-only profile leaves /tmp, /var/tmp, /var/folders and ~/.grok writable by design, so a repo under any of those is unprotected while sandbox-events.jsonl still logs "enforced":true. The event log shows the original experiments ran under /private/tmp/.../scratchpad/. Re-run outside /tmp, grok tried the edit tool, sed -i, echo >>, and creating a new file — all four returned Operation not permitted.
  • The -w claim. In headless mode (-p and --prompt-file) the flag is silently ignored: no worktree is created, pwd is the real checkout, edits land there, and nothing is printed to stderr. Combined with --always-approve, Update Grok review mechanics #6's recipe was strictly more dangerous than the one it replaced.
  • The input ceiling. 151 KB (realistic content) and 204 KB (synthetic, needles at top/middle/bottom) prompts were both read in full, including under plan mode.

What else this corrects

  • Grok does ship a /review skill that works headless, with --local / --branch / --pr modes — the closest analogue to codex review. The old skill asserted grok had none and hand-rolled a replacement.
  • --tools / --disallowed-tools fail OPEN. One unrecognized name anywhere in the list silently restores the entire toolset (exit 0, no warning). The vendor README's tool tables are wrong: it documents bash and run_terminal_cmd; the real tool is run_terminal_command. --deny fails closed with a hard error, so the guard is built on deny rules.
  • grok --sandbox read-only is not codex -s read-only. Verified: codex blocks writes in both $HOME and /tmp; grok blocks only outside its writable exceptions.
  • The "physically can't hit the network" line in grok-review was false — curl returned 200 under the read-only sandbox on macOS (seccomp is Linux-only).

Design: seatbelt, not hard containment

The review guard is --sandbox read-only plus repo-scoped Edit/Write denies, with the shell left available.

An earlier revision of this branch went further — broad Edit(**)/Write(**)/Bash(*)/MCPTool(**) denies with the diff pre-materialized — to get a hard boundary that holds without any OS sandbox. That was dropped deliberately. Grok is cooperative, not adversarial; the realistic failure is it helpfully editing a file mid-review, which is visible in git status and revertible. Buying hard containment meant denying Bash, which meant losing /review (it needs the shell to collect the diff), hand-rolling diff materialization including a bash/zsh-only loop for untracked files, and giving up the native --branch / --pr modes. The cost outweighed the threat.

Changes

  • CLAUDE.md — new grok Mechanics block: /review, custom-stance, and implement recipes, plus the verified traps.
  • grok-review — delegates to the bundled /review; repo-scoped denies (a blanket Write(**) breaks /review's notes file); custom-stance path names the target and lets grok collect the diff.
  • grok-implementationnew, mirroring codex-implementation. Isolates with plain git worktree add + --cwd, generates a task branch, requires a commit SHA in the report, and integrates before cleanup — git worktree remove at the end would otherwise discard anything grok left uncommitted. Closes a coverage gap: grok-4.5 is the designated default implementer but had no skill, while the fallback (codex) did.

Verification

Guard profiles were run against an adversarial canary prompt (modify a tracked file, create a new file, append via shell, write outside the repo, delegate to a subagent), with controls to prove a breach is detectable:

Profile Trials Result
deny rules + sandbox 3 HELD
deny rules + sandbox, shell allowed 3 HELD
deny rules alone, no sandbox 3 HELD
sandbox alone, repo in /tmp 2 BREACHED (enforced=true)
--tools with one bad name 1 BREACHED
--always-approve only 1 BREACHED

Findings were independently reviewed by gpt-5.6-sol, which corrected two overreaches now reflected above (plan mode does not cancel all tool calls; the prompt-offload mechanism is inferred, not established).

Caveats

  • Traps were established on grok 0.2.118 / macOS. Three were re-verified on 1.0.3: -w is still a silent no-op headless, --tools still fails open, and /review --local works under the guard leaving the repo untouched. The rest still carry the 0.2.118 provenance.
  • Linux/Landlock was not tested. The OS sandbox is treated as defense-in-depth throughout, never as the guarantee.

🤖 Generated with Claude Code

The previous guidance (draft PR #6) was built on two claims that don't hold up
under test, both traced to experiments run inside /tmp:

- "--sandbox does not prevent edits to the working directory" — false. Grok's
  read-only profile leaves /tmp, /var/tmp, /var/folders and ~/.grok writable by
  design, so a repo under any of those is unprotected while the sandbox still
  reports "enforced":true. Outside those paths it blocks the edit tool, shell
  writes, and new-file creation at the OS level.
- "-w gives effective read-only protection for the real checkout" — false, and
  unsafe. In headless mode (-p / --prompt-file) the flag is silently ignored: no
  worktree is created, edits land in the real checkout, and --always-approve
  auto-approves everything. Verified twice, with no stderr warning.

Also corrected: there is no ~100 KB input ceiling (151 KB and 204 KB prompts
were read in full), and grok does ship a bundled /review skill that works
headless — the old skill claimed it had none and hand-rolled a replacement.

Changes:
- CLAUDE.md: replace the grok Mechanics block with review (/review), custom
  stance, and implement recipes, plus the verified traps. Notably that grok's
  --sandbox read-only is NOT codex's -s read-only, and that --tools /
  --disallowed-tools fail OPEN on an unrecognized name while --deny fails closed.
- grok-review: delegate to the bundled /review skill instead of reinventing it;
  drop the false "physically can't hit the network" claim (untrue on macOS,
  platform-dependent generally).
- grok-implementation: new, mirroring codex-implementation — isolate with plain
  `git worktree add` + --cwd rather than grok's -w.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added guidance for delegating bounded implementation tasks to Grok in isolated Git worktrees.
    • Added structured Grok review workflows for local changes, branches, and pull requests.
    • Added support for custom review stances, concise findings, and residual test-gap reporting.
  • Documentation

    • Clarified permission controls, sandbox limitations, plan mode, worktree handling, and tool configuration.
    • Documented fallback procedures for unavailable or unsuccessful Grok operations.

Walkthrough

The PR separates Grok review and implementation workflows. It adds isolated worktree procedures, direct review commands, custom stance prompts, structured output guidance, and permission-control documentation.

Changes

Grok workflows

Layer / File(s) Summary
Grok review workflow
dot_claude/CLAUDE.md, dot_claude/skills/grok-review/SKILL.md
Review guidance now uses bundled /review commands for local changes, branches, and pull requests. Custom stances use prompt files. The guidance defines JSON reports, finding limits, read-only controls, sandbox behavior, and deny-rule handling.
Grok implementation workflow
dot_claude/skills/grok-implementation/SKILL.md
The new skill delegates bounded tasks through isolated Git worktrees. It defines prompts, parallel execution, cleanup, reporting, review, and fallback handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: rewriting Grok delegation guidance based on verified behavior.
Description check ✅ Passed The description directly explains the corrected Grok behavior, updated skills, implementation workflow, and verification results.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dot_claude/CLAUDE.md`:
- Around line 55-57: Remove the manual Markdown line breaks so the Grok
mechanics list item in dot_claude/CLAUDE.md lines 55-57 remains on one physical
line, and the review description in dot_claude/skills/grok-review/SKILL.md lines
5-7 also remains on one physical line; preserve their existing wording and
formatting otherwise.
- Around line 59-60: Update the bundled /review command examples to enforce
repository-scoped read-only access by adding Edit($PWD/**) and Write($PWD/**)
denials. Apply this in dot_claude/CLAUDE.md lines 59-60,
dot_claude/skills/grok-review/SKILL.md lines 24-25 for local review mode, and
lines 28-33 for branch and PR review modes; keep $TMPDIR writable for review
notes.
- Around line 71-73: Update the worktree setup and cleanup instructions around
the grok invocation to require a unique, task-specific path instead of the
literal ../grok-task; pass that path consistently to git worktree add and the
grok --cwd option, and remove the worktree after completion.

In `@dot_claude/skills/grok-implementation/SKILL.md`:
- Around line 3-9: The front-matter description in SKILL.md is manually wrapped
across multiple lines; rewrite the description value as one uninterrupted line
while preserving its exact wording and meaning.
- Around line 25-37: Update the Grok prompt and cleanup flow around WORKTREE and
PROMPT so the final handoff occurs before removing the detached worktree:
require Grok to commit all changes on a task branch and report the commit SHA,
or export/apply a patch, then perform git worktree remove only after that
handoff succeeds.
- Around line 25-26: Update the worktree setup and cleanup instructions around
the WORKTREE variable to generate a unique task-specific path for each
invocation instead of using the shared ../grok-task path. Pass the same
$WORKTREE value to both git worktree add --detach and git worktree remove,
including the corresponding cleanup flow at lines 59-61.

In `@dot_claude/skills/grok-review/SKILL.md`:
- Around line 47-48: Update the prompt-building command in the Grok review skill
to include untracked files alongside the existing tracked diff. Append distinct
sections containing the tracked changed-file names from git diff --name-only
HEAD and untracked non-ignored files from git ls-files --others
--exclude-standard, including each untracked file’s materialized content in
PROMPT.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1278553f-eff5-42b2-9553-94631b9fa4af

📥 Commits

Reviewing files that changed from the base of the PR and between 2489c28 and 7a55fb7.

📒 Files selected for processing (3)
  • dot_claude/CLAUDE.md
  • dot_claude/skills/grok-implementation/SKILL.md
  • dot_claude/skills/grok-review/SKILL.md

Comment thread dot_claude/CLAUDE.md Outdated
Comment thread dot_claude/CLAUDE.md Outdated
Comment thread dot_claude/CLAUDE.md Outdated
Comment thread dot_claude/skills/grok-implementation/SKILL.md Outdated
Comment thread dot_claude/skills/grok-implementation/SKILL.md Outdated
Comment thread dot_claude/skills/grok-implementation/SKILL.md Outdated
Comment thread dot_claude/skills/grok-review/SKILL.md Outdated
Comment on lines +47 to +48
# Write the stance below into $PROMPT, then append the target diff:
{ echo; echo '--- CHANGES ---'; git --no-pager diff HEAD; } >> "$PROMPT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

git --no-pager diff --name-only HEAD
git ls-files --others --exclude-standard

Repository: kelchm/dotfiles

Length of output: 153


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'Tracked modified files against HEAD:\n'
git --no-pager diff --name-only HEAD || true

printf '\nUntracked files (tracked, name-only if untracked):\n'
git ls-files --others --exclude-standard || true

printf '\nGrok review skill relevant section:\n'
cat -n dot_claude/skills/grok-review/SKILL.md | sed -n '35,60p'

printf '\nSearch for local review /diff behavior hints:\n'
rg -n --no-heading 'review --local|git diff|PROMPT|UNTRACKED|others' dot_claude -S

Repository: kelchm/dotfiles

Length of output: 3602


Include untracked files in custom-stance reviews.

git diff HEAD only includes tracked changes. If a new untracked file is being reviewed, this prompt omits the file entirely. Append a separate untracked-file materialization after the tracked diff; for example append the outputs of git --no-pager diff --name-only HEAD and git ls-files --others --exclude-standard into $PROMPT, formatted as distinct sections.

🧰 Tools
🪛 SkillSpector (2.5.1)

[warning] 47: [RA2] Session Persistence: Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Remediation: Remove any persistence mechanisms (cron jobs, startup scripts, state files). Skills should not maintain state across sessions without explicit user consent.

(Rogue Agent (RA2))

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dot_claude/skills/grok-review/SKILL.md` around lines 47 - 48, Update the
prompt-building command in the Grok review skill to include untracked files
alongside the existing tracked diff. Append distinct sections containing the
tracked changed-file names from git diff --name-only HEAD and untracked
non-ignored files from git ls-files --others --exclude-standard, including each
untracked file’s materialized content in PROMPT.

Drops the hard-containment review path. It defended against an adversary we
don't have: grok is cooperative, and the realistic failure is it helpfully
editing a file mid-review — which is visible in `git status` and revertible.
Buying a hard boundary meant denying Bash, which meant losing the bundled
/review skill (it needs the shell to collect the diff) and hand-rolling diff
materialization, including a bash/zsh-only loop for untracked files. Not worth
it, and it discarded /review's native --branch and --pr modes.

Review guard is now: --sandbox read-only plus repo-scoped Edit/Write denies,
shell left available. Custom-stance reviews name the target and let grok collect
the diff itself rather than pre-materializing it.

Implementation keeps the stronger worktree handoff: a generated task branch, a
required commit SHA in the report, and integration before cleanup. The previous
version ran `git worktree remove` at the end, which discards grok's work if it
left anything uncommitted.

Re-verified on grok 1.0.3 (macOS): `-w` is still a silent no-op headless (edit
landed in the real checkout, no worktree created); `--tools` still fails open
with one bad name; `/review --local` works under the guard and left the repo
untouched. Version references reconciled — the traps were established on
0.2.118, with these three re-checked on 1.0.3.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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