Skip to content

The plugin's code shunt never refuses a compound shell command, and a refusal names the scope it would have shown - #1689

Merged
zlareb1 merged 5 commits into
mainfrom
fix/code-shunt-passes-compound-commands
Nov 28, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
fix/code-shunt-passes-compound-commands

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The Claude Code and Codex plugins' code shunt no longer refuses a shell command made of several parts, and refuses a read or a symbol grep only when it can put the index's answer in the refusal: the functions, methods, classes and structs of the lines asked for, with their lines and headers, or the symbol's one definition. A gh issue search inside a chained command now runs without the tracker answer.

Why

A refusal costs the agent one model request and withholds whatever the call would have printed. In a measured agent session on a public Python repository, the shipped hook refused this command:

sed -n 188,198p <source file>; grep -n "self_name" <source file>; grep -n "def test_dotted_name\|def test_.*dot" <test file>

The grep in the middle looked like a symbol lookup, so the hook asked the index. self_name is a local variable, the index held no definition, and the hook refused anyway with "call loom_code_symbol". The 11-line read and the test-name grep, which had nothing to do with that word, were withheld with it. The agent did not make the suggested call. It repeated the read and the greps in its next request, which is one request and a few seconds a session without the plugin does not pay.

Reading the hook showed the same two faults on every refusal path:

  • One judged segment refused the whole command (cd repo; wc -l a; cat small; cat big was refused for the last part).
  • A refusal named an op to call next instead of carrying that op's answer. The whole-file and read-window refusals said "call code.outline" or "call code.enclosing", and the symbol refusal stood when the index had nothing to say.

What is now true:

  • A Bash command of several parts is never refused. A part is anything separated by ;, &&, ||, a newline or a pipe outside quotes. Its reads and greps are still counted for the pass counters. One the hook would have asked the index about as a command of its own (a large file, an over-cap slice, a symbol grep) carries the new pass reason compound_command; the others keep their own reason. No lookup is made and no denial budget is spent for it. A gh issue search followed by & is not judged either.
  • A refusal needs the index's answer in full.
    • A symbol grep is refused only when code.symbol returns exactly one definition and the caller's own lines from modified files fit in the refusal. No definition, several definitions, no reply within 2.5 s, or more local lines than the refusal carries: the grep runs, with pass reason index_unanswered.
    • A read is refused only when one code.outline call (4,000-token budget) returns every declaration that overlaps the lines asked for. A list the budget cut before the end of those lines, a file with no declarations there, or no reply: the read runs. A whole file whose lookup gave no declarations is asked about once per session, whether the index answered with an empty or cut outline or did not answer, so an unreachable server costs each file one wait of 2.5 s and not one per read.
  • A read refusal lists what the read would have shown: one line per declaration with its lines, qualified name and header. For a whole file that is the file's outline. For a ranged read over LOOM_SHUNT_READ_CAP it is the enclosing class and the functions in the range. A refusal that cannot carry this is not given, and spends none of the file's two denials. tail -n N file is judged as the file's last N lines: over the cap, tail -n 300 of a 900-line file is refused with the declarations of lines 601-900.
  • The list holds the kinds code.outline lists by default, and the refusal says so: functions, methods, classes, structs and the units of tests, build files and SQL. An interface, type alias, enum or constant is not among them. The refusal's heading reads "The index's outline of it (lines, qualified name, header; it lists functions, methods, classes and structs, not interfaces, type aliases, enums or constants)".
  • A budget another hook spends during a lookup is kept. The hook reads the session's counts file again when it records a miss or a read-cap denial, so a spend a parallel tool call wrote during the up to 2.5 s wait is not written over.

Design choices a reviewer may question:

  • The rule is syntactic, so cd dir && cat big.py also passes. A narrower rule (exempt a leading cd) would keep more refusals, but the agent could not predict it, and the measured cost of a wrong refusal is higher than the cost of a read.
  • The tracker shunt follows the same rule. git remote get-url origin && gh auth status && gh issue list --search … was answered from the tracker record before; refusing it withholds the first two outputs. ghIssueSearchInCommand now judges only a command that is one gh call, and its chain scan is deleted.
  • Several definitions pass. Which one the caller meant is what its grep would settle, and the old text ("N more, call loom_code_symbol for all") was a cut answer.
  • A file whose outline exceeds the budget is read, not refused. The alternative, a partial outline with a pointer to the rest, is the cut answer this change removes. The budget is 4,000 tokens, chosen from the measurement under Tests: it refuses 62% of the whole-file reads main refuses on that index, where the code.outline default of 1,500 refuses 17%.
  • The refusal names its kinds instead of asking for more of them. The outline's default kinds leave out what the TypeScript extractor records as interface, type, enum and const (and Rust's trait and impl), and a request takes at most 16 kinds, fewer than the default 15 plus those. Listing them needs a server change to code.outline, which is not in this pull request. Until then a file that is mostly types is refused with a short list, and the refusal says what the list leaves out and that a ranged read passes. Measured with the extractor on this repository: frontend/src/api.ts (1,682 lines) has 80 of its 128 declarations in the default kinds, and the generated sdk/typescript/src/generated/ops.ts (11,821 lines) has 1 of 4,403.
  • An unanswered lookup counts as a miss. Recording a miss only when the server answered would make every whole-file read of a large file wait 2.5 s while the server is unreachable.
  • Compound commands are still parsed and counted, so the pass counters keep covering the shell reads agents actually send. The alternative of not judging them at all would have removed most Bash reads from the counters.

Scope and risk

  • Touches the code shunt hook and its two libraries (hooks/loom-code-shunt.mjs, lib/code-shunt.mjs, lib/shell-command.mjs) in the Claude Code plugin, with the Codex copies regenerated, their tests and docs.
  • Deletes what the new rules replace: the refusal text with no answer, the outline price estimate quoted in the old read refusals, and the gh chain scan.
  • Leaves alone: the Read and Grep classification rules and their thresholds, the tracker answer text, the prompt-pack hook's use of symbolAnswerText, and edits, test runs and git commands, which the hook never judged.
  • Hooks in a user's session: a read the hook would refuse now waits for one code.outline reply, bounded at 2.5 s, before it is refused or passed. Before, that decision was local. A call the local rules pass costs no network call, as before. A call the index does not answer waits for that lookup and then runs: once per symbol and once per whole file in a session, and at each over-cap read. With the server unreachable the read now runs; before, a cached repository entry was enough to refuse it.
  • Fewer refusals by design. A deployment that relied on the shunt refusing cd repo && cat big-file or a large file with a long outline will see those reads run. On the measured index 114 of 301 files over 800 lines are now read whole where main refused them, 50 of them among the 71 files over 2,000 lines.
  • tokens_saved on a shunt_hit row is now the file's or the span's tokens less the refusal's own text (characters ÷ 4), because a refusal now carries up to a few thousand tokens of declarations.
  • Server: code.outline joins the session-content class, because a hook now sends it with a path taken from the session, as it does code.symbol and code.enclosing. On a deployment with mirrored document sources on, a client that does not declare session protection is refused on code.outline as it already is on the other code reads. The op's reach manifest entry gains the plugin hook.

Compatibility, rollout and rollback

  • Wire: no op or field added or removed. code.outline is now session_content. code.outcome rows with action=shunt_pass may carry two new source values, compound_command and index_unanswered. A server before this change stores them and reads them as unattributed.
  • Plugin: both manifests go from 1.2.64 to 1.2.67. Other open pull requests hold 1.2.65 and 1.2.66. The hook calls only ops a released server serves.
  • Operator steps: none.
  • Rollback: reverting leaves shunt_pass rows with the two new reasons, which the older vocabulary reads as unattributed.

Tests

Unit tests were not run locally; CI runs them. What I ran:

  • node --test --test-concurrency=1 on tests/code-shunt.test.mjs, tests/code-shunt-hook.test.mjs, tests/code-hooks-failopen.test.mjs, tests/hooks-doc.test.mjs, tests/hook-contract.test.mjs, tests/prompt-pack.test.mjs and tests/prompt-pack-hook.test.mjs in integrations/claude-code-plugin: 144 pass, 0 fail. An earlier run, while the machine was under heavy load, failed timing-bound tests in these files, among them tests this change does not touch; the hook's git calls are bounded at 1.5 s.
  • New and changed cases: a command of several parts is never refused and makes no lookup, while the same read and the same grep as the whole command are refused with the index's answer; the measured command passes with three counted passes; a symbol with no definition, several definitions or 21 local lines passes; a whole-file read whose outline is cut, empty, unanswered or unreachable passes; an over-cap read the index cannot describe passes and spends no denial; declarationsInSpan, wholeSymbolAnswer, isCompoundCommand and the one-command gh search shape; a second whole-file read of a file the index did not outline makes no second lookup, and another session asks for itself; inside a command of several parts a symbol grep is logged as compound_command and a grep for a plain word as single_file_grep; a gh search followed by & is not judged; a hit logs the file's tokens less the refusal's text; tail -n 300 of a 900-line file over a 200-line cap is refused as lines 601-900 with the one declaration there and logged with that span; a whole file whose lookup reached no server is not asked about again in the session; a symbol budget written to the counts file while code.outline is being answered survives both the miss record and the read-cap spend. The tail case and the kept-budget case failed on the previous head: the refusal read "lines 1-300" with the declaration at line 1, and the counts file lost the concurrent key.
  • The bodies of these Python tests, called from a snippet without pytest: test_outcome_pass_reason_is_the_source_from_a_fixed_vocabulary, test_shipped_automatic_senders_have_an_admission_class_or_reviewed_exception (again after the hook's reviewed digest was renewed), test_independent_delivery_roots_are_present_in_the_actual_census, six checks of tests/unit/test_codex_plugin.py (copies current, manifests agree, one version, minimum server version, hook wiring, every hook script wired), the three checks of tests/unit/test_environment_reference.py, test_outline_is_registered_and_listed_with_the_code_tools, and the four source-tree checks of tests/unit/test_public_copy.py. A snippet also confirmed the admission gate refuses an undeclared client on code.outline when session protection is on and admits it when it is off.
  • The 12 cases of bench/acceptance/fixtures/shunt_decisions.json against classifyRead and classifyGrep: 0 mismatches.
  • Gates: ruff format --check ., ruff check, the function-length gate, the secrets gate, every generator --check in make lint (the reach manifest was regenerated, then census: ok), agent_plugin_sync --check, node --check on the changed .mjs files, Biome and Prettier checks on the changed files, claude plugin validate on the plugin and the marketplace listing. The mypy gate reports errors only in server/llm/vertex_auth.py, from an untyped dependency in the local environment.

The outline budget, measured. A refusal needs the file's whole outline inside the budget, so the budget decides how many whole-file reads are still refused. I sent the hook's own code.outline request, with its 2.5 s bound, to a running Loom index of a large public C++ repository, for every third (by length) of the source files over 800 lines at the indexed commit: 300 files under the indexed paths (231 .cpp, 44 .py, 22 .h, 3 .c). main refuses a whole-file read of each of them.

Budget Refused, with the whole outline Read (index_unanswered) Longest declaration list in a refusal
1,500 tokens (this change as first pushed) 52 (17.3%) 248 3,170 characters
4,000 tokens (now) 187 (62.3%) 113 8,351 characters
  • An outline costs a median 3,110 budgeted tokens per file, 2.2 per file line (90th percentile 5.2). The 0.58 per line that main's refusal text quoted, deleted here, does not describe this index.
  • By length, at 4,000: 109 of 134 files of 800 to 1,200 lines are refused, 57 of 95 of 1,200 to 2,000, 11 of 37 of 2,000 to 3,000, and 10 of 34 over 3,000. Two of the 300 have no declarations in the index.
  • The 187 refused files hold 3.26 M tokens (bytes ÷ 4). Their declaration lists come to 0.19 M, 5.8% of that.
  • All 600 requests were answered inside the bound: median 0.36 s, 90th percentile 0.46 s, slowest 1.75 s.
  • Why 4,000: a declaration list measured about 1.9 characters per budgeted token, and the longest refusal at this budget was under 10,000 characters, the length past which the host stores a hook's context strings in a file and shows a preview. That is the maximum seen on this repository, not a limit: the server counts an outline entry at a quarter of its JSON length, so 4,000 tokens admit up to 16,000 characters of entry JSON, and a file with long signatures can produce a longer refusal. The host's documentation states no limit for a deny reason, and I did not test one. Computed from the unbudgeted outlines of the same files, a budget of 8,000 would refuse 258 (86.0%) with lists up to 17,136 characters. The budget is one constant, DEFAULT_OUTLINE_BUDGET.

Replay of recorded sessions. I took every tool call recorded in 60 agent sessions on two benchmark tasks in one public Python repository (281 calls: 210 Bash, 19 Read, 35 Edit, 17 others; 206 of the Bash commands have several parts) and ran each through the hook as the host runs it, once with main's plugin and once with this branch, against a clean checkout of the repository. The 57 calls of the second task were also replayed against that task's own revision, with no refusal on either side. A local stand-in answered code.symbol and code.outline from the checkout's own declarations. For this push I replayed this branch again; main's column is the earlier run, because main's plugin files have not changed since. The machine was loaded, and a hook whose bounded git calls run out of time judges nothing, so a call that logged no decision was run again until it did: in each configuration the hook logged 192 decisions for 112 of the 281 calls.

Kind of call Calls Refused on main Refused here
Bash, several parts: read or search 76 1 0
Bash, several parts: test run 98 0 0
Bash, several parts: edit 24 0 0
Bash, several parts: git 8 0 0
Bash, one part 4 0 0
Read 19 0 0
Edit and other tools 52 0 0
Total 281 1 0
  • main's one refusal is the measured one, reproduced byte for byte. It is the only decision that changed.
  • The hook made 1 index lookup on main and 0 here.
  • With the stand-in answering nothing, the result is the same: 1 and 0.
  • Two greps for a local variable inside commands of several parts, among them the measured one, are logged as compound_command. As first pushed, this change logged them as single_file_grep.
  • To exercise the refusal paths the recorded sessions never reach, I repeated the replay with LOOM_SHUNT_READ_CAP=5 and LOOM_SHUNT_MAX_LINES=100. main refused 44 calls, 26 of them commands of several parts (including one test run, two git commands and two edits). This branch refuses 18, the same 18 single Read calls main refuses, each carrying the declarations in its lines, for example 254-256 test_dotted_name_not_allowed def test_dotted_name_not_allowed(app, client): and 259-273 test_dotted_names_from_app def test_dotted_names_from_app(app, client): for a read of lines 252-259 of a test file. Six of the 18 read that file: its outline of 157 declarations does not fit 4,000 tokens either, but the part that fits ends after the lines they ask for, where the part 1,500 tokens returned ended before them. The hook made 18 lookups, one per refusal, and logged 46 reads and greps as compound_command.

Not verified: which kinds a running index returns for a TypeScript or Rust file (the kinds above come from running the extractor on the files, not from an index); the hook end to end against a running Loom server (the outline measurement above sent the hook's request, not a session's tool calls); the effect on an agent's cost in a live session; what the reads that now pass cost; and the host's limit on the length of a refusal reason. The replay used a clean checkout, so reads that followed an edit in the recorded sessions were judged as unmodified files, which can only add refusals.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I checked the recorded refusal against the transcript, replayed every recorded call through both versions of the hook, and read the full diff of the hook and its libraries.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code


Note

Medium Risk
Changes PreToolUse hook behavior and session-content classification for code.outline, affecting how agents read code in mirrored deployments; fewer refusals by design but more server lookups on deny paths.

Overview
The Claude Code and Codex code shunt now embeds Loom index answers in deny reasons instead of telling the agent to call code.outline, code.enclosing, or code.symbol. Whole-file and over-cap reads are denied only after a bounded code.outline (4,000-token budget) returns declarations for the requested lines; symbol greps are denied only when code.symbol returns a single whole definition. Otherwise the tool call runs (index_unanswered).

Compound shell commands (;, &&, ||, pipes, newlines) are never denied, so chained reads/greps are not blocked by one segment; gh issue-search shunt applies only to a single gh command. Session budgets add miss: keys for failed whole-file outlines; tail -n N is treated as the last N lines; tokens_saved subtracts the denial text size.

Server-side code.outline is classified as session content (like other code reads), with new shunt_pass sources compound_command and index_unanswered. Plugins bump to 1.2.68 with matching docs and expanded tests.

Reviewed by Cursor Bugbot for commit 707f248. Bugbot is set up for automated code reviews on this repo. Configure here.

… refusal names the scope it would have shown

A refusal costs the agent a model request and withholds what the call
would have printed. The shunt refused a three-part command for one of its
parts, a grep for a local variable the index holds no definition of, and
its read refusals named an op to call instead of carrying that op's
answer.

- A Bash command of several parts (a `;`, `&&`, `||` or newline list, or
  a pipeline) is never refused. Its reads and greps are still counted as
  passes (`compound_command`), with no lookup and no denial budget spent.
  A `gh` issue search inside such a command runs.
- A refusal is given only with the index's answer in full. A symbol grep
  is refused when `code.symbol` returns exactly one definition and the
  caller's lines from modified files fit; a read when `code.outline`
  returns every declaration of the lines asked for within its budget.
  Otherwise the call runs (`index_unanswered`).
- A read refusal lists those declarations: lines, qualified name, header.

`code.outline` is now sent by a hook with a session-derived path, so it
joins the session-content class like `code.symbol` and `code.enclosing`,
and its reach gains the plugin hook. Both plugin manifests are 1.2.65.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 28, 2026 12:05pm UTC
loom-telemetry Ready Ready Preview Nov 28, 2026 12:05pm UTC

Request Review

zlareb1 and others added 2 commits November 28, 2026 14:22
…00 tokens

The outline behind a read refusal is asked for with a 4,000-token budget.
Against a running index of a large C++ repository, the hook's own request
for 301 files over 800 lines returned the whole outline of 52 files at
1,500 tokens and of 187 at 4,000, in at most 8,351 characters of
declarations; an outline costs a median 2.2 budgeted tokens per file line.

A whole file the index did not outline is asked about once per session:
the miss is kept beside the denial budgets, so a repeated read of it makes
no second lookup.

A `gh` issue search followed by `&` is not judged. Inside a command of
several parts, a grep that alone would be a symbol lookup is counted as
compound_command, as a read is. The tokens_saved of a hit is net of the
refusal's own text.

Both plugin manifests are 1.2.67.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The hook sends the same ops with the same session-derived fields as
before: `code.outline` with a path and a larger constant budget,
`code.symbol` with a name, `code.outcome` with counts. The pinned digests
of both plugins' copies are renewed.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@cursor cursor 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.

Stale Bugbot comment from a previous run.

zlareb1 and others added 2 commits November 28, 2026 15:22
… and a read refusal says which kinds it lists

`tail -n N file` carries a length and no start, and the hook read the
missing start as line 1: over the read cap, `tail -n 300` of a 900-line
file was refused with the declarations of lines 1-300. The hook now counts
the slice back from the file's last line, so the refusal names lines
601-900 and lists what is declared there.

A budget spend another hook of the session records while this one waits
for `code.outline` is kept: the counts file is read again for the write,
for the miss record and for the read cap's spend.

The refusal's list holds the kinds `code.outline` lists by default. A
TypeScript interface, type alias, enum or constant is not among them, so
the refusal now says what it lists instead of calling the list the file's
declarations.

Text only: the 8,400-character refusal is stated as the longest measured,
not as a limit of the 4,000-token budget; a whole file whose lookup was not
answered is also asked about once per session, which the comments and docs
now say; and the docs no longer list a grep over a directory as denied.

The hook sends the same ops with the same fields, so its reviewed digest is
renewed for both plugins' copies.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
HOOKS.md keeps main's UserPromptSubmit rows (loom-record, its in-process
and detached scripts) and this branch's loom-code-shunt row, which names
the one index lookup a denial makes. Both plugin manifests move to 1.2.68,
one patch above main's 1.2.67.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zlareb1
zlareb1 merged commit e3fdb1e into main Nov 28, 2026
83 of 85 checks passed
@zlareb1
zlareb1 deleted the fix/code-shunt-passes-compound-commands branch November 28, 2026 12:09

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 707f248. Configure here.

const answer = symbolAnswerText(res, { asOf: repo.asOf, namespace: repo.namespace, localGrep, dirtyFiles });
if (answer) verdict.deny = denySymbolGrepWithAnswer({ ...ctx, symbol: verdict.symbol }, answer);
} catch {
/* the plain redirect stands */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cap denials ignore concurrent budget spends

Medium Severity

After the new code.outline wait, settleRead re-classifies the over-cap read with the capCounts snapshot from before the lookup, then spends from a fresh read without checking whether this file's two denials are already used. A parallel over-cap read of the same file that finishes during that wait can exhaust the budget, and this call still denies and increments the count past the limit instead of passing as cap_spent.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 707f248. Configure here.

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