brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Create and register new patches for tweakcc. Use when adding new customizations to Claude Code.
Claude Code
$ npx -y skills add Piebald-AI/tweakcc --skill patch-creation --agent claude-code
Codex
$ npx skills add Piebald-AI/tweakcc --skill patch-creation -a codex -y
Cursor
$ npx skills add Piebald-AI/tweakcc --skill patch-creation -a cursor -y
Gemini CLI
$ npx skills add Piebald-AI/tweakcc --skill patch-creation -a gemini-cli -y
GitHub Copilot
$ npx skills add Piebald-AI/tweakcc --skill patch-creation -a github-copilot -y
OpenCode
$ npx skills add Piebald-AI/tweakcc --skill patch-creation -a opencode -y
Windsurf
$ npx skills add Piebald-AI/tweakcc --skill patch-creation -a windsurf -y
name: patch-creation description: Create and register new patches for tweakcc. Use when adding new customizations to Claude Code.
Patches are code modifications applied to Claude Code's `cli.js` (or native binary). Each patch finds specific patterns in the minified code and replaces/injects new behavior.
Create `src/patches/myPatch.ts`:
// Please see the note about writing patches in ./index
import { showDiff } from './index';
/**
* Description of what this patch does.
*
* CC X.Y.Z:
* ```diff
* // Show before/after of the code change
* -oldCode
* +newCode
* ```
*/
export const writeMyPatch = (
file: string,
configValue: string // Add parameters as needed
): string | null => {
// Pattern to find in minified code
// IMPORTANT: Use [$\w]+ for identifiers (not \w+) because $ is valid in JS identifiers
// IMPORTANT: Start patterns with a boundary char (,;}{) for HIGH performance (e.g. 1.5s -> 30ms)
const pattern = /,somePattern([$\w]+)/;
const match = file.match(pattern);
if (!match || match.index === undefined) {
console.error('patch: myPatch: failed to find pattern');
return null;
}
const replacement = `,newCode${match[1]}`;
const startIndex = match.index;
const endIndex = startIndex + match[0].length;
const newFile =
file.slice(0, startIndex) + replacement + file.slice(endIndex);
showDiff(file, newFile, replacement, startIndex, endIndex);
return newFile;
};
````
### 2. Add config type (if patch is configurable)
Edit `src/types.ts` - add to `MiscConfig` or create a new interface:
```typescript
export interface MiscConfig {
// ... existing fields ...
myNewSetting: string | null; // null = disabled
}Edit `src/defaultSettings.ts`:
misc: {
// ... existing fields ...
myNewSetting: null, // or a sensible default
},Edit `src/patches/index.ts`:
**4a. Add import:**
import { writeMyPatch } from './myPatch';**4b. Add patch definition (in `PATCH_DEFINITIONS` array):**
{
id: 'my-patch',
name: 'My patch',
group: PatchGroup.FEATURES, // or ALWAYS_APPLIED, MISC_CONFIGURABLE
description: 'What this patch does for the user',
},**4c. Add patch implementation (in `patchImplementations` object):**
'my-patch': {
fn: c => writeMyPatch(c, config.settings.misc!.myNewSetting!),
condition: !!config.settings.misc?.myNewSetting,
},Edit `src/ui/components/MiscView.tsx` to add a toggle or input for the setting.
| File | Purpose | | -------------------------------- | -------------------------------------------------- | | `src/patches/*.ts` | Individual patch implementations | | `src/patches/index.ts` | Patch registry, definitions, and application logic | | `src/types.ts` | Config type definitions (`MiscConfig`, etc.) | | `src/defaultSettings.ts` | Default values for all settings | | `src/ui/components/MiscView.tsx` | UI for misc settings |
When adding a new patch, update these locations:
1. **Use `[$\w]+` for identifiers** - Not `\w+`, because `$` is valid in JS identifiers and common in minified code
2. **Start patterns with boundary characters** - Use `,`, `;`, `{`, `}` at the start to dramatically speed up matching (can reduce 1.5s to 30ms)
3. **Don't use `\b` for word boundaries** - It doesn't treat `$` as a word character, so `\b[$\w]+` won't match `,$=`
4. **Extract function bodies carefully** - Count braces to find matching `}` when you need the full function
5. **Use `showDiff()` for debugging** - Always call it to log what the patch is changing
6. **Return `null` on failure** - Let the patch system know the patch couldn't be applied
7. **Handle multiple CC versions** - Code patterns may change between versions; try multiple patterns if needed
// Bypass a feature flag check
const pattern = /function [$\w]+\(\)\{return [$\w]+\("my_feature_flag"/;
const match = file.match(pattern);
if (!match || match.index === undefined) {
console.error('patch: myPatch: failed to find feature flag');
return null;
}
const insertIndex = match.index + match[0].indexOf('{') + 1;
const insertion = 'return true;';
const newFile =
file.slice(0, insertIndex) + insertion + file.slice(insertIndex);
showDiff(file, newFile, insertion, insertIndex, insertIndex);
return newFile;// Replace a hardcoded value
const pattern = /(someConfig=)\d+(;)/;
const match = file.match(pattern);
if (!match || match.index === undefined) {
console.error('patch: myPatch: failed to find config value');
return null;
}
const replacement = match[1] + newValue + match[2];
const startIndex = match.index;
const endIndex = startIndex + match[0].length;
const newFile = file.slice(0, startIndex) + replacement + file.slice(endIndex);
showDitweakcc is a CLI tool that upgrades your Claude Code experience. Customize its system prompts, add custom themes, create toolsets, and personalize the UI. From the team behind Piebald. ing...'
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.