# Patch Creation

Create and register new patches for tweakcc.

- Repository: https://github.com/Piebald-AI/tweakcc (2579 stars)
- Category: AI and agents
- License: MIT
- Last updated: 2026-10-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add Piebald-AI/tweakcc --skill patch-creation -g -a claude-code -y`
Codex: `npx skills add Piebald-AI/tweakcc --skill patch-creation -g -a codex -y`
Cursor: `npx skills add Piebald-AI/tweakcc --skill patch-creation -g -a cursor -y`
Gemini CLI: `npx skills add Piebald-AI/tweakcc --skill patch-creation -g -a gemini-cli -y`

## Description

Create and register new patches for tweakcc. Use when adding new customizations to Claude Code.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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';
```

The rest: https://github.com/Piebald-AI/tweakcc/blob/HEAD/.claude/skills/patch-creation/SKILL.md
