Skip to content

Apply system prompts across native JavaScript chunks and embedded text modules - #1011

Open
mike1858 wants to merge 3 commits into
mainfrom
fix-system-prompt-matching-1008
Open

mike1858 wants to merge 3 commits into
mainfrom
fix-system-prompt-matching-1008

Conversation

@mike1858

@mike1858 mike1858 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Why

A fresh configuration on Claude Code 2.1.280 reports 642 missing system prompts, exactly reproducing the report in #1008. Prompt application searches only the 21 KB entrypoint, but the executable distributes its prompts across 1,975 JavaScript modules and embedded text assets. Resetting the local Markdown files cannot fix the missing search scope.

This addresses the prompt-loading failure in #1008, not the separate feature-patch failures or release request in that issue.

What changed

  • Extract the native module corpus for prompt application even when preventUpdateToUnsupportedVersions is disabled.
  • Load prompt definitions once, then search JavaScript and Bun text-loader modules independently. Keep each occurrence's captured identifiers in its own module; report a missing prompt only after searching the entire corpus.
  • Decode native module encodings and preserve literal text-loader content without JavaScript escaping. Untouched prompt sources remain byte-identical.
  • Compose prompt changes with optional update-guard edits so neither overwrites the other. Parse-check the final entrypoint and changed JavaScript chunks before identity-validated repacking; text payloads bypass JavaScript parsing but still require valid UTF-8.
  • Permit targeted replacement of Bun's explicit Text loader (13) alongside JavaScript (1), while continuing to reject binary/file-loader assets regardless of filename.
  • Retain the npm single-source path and legacy native extraction fallback.
  • Cover cross-chunk captures, missing-warning aggregation, module boundaries, untouched content, filters, literal text, guard/prompt composition, parse failures, and text-module replacement.

Validation

  • pnpm test — 593 passed, 5 skipped, including the compiled Bun multi-module round-trip tests.

  • pnpm lint — passed.

  • pnpm build — passed.

  • Built the base (f4d4681) and PR CLIs and ran node dist/index.mjs --apply --yes --patches "$PROMPT_IDS" against separate copies of the same Claude Code 2.1.280 executable, with isolated TWEAKCC_CONFIG_DIR and TWEAKCC_CC_INSTALLATION_PATH. $PROMPT_IDS contained every ID from the 2.1.280 snapshot:

    CLI Missing-prompt warnings Vanilla executable Startup
    Base 642 Byte-identical 2.1.280 (Claude Code)
    PR 0 Byte-identical 2.1.280 (Claude Code)
  • Edited agent-prompt-auto-mode-rule-reviewer (JavaScript) and system-prompt-autonomous-loop-check (text) in the isolated configuration, then ran node dist/index.mjs --apply --yes --patches agent-prompt-auto-mode-rule-reviewer,system-prompt-autonomous-loop-check. Both customizations applied without missing-prompt warnings; the repacked executable returned 2.1.280 (Claude Code) from --version.

  • Separate source-application/repacking checks on actual 2.1.280 and 2.1.282 artifacts verified edited JavaScript/text payloads, byte-identical unrelated modules, unchanged original executables, and successful --version startup. A disposable 2.1.280 runtime probe read the edited text payload back exactly, including Unicode, backticks, and backslashes.

Known limitations

  • Non-prompt feature patches still use their existing matching paths; this does not repair the other customization failures reported in Opus 5.5 needs cc 2.1.280 - next official tweakcc release? #1008.
  • Testing the 2.1.282 snapshot from Prompts for 2.1.282 #1010 (ed6ad02) finds two separate snapshot mismatches: a build-specific worker path in Skill: /doctor slash command, and a hard-coded minified show:WOs identifier in System Reminder: Directory sync restored files mismatch. Those two warnings remain; this PR does not change that pending snapshot.

Summary by CodeRabbit

  • New Features
    • System prompts can now be applied across JavaScript and embedded text modules in native installations, including when the update guard is disabled.
  • Bug Fixes
    • Prompt changes preserve text-module content, including special characters, and are included when native modules are repacked.
    • Native installation updates now check changed JavaScript modules for parsing errors before repacking, preventing repacks when parsing fails.
    • Native update checks now report an error when module information is unavailable.

…t modules

Search each native JavaScript and text module instead of only the
entrypoint. Preserve module-local captures and literal text encoding,
compose prompt edits with the update guard, and validate changed
JavaScript before identity-checked repacking.

Reproduce the 642 missing-prompt warnings reported in #1008 and eliminate
them on Claude Code 2.1.280. Add regression coverage for chunk matching,
text payloads, filters, edit composition, and parse failures.
Record the assigned pull request number in the Unreleased changelog.
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 9e43b600-3dac-45c8-a51c-2829075eee62

📥 Commits

Reviewing files that changed from the base of the PR and between 960ab20 and deb4839.

📒 Files selected for processing (1)
  • CHANGELOG.md

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

System-prompt processing now supports multiple source modules, including Bun Text-loader modules. Native customization stages prompt and update-guard edits by module, parses edited JavaScript sources, and includes combined edits in module-aware repacking.

Changes

Native module system prompting

Layer / File(s) Summary
Multi-source prompt patching
src/patches/systemPrompts.ts, src/patches/systemPrompts.test.ts
applySystemPromptsToSources patches each source independently, handles text-loader content without JavaScript escaping, and merges results by prompt ID. Tests cover per-source matches, filtering, diagnostics, and unchanged sources.
Native corpus extraction and prompt staging
src/patches/index.ts, src/nativeInstallation.ts, src/nativeModuleReplacement.test.ts, CHANGELOG.md
Native customization extracts module metadata with or without the update guard and stages prompts for JavaScript and Text-loader modules. Module replacement accepts loader values 1 and 13. The changelog records the prompt support.
Edit validation and module repacking
src/patches/index.ts, src/patches/preventUnsupportedUpdatesFallback.test.ts
Prompt and update-guard edits are combined by module index, with guard edits taking precedence. Parsing checks edited JavaScript modules, and repacking receives the combined edits. Tests cover both guard states and parse failures.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant NativeCustomization
  participant BunModuleCorpus
  participant applySystemPromptsToSources
  participant NativeUpdateGuard
  participant JavaScriptParser
  participant ModuleAwareRepacker
  NativeCustomization->>BunModuleCorpus: Extract module metadata and sources
  NativeCustomization->>applySystemPromptsToSources: Patch JavaScript and Text-loader sources
  NativeCustomization->>NativeUpdateGuard: Check prompt-patched module sources
  NativeCustomization->>JavaScriptParser: Parse edited JavaScript modules
  NativeCustomization->>ModuleAwareRepacker: Repack combined module edits
Loading

Suggested reviewers: aegntic

Merge Risk: ⚪ Minimal · up to deb48

The reviewed prompt-processing and native-repacking changes show no identified issue that blocks merging.

Architecture Summary

Architecture risk: 🔵 Low · up to deb48

The change affects 2 systems.

Changed systems: src, CHANGELOG.md

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 6 changed files map to changed impact.
  • observed — CHANGELOG.md (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/nativeInstallation.ts: The replacement documentation now describes eligible sources as JavaScript or text-loader sources, rather than JavaScript sources only.
  • observed — Modified behavior in src/nativeInstallation.ts: The invalid UTF-8 or NUL-byte error now describes the required replacement as source text instead of JavaScript.
  • observed — Modified behavior in src/nativeInstallation.ts: The loader check now accepts values 1 (JavaScript) and 13 (text); all other module loader values still cause replacement to throw.
  • observed — Modified behavior in src/nativeModuleReplacement.test.ts: Added coverage for replacing a non-entrypoint module’s text-loader prompt, asserting the replacement source is preserved, loader metadata is unchanged, the adjacent byte is cleared, and the other module sources remain identical.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: applying system prompts across native JavaScript chunks and embedded Bun text modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 6 files. (1 skipped: 1 …
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

A rabbit reads each module line,
And finds the prompts in text and code.
It tucks the edits in careful files,
Then checks the JavaScript on the road.
The bundles hop back, neat and bright,
While bunny guards the source all night.

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

@KJ7LNW

KJ7LNW commented Sep 25, 2026 •

Copy link
Copy Markdown

Here's the output. The specific problem this fixes seems to be working, but if you look at the bottom it's still failing to apply a bunch of patches, However, those could be out of scope to this specific pull request since the issue it solves it appears to be working.

]$ claude  --version
2.1.280 (Claude Code)

# rm -rf ~/.tweakcc/system-prompts/ ~/.tweakcc/config.json
# git log -n1 
commit deb483910d76a095098de377eb42f13891cf6706 (HEAD, origin/fix-system-prompt-matching-1008)
Merge: 960ab20 d3fc4c2
Author: Mike <mike@piebald.ai>
Date:   Fri Sep 25 14:01:18 2026 -0600

    Merge branch 'main' into fix-system-prompt-matching-1008

# run tweakcc -ay
+ rm -rf ./dist/
+ npx pnpm install
Already up to date
Done in 2ms using pnpm v12.6.0
+ npx pnpm build:dev
$ tsdown --dts src/index.tsx src/lib/index.ts
ℹ tsdown v0.18.4 powered by rolldown v1.0.0-beta.57
ℹ entry: src/index.tsx, src/lib/index.ts
ℹ target: node20.0.0
ℹ tsconfig: tsconfig.json
ℹ Build start
ℹ Granting execute permission to dist/index.mjs
ℹ dist/index.mjs                        256.01 kB │ gzip: 48.78 kB
ℹ dist/lib/index.mjs                      3.64 kB │ gzip:  1.50 kB
ℹ dist/config-BiWIY3AR.mjs              390.08 kB │ gzip: 96.64 kB
ℹ dist/nativeInstallation-CzGpfZuH.mjs   50.45 kB │ gzip: 12.68 kB
ℹ dist/content-Cs7Fwod4.mjs              31.44 kB │ gzip:  7.89 kB
ℹ dist/lib/index.d.mts                   11.00 kB │ gzip:  3.46 kB
ℹ dist/index.d.mts                        0.01 kB │ gzip:  0.03 kB
ℹ 7 files, total: 742.63 kB
✔ Build complete in 827ms
+ TWEAKCC_CC_INSTALLATION_PATH=/home/claude/.npm-global/bin/claude
+ npx pnpm start -ay
$ node dist/index.mjs -ay
Applying saved customizations to Claude Code...
Configuration saved at: /home/claude/.tweakcc/config.json
Created 748 new prompt file(s):
...
Found Claude Code (native installation): /home/claude/.npm-global/lib/node_modules/@anthropic-ai/claude-code/bin/claude.exe
Version: 2.1.280

Pre-apply summary
  Config: /home/claude/.tweakcc/config.json
  Claude Code: 2.1.280
  Patches below are what --apply will attempt (pattern match may still fail).

  Always Applied:
    • Verbose property (verbose-property) [default-on]
      Token counter will show (2s · ↓ 169 tokens · thinking)
    • Opusplan[1m] support (opusplan1m) [default-on]
      Use the "Opus Plan 1M" model: Opus for planning, Sonnet 1M context for building
    • Fix LSP support (fix-lsp-support) [default-on]
      Enable/fix nascent LSP support
    • Clear screen command (clear-screen) [default-on]
      Register /clear-screen command (clear scrollback + redraw)
    • Session color from env (session-color) [default-on]
      Set session prompt bar color via TWEAKCC_SESSION_COLOR env var
    • Keybinding customization (keybinding-customization) [default-on]
      Force-enable custom keybindings when CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

  Misc Configurable:
    • Model customizations (model-customizations) [default-on]
      Access all Claude models with /model, not just latest 3
    • Show more items in select menus (show-more-items-in-select-menus) [default-on]
      Show 25 items in select menus instead of default 5
    • Patches applied indication (patches-applied-indication) [default-on]
      Show "tweakcc patches applied" and tweakcc version inside CC
    • Input chevron color (input-chevron-color) [default-on]
      The input chevron changes color based on loading state (e.g. green when idle)
    • Thinking block visibility (thinking-visibility) [default-on]
      Thinking blocks outputted by the model will show without Ctrl+O
    • AGENTS.md (and others) (agents-md) [default-on]
      Support AGENTS.md and others in addition to CLAUDE.md

  Features:
    • Worktree mode (worktree-mode) [default-on]
      Enable the EnterWorktree tool for isolated git worktree sessions
    • Session memory (session-memory) [default-on]
      Enable session memory (auto-extraction + past session search)
    • MCP non-blocking (mcp-non-blocking) [default-on]
      If you have MCP servers, CC startup will be much faster
    • User message display (user-message-display)
      User messages in the chat history will be styled

Loading system prompts...
Applying customizations...
patch: verbose: failed to find createElement with verbose spinner props
patch: opusplan1m: patchModeSwitchingFunction: failed to find mode switching pattern
patch: opusplan1m: failed to apply mode switching patch
patch: fixLspSupport: failed to find ensureServerStarted
patch: findCustomModelListInsertionPoint: failed to find custom model push
patch: writeShowMoreItemsInSelectMenus: failed to find locations
patch: patchesAppliedIndication: failed to find chalk variable
patch: thinkingVisibility: failed to find thinking visibility pattern
patch: agentsMd: failed to find CLAUDE.md reading function
patch: worktreeMode: failed to find worktree gate function pattern
patch: sessionMemory: failed to find extraction gate
patch: findTextComponent: failed to find text component
patch: userMessageDisplay: failed to find Text component

Patches applied (run with --show-unchanged to show all patches):

  Always Applied:
    ✗ Verbose property
    ✗ Opusplan[1m] support
    ✗ Fix LSP support
    ✗ Clear screen command
    ✗ Session color from env
    ✗ Keybinding customization

  Misc Configurable:
    ✗ Model customizations
    ✗ Show more items in select menus
    ✗ Patches applied indication
    ✗ Input chevron color
    ✗ Thinking block visibility
    ✗ AGENTS.md (and others)

  Features:
    ✗ Worktree mode
    ✗ Session memory
    ✗ User message display

Customizations applied with some failures.

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.

2 participants