You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
investigation(skills): Claude Code may substitute positional $0 inside qa SKILL.md awk programs when /qa gets an argument #1289
Found:#1249's QA phase (2026-10-03) reported: "Skill-argument substitution replaces $0 in qa SKILL.md awk programs, silently breaking §6c Step 1 and manual-AC attribution." Unverified: QA gave no transcript excerpt, and the runner has not reproduced it.
Problem (if real). Claude Code substitutes $ARGUMENTS, $ARGUMENTS[N] and the positional shorthand $0, $1, … in a skill's markdown when the skill is invoked with arguments, as /qa 1249 and the orchestrator's phase prompts do. The docs don't say whether fenced code blocks are exempt. The documented escape is a single backslash (\$0).
.claude/skills/qa/SKILL.md has 5 bare $0 uses on main, all inside awk programs:
:2863–:2866: the manual-AC attribution program (tolower($0), ac = $0)
If $0 becomes 1249, substr(1249, 2) prints 249 for every added line. tolower(1249) never matches, so attribution goes silent. Neither fails loudly.
Other skills may have the same exposure: run rg -n '\$[0-9]' .claude/skills/*/SKILL.md.
AC
AC-1: Reproduce or refute. Invoke a scratch skill containing a bash-fenced awk '{ print $0 }' with an argument, and record what the model receives. Evidence: the result recorded on this issue, with the Claude Code version
AC-2: If AC-1 reproduces, every bare positional $N in the shipped skills (all mirrored copies) is escaped or rewritten. A lint (scripts/lint-skill-*.ts) rejects an unescaped $[0-9] inside skill bodies. Evidence: a gate test, mutation-verified
A scratch project skill (.claude/skills/zzsubst1289/SKILL.md) held a bash-fenced block with awk '{ print substr($0, 2) }' and awk '{ print $1, $2 }', plus an escaped `\$0`. Run with claude -p "<invocation>" --model haiku --output-format stream-json; the model was told to echo the body verbatim.
Invocation
Skill text
Model received
/zzsubst1289 1249
substr($0, 2)
substr(1249, 2)
/zzsubst1289 1249
$1, $2
unchanged
/zzsubst1289 1249 --phase qa
$1, $2
--phase, qa
either
`\$0`
`$0`
Fenced code blocks are not exempt from substitution.
The \$N escape works.
$N is replaced only when argument N exists, so a one-argument /qa {issue} (the orchestrator's prompt, phase-registry.ts:289) breaks only $0.
Exposure on main:
$0, broken on every argument-bearing /qa:
qa/SKILL.md:2220 (§6c Step 1)
qa/SKILL.md:2846-2849 (manual-AC attribution)
$1/$2, broken only when the skill gets two or more arguments:
qa/SKILL.md:1638-1639, 2057, 2961-2962
loop/SKILL.md:126
setup/SKILL.md:139
release/SKILL.md:382
AC-1 is answered: proceed with AC-2. A suggestion for AC-2: move the two QA awk programs into a script (as scripts/qa/precheck.ts already does) rather than only escaping them, so that future inline awk can't reintroduce the problem. The lint is still needed for anything that stays inline.
AC-1 is done. The reproduction is in the comment above (Claude Code 2.1.289, $0 → 1249 inside fenced blocks). AC-3 does not apply. Implement AC-2.
Find the owner before choosing the fix. Inline shell inside SKILL.md is exposed because Claude Code treats skill text as a template. Before deciding "escape vs move to a script", list every producer of inline positional $N. That means all skills, every mirrored copy (.claude/skills, templates/skills, the plugin tree; see chore(plugin): retire the root hooks/ and skills/ copies once ./plugin ships #1271's shared mirror-roots list), and any skill-template generator. If the class needs a rule beyond this issue, surface it rather than patching locally.
Phase rules (both exec and qa): run the full suite at most once, in the foreground, with timeout, and only after a WIP commit. Run targeted vitest files otherwise; CI runs the full suite. QA: this note applies to you too. Put every SEQUANT_MUTATION marker and the AC table inside exec's final ## Summary; the orchestrator builds the PR body from it.
AC-1: already satisfied by the reproduction comment (Claude Code 2.1.289). Fenced code is NOT exempt; \$N escape works; $N is replaced only when argument N exists.
AC-3: not applicable (AC-1 reproduced). Implement AC-2 only.
AC-2: "escaped or rewritten" is fine, but its Evidence: is not command-shaped. Tightened below to npx vitest run scripts/lint-skill-argument-substitution.test.ts (fails today on the 12 sites; passes only once fixed).
Scope Assessment
Non-Goals:⚠️ none stated in the issue. Proposed: no change to how the orchestrator invokes skills; no change to $ARGUMENTS use.
Verification: Manual Test (recorded on issue) Scenario: Given a scratch skill with fenced awk '{ print substr($0, 2) }' → When invoked /x 1249 → Then model receives substr(1249, 2). Recorded in the first issue comment.
AC-2: No bare positional $N in shipped skill bodies; a lint enforces it
Verification: Unit Test (gate test) + CLI lint Scenario: Given any SKILL.md in .claude/skills, templates/skills, plugin/skills → When the lint scans the body → Then an unescaped $[0-9] is a violation; today 12 sites violate it, after the change 0. Assumptions: Only SKILL.md bodies are substituted. references/*.md and scripts/*.sh are loaded as files, not templated (to confirm in exec with the same scratch-skill technique, one extra row).
AC-3: N/A (AC-1 reproduced).
Implementation Plan
Producer inventory (whole-repo grep, (?<!\\)\$[0-9] in SKILL.md, canonical copy; mirrors are generated copies via check-skill-sync --fix; no template generator exists for skill bodies):
Site
Program
Breaks when
qa/SKILL.md:2220
substr($0, 2) (§6c Step 1)
any argument
qa/SKILL.md:2846-2849
manual-AC attribution (tolower($0), ac = $0); the $0 in the comment at :2843 too
any argument
qa/SKILL.md:1638-1639, 2057, 2961-2962
awk '{print $1}', sed/grep $1/$2
2+ arguments
loop:126, setup:139, release:382
awk '{print $2}' etc.
2+ arguments
Not in scope (not substituted, so not violations): qa/scripts/quality-checks.sh (a real script file).
Phase 1: Move the two always-broken QA programs out of the body
Add scripts/qa/ helper(s) (precheck.ts is the precedent), e.g. scripts/qa/added-lines.ts and scripts/qa/manual-ac-attribution.ts, with unit tests that run the real logic against fixture diffs/spec text. The SKILL.md calls them instead of inline awk. Check how precheck is shipped to consumer projects before choosing the location; if consumers do not get scripts/qa/, put the helpers under the skill's own scripts/ dir (like quality-checks.sh) so they ship in all three roots.
Update §6c Step 1 and the attribution block in .claude/skills/qa/SKILL.md, then npm run sync:skills (edit canonical first).
Phase 2: Escape the remaining $N
Escape \$1/\$2 in qa (1638-1639, 2057, 2961-2962), loop:126, setup:139, release:382. Open question below on non-Claude drivers.
Phase 3: Lint
scripts/lint-skill-argument-substitution.ts (+ test): scan SKILL_ROOTS imported from check-skill-sync.ts (the single list, chore(plugin): retire the root hooks/ and skills/ copies once ./plugin ships #1271), SKILL.md files only, flag (?<!\\)\$[0-9] outside a small allowlist for currency ($5, $0.50, $2/call: require the digit not be followed by .digit/k/M//... exact rule fixed by the corpus run). Exit 1 on violation.
Wire lint:skill-argument-substitution into package.json and .github/workflows/ci.yml beside lint:skill-calls.
Gate test scoped to the scanned SKILL.md region: fixture with awk '{print $0}' fails; \$0 passes; currency passes. Mutation-verify: delete the lint's $N pattern → the fixture test fails; restore. Record in PR body with Mutation-verified: AC-2 — <mutation>; scripts/lint-skill-argument-substitution.test.ts > … > <case> failed; restored. (path first).
Run the lint against the real corpus (all three roots) and show 0 violations; also show it reports the 12 sites on pre-change main (git stash/base checkout).
Design Review
Where does this belong? Behavior lives in checked scripts (tested); the lint lives in scripts/lint-skill-*.ts, next to the other skill lints, roots from the shared list.
Simplest correct approach? Escape all 12 sites. Rejected as the only fix: the escape leaves a literal \$0 for any driver that does not template (codex/opencode read the same SKILL.md; to verify), and inline awk stays untested (feat(qa): require detection-pattern verification for skill regex/grep/awk changes #551). So: script the two always-broken QA programs, escape the rest, lint everything.
Senior challenge: "why not escape only?" → driver portability + testability above. "Why not script all 12?" → 1-liner field extraction; cost exceeds benefit, lint catches regressions.
Producers/consumers: producers = hand-written SKILL.md bodies in 3 roots (mirror via sync); no generator. Consumers = Claude Code substitution; non-Claude drivers. Reported, no divergence from the issue's prescription.
Feature Quality Planning
All standard checks pass. Notable:
Consumer projects get these skills via sequant init/sync; the helper scripts must ship with them (see step 1).
Lint false positives on prices are the main risk; verify on the real corpus.
Open Questions
Do non-Claude drivers (codex, opencode) see \$0 literally? Recommendation: check opencode debug skill / codex exec during exec; if yes, the script approach is required for the 2 QA sites and the escape is acceptable only for the 1-2-arg field extractions. Impact: broken awk under those drivers.
Should the lint also cover $ARGUMENTS-style tokens and $(( ))/${1}? Recommendation: no, $[0-9] only (matches the documented substitution set plus the repro). Impact: low.
Recommended Workflow
Phases: exec → qa Quality Loop: disabled Reasoning: Standard bug fix with a gate test (AC-2 declares gate evidence; testgen skipped: the test is specified in step 6). Note for exec/qa: run the full suite at most once; targeted vitest otherwise; put the SEQUANT_MUTATION markers and AC table in exec's final ## Summary.
AC-2's gate test has no recorded mutation result in the PR body (QA verified it: gutting POSITIONAL_RE fails the flag tests)
Missing CHANGELOG entry for a user-facing skill fix
Non-Claude drivers (codex/opencode) may read the escaped $N literally and awk errors silently behind || true
Unconfirmed whether references/*.md files are also substituted (the lint scans SKILL.md only)
The manual-AC attribution awk program was escaped rather than moved to a script, as the spec preferred. It works under Claude Code, but it is still untested inline awk.
The escaped \$N lines are a syntax error for any driver that does not process templates (ledger item 1).
Missing mutation record for AC-2: fixed in this PR. Mutation-verified and recorded in the PR body; the marker parses as valid.
Missing CHANGELOG entry: fixed in this PR.
Codex/opencode read \$N literally and awk fails: fixed in this PR. Fields are rewritten as $(N), which Claude Code leaves alone and awk evaluates the same way. The lint now rejects the escaped form as well.
The manual-AC awk program is escaped inline rather than moved to a script: dropped. In its $(N) form it works for every driver, and the runner executed it against sample input with output identical to main. Moving it would also have to move lint-skill-gates's pattern parser.
Whether references/*.md get substituted: dropped. Claude Code templates only the skill body it injects. References and scripts reach the model through Read or Bash as file contents, so they are not subject to substitution.
Activity
admarble commentedon Oct 4, 2026
AC-1: reproduced (Claude Code 2.1.289)
A scratch project skill (
.claude/skills/zzsubst1289/SKILL.md) held a bash-fenced block withawk '{ print substr($0, 2) }'andawk '{ print $1, $2 }', plus an escaped`\$0`. Run withclaude -p "<invocation>" --model haiku --output-format stream-json; the model was told to echo the body verbatim./zzsubst1289 1249substr($0, 2)substr(1249, 2)/zzsubst1289 1249$1, $2/zzsubst1289 1249 --phase qa$1, $2--phase, qa`\$0``$0`\$Nescape works.$Nis replaced only when argument N exists, so a one-argument/qa {issue}(the orchestrator's prompt,phase-registry.ts:289) breaks only$0.Exposure on main:
$0, broken on every argument-bearing/qa:qa/SKILL.md:2220(§6c Step 1)qa/SKILL.md:2846-2849(manual-AC attribution)$1/$2, broken only when the skill gets two or more arguments:qa/SKILL.md:1638-1639,2057,2961-2962loop/SKILL.md:126setup/SKILL.md:139release/SKILL.md:382AC-1 is answered: proceed with AC-2. A suggestion for AC-2: move the two QA awk programs into a script (as
scripts/qa/precheck.tsalready does) rather than only escaping them, so that future inline awk can't reintroduce the problem. The lint is still needed for anything that stays inline.admarble commentedon Oct 4, 2026
Runner context (before
sequant run)$0→1249inside fenced blocks). AC-3 does not apply. Implement AC-2.$N. That means all skills, every mirrored copy (.claude/skills,templates/skills, the plugin tree; see chore(plugin): retire the root hooks/ and skills/ copies once ./plugin ships #1271's shared mirror-roots list), and any skill-template generator. If the class needs a rule beyond this issue, surface it rather than patching locally.timeout, and only after a WIP commit. Run targeted vitest files otherwise; CI runs the full suite. QA: this note applies to you too. Put everySEQUANT_MUTATIONmarker and the AC table inside exec's final## Summary; the orchestrator builds the PR body from it.admarble commentedon Oct 4, 2026
Complexity: Standard (3 ACs, 5 directories)
AC Quality Check
\$Nescape works;$Nis replaced only when argument N exists.Evidence:is not command-shaped. Tightened below tonpx vitest run scripts/lint-skill-argument-substitution.test.ts(fails today on the 12 sites; passes only once fixed).Scope Assessment
Non-Goals:⚠️ none stated in the issue. Proposed: no change to how the orchestrator invokes skills; no change to
$ARGUMENTSuse.Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: Reproduce or refute — DONE
Verification: Manual Test (recorded on issue)
Scenario: Given a scratch skill with fenced
awk '{ print substr($0, 2) }'→ When invoked/x 1249→ Then model receivessubstr(1249, 2). Recorded in the first issue comment.AC-2: No bare positional
$Nin shipped skill bodies; a lint enforces itVerification: Unit Test (gate test) + CLI lint
Scenario: Given any
SKILL.mdin.claude/skills,templates/skills,plugin/skills→ When the lint scans the body → Then an unescaped$[0-9]is a violation; today 12 sites violate it, after the change 0.Assumptions: Only
SKILL.mdbodies are substituted.references/*.mdandscripts/*.share loaded as files, not templated (to confirm in exec with the same scratch-skill technique, one extra row).AC-3: N/A (AC-1 reproduced).
Implementation Plan
Producer inventory (whole-repo grep,
(?<!\\)\$[0-9]in SKILL.md, canonical copy; mirrors are generated copies viacheck-skill-sync --fix; no template generator exists for skill bodies):substr($0, 2)(§6c Step 1)tolower($0),ac = $0); the$0in the comment at :2843 tooawk '{print $1}',sed/grep$1/$2awk '{print $2}'etc.Not in scope (not substituted, so not violations):
qa/scripts/quality-checks.sh(a real script file).Phase 1: Move the two always-broken QA programs out of the body
scripts/qa/helper(s) (precheck.ts is the precedent), e.g.scripts/qa/added-lines.tsandscripts/qa/manual-ac-attribution.ts, with unit tests that run the real logic against fixture diffs/spec text. The SKILL.md calls them instead of inline awk. Check how precheck is shipped to consumer projects before choosing the location; if consumers do not getscripts/qa/, put the helpers under the skill's ownscripts/dir (likequality-checks.sh) so they ship in all three roots..claude/skills/qa/SKILL.md, thennpm run sync:skills(edit canonical first).Phase 2: Escape the remaining
$N\$1/\$2in qa (1638-1639, 2057, 2961-2962), loop:126, setup:139, release:382. Open question below on non-Claude drivers.Phase 3: Lint
scripts/lint-skill-argument-substitution.ts(+ test): scanSKILL_ROOTSimported fromcheck-skill-sync.ts(the single list, chore(plugin): retire the root hooks/ and skills/ copies once ./plugin ships #1271), SKILL.md files only, flag(?<!\\)\$[0-9]outside a small allowlist for currency ($5,$0.50,$2/call: require the digit not be followed by.digit/k/M//... exact rule fixed by the corpus run). Exit 1 on violation.lint:skill-argument-substitutionintopackage.jsonand.github/workflows/ci.ymlbesidelint:skill-calls.awk '{print $0}'fails;\$0passes; currency passes. Mutation-verify: delete the lint's$Npattern → the fixture test fails; restore. Record in PR body withMutation-verified: AC-2 — <mutation>; scripts/lint-skill-argument-substitution.test.ts > … > <case> failed; restored.(path first).git stash/base checkout).Design Review
scripts/lint-skill-*.ts, next to the other skill lints, roots from the shared list.\$0for any driver that does not template (codex/opencode read the same SKILL.md; to verify), and inline awk stays untested (feat(qa): require detection-pattern verification for skill regex/grep/awk changes #551). So: script the two always-broken QA programs, escape the rest, lint everything.git log -Sforsubstr($0shows only feat(qa): require detection-pattern verification for skill regex/grep/awk changes #551/feat(#551): /qa Section 6c — detection-pattern verification for skill regex/grep/awk changes #572 introducing it). No recurrence ≥2. Class is guarded by the lint, so it stays fixed.Feature Quality Planning
All standard checks pass. Notable:
sequant init/sync; the helper scripts must ship with them (see step 1).Open Questions
\$0literally? Recommendation: checkopencode debug skill/ codex exec during exec; if yes, the script approach is required for the 2 QA sites and the escape is acceptable only for the 1-2-arg field extractions. Impact: broken awk under those drivers.$ARGUMENTS-style tokens and$(( ))/${1}? Recommendation: no,$[0-9]only (matches the documented substitution set plus the repro). Impact: low.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Standard bug fix with a gate test (AC-2 declares gate evidence; testgen skipped: the test is specified in step 6). Note for exec/qa: run the full suite at most once; targeted vitest otherwise; put the
SEQUANT_MUTATIONmarkers and AC table in exec's final## Summary.Label Review
Current: bug. Recommended: bug, planned. Quality loop stays off.
admarble commentedon Oct 4, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 2/3 met
Gaps:
\$Nlines are a syntax error for any driver that does not process templates (ledger item 1).admarble commentedon Oct 4, 2026
Execution Verification
Command:
npm run lint:skill-argument-substitution(in the #1289 worktree, after the runner's$(N)rewrite)Result: Verified by human review
Execution Output
Exit code: 0
Duration: 1s
Negative check (
\$0reintroduced atqa/SKILL.md:2847, then restored). Exit code: 1Human Confirmation:
Verified by
/verifycommandfix(#1289): write awk fields as $(N), not \$N, so untemplated drivers…
admarble commentedon Oct 4, 2026
Runner follow-up ledger (QA pass on PR #1303)
valid.\$Nliterally and awk fails: fixed in this PR. Fields are rewritten as$(N), which Claude Code leaves alone and awk evaluates the same way. The lint now rejects the escaped form as well.$(N)form it works for every driver, and the runner executed it against sample input with output identical tomain. Moving it would also have to movelint-skill-gates's pattern parser.references/*.mdget substituted: dropped. Claude Code templates only the skill body it injects. References and scripts reach the model through Read or Bash as file contents, so they are not subject to substitution.}parses to nothing.