Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

What is PRECC?

PRECC (تصحیح خطای پیش‌بینانه برای Claude Code) is a Rust tool that intercepts Claude Code bash commands via the official PreToolUse hook mechanism. It fixes errors before they happen, saving tokens and eliminating retry loops.

رایگان برای کاربران جامعه.

The Problem

Claude Code wastes significant tokens on preventable mistakes:

  • Wrong-directory errors – Running cargo build in a parent directory that has no Cargo.toml, then retrying after reading the error.
  • Retry loops – A failed command produces verbose output, Claude reads it, reasons about it, and retries. Each cycle burns hundreds of tokens.
  • Verbose output – Commands like find or ls -R dump thousands of lines that Claude must process.

The Four Pillars

اصلاح زمینه (cd-prepend)

تشخیص می‌دهد زمانی که دستوراتی مانند cargo build یا npm test در پوشه اشتباه اجرا می‌شوند و cd /مسیر/درست && را قبل از اجرا اضافه می‌کند.

GDB Debugging

Detects opportunities to attach GDB for deeper debugging of segfaults and crashes, providing structured debug information instead of raw core dumps.

Session Mining

Mines Claude Code session logs for failure-fix pairs. When the same mistake recurs, PRECC already knows the fix and applies it automatically.

Automation Skills

A library of built-in and mined skills that match command patterns and rewrite them. Skills are defined as TOML files or SQLite rows, making them easy to inspect, edit, and share.

How It Works (30-Second Version)

  1. Claude Code is about to run a bash command.
  2. The PreToolUse hook sends the command to precc-hook as JSON on stdin.
  3. precc-hook runs the command through the pipeline (skills, directory correction, compression) in under 3 milliseconds.
  4. The corrected command is returned as JSON on stdout.
  5. Claude Code executes the corrected command instead.

Claude never sees the error. No tokens wasted.

Adaptive Compression

اگر یک دستور پس از فشرده‌سازی شکست بخورد، PRECC به طور خودکار فشرده‌سازی را در تلاش بعدی رد می‌کند تا Claude خروجی کامل غیرفشرده را برای اشکال‌زدایی دریافت کند.

Live Usage Statistics

MetricValue
Hook invocations
Tokens saved
Saving ratio%
RTK rewrites
CD corrections
Hook latency ms (p50)

اعداد تخمینی هستند. هر شکست جلوگیری شده یک چرخه کامل تلاش مجدد را اجتناب می‌کند: خروجی خطا، استدلال مدل و دستور تلاش مجدد. These numbers update automatically from anonymized telemetry.