Skip to content
Merged
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
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,42 @@ d.context("fixing auth bug")
d.checkpoint("Fixed it", what_worked="git blame first")
```

### Claude Code — Native Hooks (v3.3.0)

One command. Every Claude Code session becomes self-evolving.

```bash
dhee install
```

That's it. Dhee hooks into Claude Code's lifecycle — no CLAUDE.md bloat, no SKILL.md files, no markdown accumulation. Structured XML context injection, budgeted to ~630 tokens regardless of how much memory you have.

**What happens automatically:**

| Hook | When | What Dhee does |
|:-----|:-----|:---------------|
| `SessionStart` | Session opens | Injects last session, insights, performance trends, relevant memories |
| `UserPromptSubmit` | Every prompt | Surfaces memories relevant to what you just asked |
| `PostToolUse` | After Edit/Write/Bash | Captures what Claude did (secrets auto-stripped) |
| `PreCompact` | Before context compaction | Checkpoints state so nothing is lost |
| `Stop` | Session ends | Records outcomes — what worked, what failed, learnings |

Or start Claude Code directly with context:

```bash
dhee task "fix the flaky auth test"
```

**Why not CLAUDE.md?** Markdown files are static. After 6 months of accumulated knowledge, they rot — stale patterns sit at equal weight to current ones, no retrieval ranking, no forgetting. Dhee uses vector memory with strength-based decay. Relevant memories surface. Irrelevant ones fade. The context budget stays constant at ~630 tokens whether you have 50 memories or 50,000.

### CLI

```bash
dhee remember "User prefers Python"
dhee recall "programming language"
dhee checkpoint "Fixed auth bug" --what-worked "checked logs"
dhee install # install Claude Code hooks
dhee uninstall-hooks # remove them
```

### Docker
Expand Down Expand Up @@ -219,8 +249,18 @@ These are surfaced through `context()` and `checkpoint()` automatically when ena
## Architecture

```
Agent (Claude, GPT, Cursor, custom)
Claude Code (or any agent)
├── SessionStart hook ──→ dhee.context() ──→ XML renderer ──→ system prompt injection
├── UserPromptSubmit ───→ dhee.recall() ──→ ranked memories ──→ per-turn context
├── PostToolUse ────────→ dhee.remember() ─→ privacy filter ──→ stored (0 LLM)
├── PreCompact ─────────→ dhee.checkpoint() + re-inject context
└── Stop ───────────────→ dhee.checkpoint(what_worked, what_failed, outcome_score)
```

The 4-operation API under the hooks:

```
├── remember(content) → Engram: embed + store (0 LLM)
├── recall(query) → Engram: embed + vector search (0 LLM)
├── context(task) → Buddhi: performance + insights + intentions + memories
Expand Down
2 changes: 1 addition & 1 deletion dhee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# Default: CoreMemory (lightest, zero-config)
Memory = CoreMemory

__version__ = "3.2.0"
__version__ = "3.3.0"
__all__ = [
# Memory classes
"Engram",
Expand Down
68 changes: 68 additions & 0 deletions dhee/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,58 @@ def cmd_uninstall(args: argparse.Namespace) -> None:
print("Cancelled.")


def cmd_task(args: argparse.Namespace) -> None:
"""Start Claude Code with Dhee cognition hooks."""
from dhee.hooks.claude_code.install import ensure_installed

result = ensure_installed()
if result.already_installed:
pass # hooks already in place
elif result.created or result.updated:
print(f" Dhee hooks installed → {result.settings_path}")

# Find claude executable
claude_bin = shutil.which("claude")
if not claude_bin:
print("Error: 'claude' not found in PATH. Install Claude Code first.", file=sys.stderr)
sys.exit(1)

# Build command
cmd = [claude_bin]
if args.print_mode:
cmd.append("--print")
if args.description:
cmd.append(args.description)

# Replace current process with claude
os.execvp(claude_bin, cmd)


def cmd_install_hooks(args: argparse.Namespace) -> None:
"""Install Dhee hooks into Claude Code."""
from dhee.hooks.claude_code.install import install_hooks

result = install_hooks(force=args.force)
if result.already_installed and not args.force:
print(" Dhee hooks already installed.")
else:
action = "Created" if result.created else "Updated"
print(f" {action} {result.settings_path}")
print(f" Hooks: {', '.join(result.events)}")
if result.backed_up:
print(f" Backup: {result.backed_up}")


def cmd_uninstall_hooks(args: argparse.Namespace) -> None:
"""Remove Dhee hooks from Claude Code."""
from dhee.hooks.claude_code.install import uninstall_hooks

if uninstall_hooks():
print(" Dhee hooks removed.")
else:
print(" No Dhee hooks found.")


def cmd_benchmark(args: argparse.Namespace) -> None:
"""Run performance benchmarks."""
import time
Expand Down Expand Up @@ -458,6 +510,19 @@ def build_parser() -> argparse.ArgumentParser:
p_status = sub.add_parser("status", help="Show version, config, and agents")
p_status.add_argument("--json", action="store_true", help="JSON output")

# task
p_task = sub.add_parser("task", help="Start Claude Code with Dhee cognition")
p_task.add_argument("description", nargs="?", default="", help="Task description")
p_task.add_argument("--user-id", default="default", help="User ID")
p_task.add_argument("--print", dest="print_mode", action="store_true", help="One-shot mode")

# install (hooks)
p_install = sub.add_parser("install", help="Install Dhee hooks into Claude Code")
p_install.add_argument("--force", action="store_true", help="Overwrite existing hooks")

# uninstall-hooks
sub.add_parser("uninstall-hooks", help="Remove Dhee hooks from Claude Code")

# benchmark
sub.add_parser("benchmark", help="Run performance benchmarks")

Expand All @@ -481,6 +546,9 @@ def build_parser() -> argparse.ArgumentParser:
"export": cmd_export,
"import": cmd_import,
"status": cmd_status,
"task": cmd_task,
"install": cmd_install_hooks,
"uninstall-hooks": cmd_uninstall_hooks,
"benchmark": cmd_benchmark,
"uninstall": cmd_uninstall,
}
Expand Down
Empty file added dhee/hooks/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions dhee/hooks/claude_code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from dhee.hooks.claude_code.install import ensure_installed, install_hooks, uninstall_hooks
from dhee.hooks.claude_code.renderer import estimate_tokens, render_context
Loading
Loading