Skip to main content
skill CX Codex

patch-creation — Claude Code skill: what it does, how to install

patch-creation provides instructions and code templates to create and register patches for tweakcc, customizing Claude Code binaries.

MIT ★ 2,619 updated 2026-10-24

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Piebald-AI/tweakcc --skill patch-creation -a claude-code
Open on GitHub

What patch-creation does

The skill guides developers in writing code modifications for Claude Code minified cli.js or native binaries. It explains the structure of patch files under src/patches/*.ts, showing how to identify target code segments via regex, apply text replacements, and verify changes with showDiff().

Matching minified JavaScript requires strict regex conventions. Patch patterns must match identifiers with [$\w]+ because $ is a valid character in JavaScript variable names. Starting patterns with boundary characters such as commas or semicolons speeds up evaluation, dropping scan duration from 1.5s down to 30ms. The workflow also details registering the patch in src/patches/index.ts, updating src/types.ts, and setting defaults in src/defaultSettings.ts.

Running npm run build and executing npx tweakcc --apply are mandatory steps to test changes on an installed Claude Code binary.

What it helps with

  • build regex patterns for minified cli.js modifications
  • register a new patch definition in src/patches/index.ts
  • wire patch configuration options into src/types.ts and defaultSettings.ts
  • add toggles for new patches in MiscView.tsx

Example prompts for the agent

  • Write a tweakcc patch that bypasses a feature flag check in Claude Code
  • Register a new patch under PatchGroup.FEATURES and update types.ts
  • Help me match an identifier in minified JS using boundary characters

How to install patch-creation

1Skills CLI (Vercel)

npx skills add Piebald-AI/tweakcc --skill patch-creation -a claude-code

2Manually: put the files in place

~/.claude/skills/patch-creation/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/patch-creation/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about patch-creation

How to install patch-creation in Claude Code?

Run npx skills add Piebald-AI/tweakcc --skill patch-creation -a claude-code.

What is the patch-creation skill used for?

It provides a checklist and code conventions for writing tweakcc patches that modify the Claude Code runtime.

Why must patch patterns avoid standard word boundaries like \b?

JavaScript minifiers frequently emit $ inside identifiers. Word boundary assertions like \b do not treat $ as a word character, breaking match accuracy.

Source text

SKILL.md · MIT
---
name: patch-creation
description: Create and register new patches for tweakcc. Use when adding new customizations to Claude Code.
---

# Patch Creation & Registration

## Overview

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.

## Creating a New Patch

### 1. Create the patch file

Create `src/patches/myPatch.ts`:

````typescript
// 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
}
```

### 3. Add default value

Edit `src/defaultSettings.ts`:

```typescript
misc: {
  // ... existing fields ...
  myNewSetting: null,  // or a sensible default
},
```

### 4. Register in index.ts

Edit `src/patches/index.ts`:

**4a. Add import:**

```typescript
import { writeMyPatch } from './myPatch';
```

**4b. Add patch definition (in `PATCH_DEFINITIONS` array):**

```typescript
{
  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):**

```typescript
'my-patch': {
  fn: c => writeMyPatch(c, config.settings.misc!.myNewSetting!),
  condition: !!config.settings.misc?.myNewSetting,
},
```

### 5. Add UI (optional)

Edit `src/ui/components/MiscView.tsx` to add a toggle or input for the setting.

## Key Files

| 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                               |

## Registration Checklist

When adding a new patch, update these locations:

- [ ] `src/patches/myPatch.ts` - Create the patch file with exported function
- [ ] `src/types.ts` - Add config type (if configurable)
- [ ] `src/defaultSettings.ts` - Add default value (if configurable)
- [ ] `src/patches/index.ts`:
  - [ ] Import the patch function
  - [ ] Add to `PATCH_DEFINITIONS` array (id, name, group, description)
  - [ ] Add to `patchImplementations` object (fn, condition)
- [ ] `src/ui/components/MiscView.tsx` - Add UI controls (optional)

## Patch Groups

- `PatchGroup.ALWAYS_APPLIED` - Core patches that are always applied
- `PatchGroup.MISC_CONFIGURABLE` - User-configurable misc settings
- `PatchGroup.FEATURES` - Feature patches that can be enabled/disabled

## Pattern Writing Tips

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

## Example: Simple Toggle Patch

```typescript
// 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;
```

## Example: Replace a Value

```typescript
// 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);

showDiff(file, newFile, replacement, startIndex, endIndex);
return newFile;
```

## Testing

1. Run `npm run build` to compile
2. Run `npx tweakcc --apply` to apply patches
3. Check console output for patch success/failure
4. Run Claude Code to verify behavior

© Piebald-AI · MIT · Piebald-AI/tweakcc

Similar skills

All skills for Agent setup: memory, context, orchestration →

Project sponsors

Companies that keep this analytics open