Skip to content

Commit 2ecddfe

Browse files
AlexMikhalevclaude
andcommitted
docs: add Claude Code integration quick setup guide
- Add step-by-step user-level setup for terraphim-agent and hooks - Document git-safety-guard and text replacement features - Add verification commands and feature table - Link to terraphim-skills for full documentation - Note crates.io version is outdated, recommend GitHub releases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ac30743 commit 2ecddfe

1 file changed

Lines changed: 114 additions & 5 deletions

File tree

README.md

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,116 @@ For development, see our comprehensive [Development Setup Guide](docs/src/develo
476476

477477
## Claude Code Integration
478478

479-
Terraphim provides seamless integration with Claude Code through multiple approaches, enabling intelligent text replacement and codebase quality evaluation.
479+
Terraphim provides seamless integration with Claude Code through hooks, skills, and the terraphim-agent CLI.
480+
481+
### Quick Setup (User-Level)
482+
483+
**Step 1: Install terraphim-agent**
484+
```bash
485+
# macOS ARM64 (Apple Silicon)
486+
gh release download --repo terraphim/terraphim-ai \
487+
--pattern "terraphim-agent-aarch64-apple-darwin" --dir /tmp
488+
chmod +x /tmp/terraphim-agent-aarch64-apple-darwin
489+
mv /tmp/terraphim-agent-aarch64-apple-darwin ~/.cargo/bin/terraphim-agent
490+
491+
# macOS x86_64 (Intel)
492+
gh release download --repo terraphim/terraphim-ai \
493+
--pattern "terraphim-agent-x86_64-apple-darwin" --dir /tmp
494+
chmod +x /tmp/terraphim-agent-x86_64-apple-darwin
495+
mv /tmp/terraphim-agent-x86_64-apple-darwin ~/.cargo/bin/terraphim-agent
496+
497+
# Linux x86_64
498+
gh release download --repo terraphim/terraphim-ai \
499+
--pattern "terraphim-agent-x86_64-unknown-linux-gnu" --dir /tmp
500+
chmod +x /tmp/terraphim-agent-x86_64-unknown-linux-gnu
501+
mv /tmp/terraphim-agent-x86_64-unknown-linux-gnu ~/.cargo/bin/terraphim-agent
502+
```
503+
504+
**Note:** The crates.io version (`cargo install terraphim_agent`) is v1.0.0 and missing `hook` and `guard` commands. Use GitHub releases.
505+
506+
**Step 2: Install Claude Code Skills Plugin**
507+
```bash
508+
claude plugin marketplace add terraphim/terraphim-skills
509+
claude plugin install terraphim-engineering-skills@terraphim-skills
510+
```
511+
512+
**Step 3: Configure User-Level Hooks**
513+
514+
Add to `~/.claude/settings.local.json`:
515+
```json
516+
{
517+
"hooks": {
518+
"PreToolUse": [{
519+
"matcher": "Bash",
520+
"hooks": [{
521+
"type": "command",
522+
"command": "~/.claude/hooks/pre_tool_use.sh"
523+
}]
524+
}]
525+
}
526+
}
527+
```
528+
529+
Create `~/.claude/hooks/pre_tool_use.sh`:
530+
```bash
531+
#!/bin/bash
532+
set -euo pipefail
533+
INPUT=$(cat)
534+
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty')
535+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
536+
537+
[ "$TOOL_NAME" != "Bash" ] && exit 0
538+
[ -z "$COMMAND" ] && exit 0
539+
540+
AGENT="$HOME/.cargo/bin/terraphim-agent"
541+
[ ! -x "$AGENT" ] && exit 0
542+
543+
# Git Safety Guard - block destructive commands
544+
GUARD=$($AGENT guard --json <<< "$COMMAND" 2>/dev/null || echo '{"decision":"allow"}')
545+
if echo "$GUARD" | jq -e '.decision == "block"' >/dev/null 2>&1; then
546+
REASON=$(echo "$GUARD" | jq -r '.reason')
547+
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"BLOCKED: '"$REASON"'"}}'
548+
exit 0
549+
fi
550+
551+
# Knowledge graph replacement
552+
cd ~/.config/terraphim 2>/dev/null && $AGENT hook --hook-type pre-tool-use --json <<< "$INPUT" 2>/dev/null
553+
```
554+
555+
```bash
556+
mkdir -p ~/.claude/hooks && chmod +x ~/.claude/hooks/pre_tool_use.sh
557+
```
558+
559+
**Step 4: Set Up Knowledge Graph**
560+
```bash
561+
mkdir -p ~/.config/terraphim/docs/src/kg
562+
563+
cat > ~/.config/terraphim/docs/src/kg/bun_install.md << 'EOF'
564+
# bun install
565+
synonyms:: npm install, yarn install, pnpm install
566+
EOF
567+
```
568+
569+
### Features
570+
571+
| Feature | Command | Description |
572+
|---------|---------|-------------|
573+
| **Git Safety Guard** | `terraphim-agent guard` | Blocks destructive commands (git reset --hard, rm -rf, etc.) |
574+
| **Text Replacement** | `terraphim-agent replace` | Knowledge graph-based text substitution |
575+
| **Hook Integration** | `terraphim-agent hook` | Claude Code PreToolUse/PostToolUse hooks |
576+
577+
### Verification
578+
```bash
579+
# Test guard
580+
echo "git reset --hard" | terraphim-agent guard --json
581+
# {"decision":"block","reason":"git reset --hard destroys uncommitted changes..."}
582+
583+
# Test replacement
584+
cd ~/.config/terraphim && echo "npm install" | terraphim-agent replace
585+
# bun install
586+
```
587+
588+
📖 **Full Documentation**: [terraphim-skills README](https://github.com/terraphim/terraphim-skills)
480589

481590
### 🔄 Text Replacement (Hooks & Skills)
482591

@@ -485,8 +594,8 @@ Use Terraphim's knowledge graph capabilities to automatically replace text patte
485594
**Claude Code Hooks** - Automatic, transparent replacements:
486595
```bash
487596
# Example: Automatically replace npm with bun
488-
echo "npm install" | terraphim-tui replace
489-
# Output: bun_install
597+
echo "npm install" | terraphim-agent replace
598+
# Output: bun install
490599
```
491600

492601
**Claude Skills** - Context-aware, conversational assistance:
@@ -495,8 +604,8 @@ echo "npm install" | terraphim-tui replace
495604
- Progressive disclosure of functionality
496605

497606
**Examples:**
498-
- Package manager enforcement (npm/yarn/pnpm bun)
499-
- Attribution replacement (Claude Code Terraphim AI)
607+
- Package manager enforcement (npm/yarn/pnpm -> bun)
608+
- Attribution replacement (Claude Code -> Terraphim AI)
500609
- Custom domain-specific replacements
501610

502611
📖 **Complete Guide**: [examples/TERRAPHIM_CLAUDE_INTEGRATION.md](examples/TERRAPHIM_CLAUDE_INTEGRATION.md)

0 commit comments

Comments
 (0)