Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/agents/system-architect.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ src/main.rs
│ ├── tee.rs ← Raw output recovery on failure
│ ├── filter.rs ← Language-aware code filtering
│ └── utils.rs ← strip_ansi, truncate, execute_command
├── hooks/ ← init, rewrite, verify, trust, integrity
├── hooks/ ← init, rewrite, verify, trust
└── analytics/ ← gain, cc_economics, ccusage, session_cmd
```

Expand Down
25 changes: 18 additions & 7 deletions .claude/agents/technical-writer.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,28 @@ RTK integrates with Claude Code via bash hooks for transparent command rewriting
4. RTK applies filter, returns condensed output
5. Claude sees token-optimized result (80% savings)

## Hook Files

- `.claude/hooks/rtk-rewrite.sh` - Command rewriting (DO NOT MODIFY)
- `.claude/hooks/rtk-suggest.sh` - Suggestion when filter available
## Hook Configuration

RTK uses native hooks defined in `~/.claude/settings.json`:
```json
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "rtk hook claude"
}]
}]
}
}
```

## Verification

**Check hooks are active**:
**Check hook is active**:
```bash
ls -la .claude/hooks/*.sh
# Should show -rwxr-xr-x (executable)
rtk init --show # Should show "✅ Hook: installed"
```

**Test hook integration** (in Claude Code session):
Expand Down
68 changes: 26 additions & 42 deletions .claude/commands/diagnose.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,14 @@ git status --short && git branch --show-current

```bash
# Hook configuration check
if [ -f ".claude/hooks/rtk-rewrite.sh" ]; then
echo "✅ OK: rtk-rewrite.sh hook present"
# Check if hook is executable
if [ -x ".claude/hooks/rtk-rewrite.sh" ]; then
echo "✅ OK: hook is executable"
if [ -f ".claude/settings.json" ]; then
if grep -q '"rtk hook claude' ".claude/settings.json" 2>/dev/null; then
echo "✅ OK: RTK native hook configured in settings.json"
else
echo "⚠️ WARNING: hook not executable (chmod +x needed)"
echo "⚠️ WARNING: RTK hook not found in settings.json"
fi
else
echo "❌ MISSING: rtk-rewrite.sh hook"
fi
```

```bash
# Hook rtk-suggest.sh check
if [ -f ".claude/hooks/rtk-suggest.sh" ]; then
echo "✅ OK: rtk-suggest.sh hook present"
if [ -x ".claude/hooks/rtk-suggest.sh" ]; then
echo "✅ OK: hook is executable"
else
echo "⚠️ WARNING: hook not executable (chmod +x needed)"
fi
else
echo "❌ MISSING: rtk-suggest.sh hook"
echo "⚠️ WARNING: settings.json not found"
fi
```

Expand Down Expand Up @@ -158,10 +142,10 @@ multiSelect: true
options:
- label: "cargo install --path ."
description: "Installer RTK localement depuis le repo"
- label: "chmod +x .claude/hooks/bash/*.sh"
description: "Rendre les hooks exécutables"
- label: "rtk init -g --auto-patch"
description: "Réinstaller les hooks natifs RTK"
- label: "Tout corriger (recommandé)"
description: "Install RTK + fix hooks permissions"
description: "Install RTK + réinstaller hooks"
```

**Adaptations selon contexte** :
Expand All @@ -177,13 +161,13 @@ options:
description: "Installer RTK via Homebrew (macOS/Linux)"
```

### Si hooks manquants/non exécutables
### Si hooks manquants/non configurés
```
options:
- label: "chmod +x .claude/hooks/*.sh"
description: "Rendre tous les hooks exécutables"
- label: "Copier hooks depuis template"
description: "Si hooks manquants, copier depuis repository principal"
- label: "rtk init -g"
description: "Réinstaller les hooks natifs RTK"
- label: "rtk init --show"
description: "Vérifier l'état des hooks"
```

### Si rtk gain échoue
Expand All @@ -205,20 +189,20 @@ cargo install --path .
which rtk && rtk --version
```

### Fix 2 : Rendre hooks exécutables
### Fix 2 : Réinstaller les hooks natifs
```bash
chmod +x .claude/hooks/*.sh
# Vérifier permissions
ls -la .claude/hooks/*.sh
rtk init -g --auto-patch
# Vérifier installation
rtk init --show
```

### Fix 3 : Tout corriger (recommandé)
```bash
# Install RTK
cargo install --path .

# Fix hooks permissions
chmod +x .claude/hooks/*.sh
# Réinstaller les hooks
rtk init -g --auto-patch

# Verify
which rtk && rtk --version && rtk gain --history | head -3
Expand Down Expand Up @@ -319,18 +303,18 @@ rtk gain --help # Should work
echo $CLAUDE_CODE_HOOK_BASH_TEMPLATE
# Should print hook template path - if empty, not in Claude Code

# Check hooks exist and executable
ls -la .claude/hooks/*.sh
# Should show -rwxr-xr-x (executable)
# Check if native hook is configured
rtk init --show
# Should show "✅ Hook: installed"
```

**Fix**:
```bash
# Make hooks executable
chmod +x .claude/hooks/*.sh
# Reinstall native hooks
rtk init -g --auto-patch

# Verify hooks load in new Claude Code session
# (restart Claude Code session after chmod)
# Verify in new Claude Code session
# (restart Claude Code session after reinstall)
```

## Version Compatibility Matrix
Expand Down
3 changes: 1 addition & 2 deletions .claude/rules/search-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ src/
│ ├── hook_cmd.rs ← Gemini/Copilot hook processors
│ ├── hook_check.rs ← Hook status detection
│ ├── verify_cmd.rs ← rtk verify command
│ ├── trust.rs ← Project trust/untrust
│ └── integrity.rs ← SHA-256 hook verification
│ └── trust.rs ← Project trust/untrust
├── analytics/ ← Token savings analytics
│ ├── gain.rs ← rtk gain command
│ ├── cc_economics.rs ← Claude Code economics
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Build
/target
.cargo-ok

# Environment & Secrets
.env
.env.*
settings.local.json
*.pem
*.key
*.crt
Expand Down
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Savings by ecosystem:

- **Command Modules**: `src/cmds/` — organized by ecosystem (git, rust, js, python, go, dotnet, cloud, system, ruby). Each ecosystem README lists its files.
- **Core Infrastructure**: `src/core/` — utils, filter, tracking, tee, config, toml_filter, display_helpers, telemetry
- **Hook System**: `src/hooks/` — init, rewrite, permissions, hook_cmd, hook_check, hook_audit, verify, trust, integrity
- **Hook System**: `src/hooks/` — init, rewrite, permissions, hook_cmd, hook_check, hook_audit, verify, trust
- **Analytics**: `src/analytics/` — gain, cc_economics, ccusage, session_cmd

### Module Count Breakdown
Expand Down
34 changes: 16 additions & 18 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ rtk gain # MUST show token savings, not "command not found"

```bash
rtk init -g
# → Installs hook to ~/.claude/hooks/rtk-rewrite.sh
# → Configures native hook in settings.json
# → Creates ~/.claude/RTK.md (10 lines, meta commands only)
# → Adds @RTK.md reference to ~/.claude/CLAUDE.md
# → Prompts: "Patch settings.json? [y/N]"
Expand All @@ -113,22 +113,21 @@ rtk init --show # Check hook is installed and executable
Claude Code's hook registry. RTK adds a PreToolUse hook that rewrites commands transparently. Without this, Claude won't invoke the hook automatically.

```
Claude Code settings.json rtk-rewrite.sh RTK binary
│ │ │ │
│ "git status" │ │ │
│ ──────────────────►│ │ │
│ │ PreToolUse trigger │ │
│ │ ───────────────────►│ │
│ │ │ rewrite command │
│ │ │ → rtk git status │
│ │◄────────────────────│ │
│ │ updated command │ │
│ │ │
│ execute: rtk git status │
│ ─────────────────────────────────────────────────────────────►│
│ │ filter
│ "3 modified, 1 untracked ✓" │
│◄──────────────────────────────────────────────────────────────│
Claude Code settings.json RTK binary (native hook)
│ │ │
│ "git status" │ │
│ ──────────────────►│ │
│ │ PreToolUse trigger │
│ │ ────────────────────►│
│ │ │ rewrite command
│ │ │ → rtk git status
│ │◄─────────────────────│ updated command
│ │ │
│ execute: rtk git status │
│ ──────────────────────────────────────────────►│
│ │ filter
│ "3 modified, 1 untracked ✓" │
│◄─────────────────────────────────────────────────│
```

**Backup Safety**:
Expand Down Expand Up @@ -247,7 +246,6 @@ rtk vitest run
rtk init -g --uninstall

# What gets removed:
# - Hook: ~/.claude/hooks/rtk-rewrite.sh
# - Context: ~/.claude/RTK.md
# - Reference: @RTK.md line from ~/.claude/CLAUDE.md
# - Registration: RTK hook entry from settings.json
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following files are considered **high-risk** and trigger mandatory 2-reviewe
- **`src/summary.rs`** - Command output aggregation (data exfiltration risk)
- **`src/tracking.rs`** - SQLite database operations (privacy/telemetry concerns)
- **`src/discover/registry.rs`** - Rewrite logic for all commands (command injection risk via rewrite rules)
- **`hooks/rtk-rewrite.sh`** / **`.claude/hooks/rtk-rewrite.sh`** - Thin delegator hook (executes in Claude Code context, intercepts all commands)
- **`src/hooks/hook_cmd.rs`** - Native hook processor (executes in Claude Code context, intercepts all commands)

### Tier 2: Input Validation
- **`src/pnpm_cmd.rs`** - Package name validation (prevents injection via malicious names)
Expand Down
3 changes: 1 addition & 2 deletions docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,8 @@ rtk init -g --uninstall # Desinstaller

| Fichier | Description |
|---------|-------------|
| `~/.claude/hooks/rtk-rewrite.sh` | Script hook (delegue a `rtk rewrite`) |
| `~/.claude/settings.json` | Configuration du hook natif `rtk hook claude` |
| `~/.claude/RTK.md` | Instructions minimales pour le LLM |
| `~/.claude/settings.json` | Enregistrement du hook PreToolUse |

### `rtk rewrite` -- Recriture de commande

Expand Down
12 changes: 5 additions & 7 deletions docs/TECHNICAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ This is the full lifecycle of a command through RTK, from LLM agent to filtered
The user runs `rtk init` to set up hooks for their LLM agent. This:

1. Writes a thin shell hook script (e.g., `~/.claude/hooks/rtk-rewrite.sh`)
2. Stores its SHA-256 hash for integrity verification
3. Patches the agent's settings file (e.g., `settings.json`) to register the hook
4. Writes RTK awareness instructions (e.g., `RTK.md`) for prompt-level guidance
2. Patches the agent's settings file (e.g., `settings.json`) to register the hook
3. Writes RTK awareness instructions (e.g., `RTK.md`) for prompt-level guidance

RTK supports 7 agents, each with its own installation mode. The hook scripts are embedded in the binary and written at install time.

Expand Down Expand Up @@ -101,8 +100,7 @@ Once the rewritten command reaches RTK:
1. **Telemetry**: `telemetry::maybe_ping()` fires a non-blocking daily usage ping
2. **Clap parsing**: `Cli::try_parse()` matches against the `Commands` enum
3. **Hook check**: `hook_check::maybe_warn()` warns if the installed hook is outdated (rate-limited to 1/day)
4. **Integrity check**: `integrity::runtime_check()` verifies the hook's SHA-256 hash for operational commands
5. **Routing**: A `match cli.command` dispatches to the specialized filter module
4. **Routing**: A `match cli.command` dispatches to the specialized filter module

If Clap parsing fails (command not in the enum), the fallback path runs instead.

Expand Down Expand Up @@ -182,7 +180,7 @@ Start here, then drill down into each README for file-level details.
|-----------|-------------|-------------------------------|
| `main.rs` | CLI entry point, `Commands` enum, routing match | _(no README — read the file directly)_ |
| [`core/`](../src/core/README.md) | Shared infrastructure | Tracking DB schema, config system, tee recovery, TOML filter engine, utility functions |
| [`hooks/`](../src/hooks/README.md) | Hook system | Installation flow (`rtk init`), integrity verification, rewrite command, trust model |
| [`hooks/`](../src/hooks/README.md) | Hook system | Installation flow (`rtk init`), rewrite command, trust model |
| [`analytics/`](../src/analytics/README.md) | Token savings analytics | `rtk gain` dashboard, Claude Code economics, ccusage parsing |
| [`cmds/`](../src/cmds/README.md) | **Command filters (9 ecosystems)** | Common filter pattern, cross-command routing, token savings table, **links to each ecosystem** |
| [`discover/`](../src/discover/README.md) | History analysis + rewrite registry | Rewrite patterns, session providers, compound command splitting |
Expand Down Expand Up @@ -221,7 +219,7 @@ RTK supports the following LLM agents through hook integrations:
| Codex CLI | Awareness doc | AGENTS.md integration | N/A (prompt) |
| OpenCode | TS plugin | `tool.execute.before` event | Yes (in-place mutation) |

> **Details**: [`hooks/README.md`](../hooks/README.md) has the full JSON schemas for each agent. [`src/hooks/README.md`](../src/hooks/README.md) covers installation, integrity verification, and the rewrite command.
> **Details**: [`hooks/README.md`](../hooks/README.md) has the full JSON schemas for each agent. [`src/hooks/README.md`](../src/hooks/README.md) covers installation, the rewrite command, and trust management.

---

Expand Down
12 changes: 5 additions & 7 deletions docs/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@ rtk init --show # Should show "✅ Hook: executable, with guards"

**Option B: Manual (fallback)**
```bash
# Copy hook to Claude Code hooks directory
mkdir -p ~/.claude/hooks
cp .claude/hooks/rtk-rewrite.sh ~/.claude/hooks/
chmod +x ~/.claude/hooks/rtk-rewrite.sh
# Verify rtk is in PATH
which rtk # Should show rtk binary location
```

Then add to `~/.claude/settings.json` (replace `~` with full path):
Then add to `~/.claude/settings.json`:
```json
{
"hooks": {
Expand All @@ -154,7 +152,7 @@ Then add to `~/.claude/settings.json` (replace `~` with full path):
"hooks": [
{
"type": "command",
"command": "/Users/yourname/.claude/hooks/rtk-rewrite.sh"
"command": "rtk hook claude"
}
]
}
Expand All @@ -163,7 +161,7 @@ Then add to `~/.claude/settings.json` (replace `~` with full path):
}
```

**Note**: Use absolute path in `settings.json`, not `~/.claude/...`
**Note**: The native `rtk hook claude` command is built into the RTK binary — no separate script file needed.

---

Expand Down
2 changes: 1 addition & 1 deletion hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Owns: per-agent hook scripts and configuration files for 7 supported agents (Claude Code, Copilot, Cursor, Cline, Windsurf, Codex, OpenCode).

Does **not** own: hook installation/uninstallation (that's `src/hooks/init.rs`), the rewrite pattern registry (that's `discover/registry`), or integrity verification (that's `src/hooks/integrity.rs`).
Does **not** own: hook installation/uninstallation (that's `src/hooks/init.rs`) or the rewrite pattern registry (that's `discover/registry`).

Relationship to `src/hooks/`: that component **creates** these files; this directory **contains** them.

Expand Down
Loading