Claude Code hooks
One command, and every Claude Code session in a project starts with its memory, has its turns captured, and is recapped when it ends. The model spends no tokens on any of it.
Install
In the project, logged in, with an agent for it if you want one:
rf agents create claude-code --use # optional: write as an agent
rf hooks installThat adds four hooks to .claude/settings.json, beside whatever is there already. The next Claude Code session in the project uses them. Claude Code runs hooks through your shell, so rf has to be on your PATH; the install says so when it is not. With an agent, the hooks and the commands Claude Code runs act as it; you, in your own terminal, keep your login.
What each hook does
| When | What happens |
|---|---|
| A session starts, resumes, is cleared, is compacted, or is forked | The collection's context pack, its profile and most important memories, is added to Claude's context under # From rentfree's memory. An empty collection adds nothing. |
| You send a prompt | The prompt is logged to the session as a message.user event. The notices Claude Code sends as prompts when a background task finishes are left out, since you did not write them. |
| Claude finishes a turn | Its final message is logged as a message.assistant event. |
| The session ends | The rentfree session is ended, which starts a recap: the session's events become memories, and the profile is rewritten. The next session starts with them. A session that logged nothing has nothing to end. |
Each Claude Code session is one rentfree session, made by the first prompt it logs and found again by every hook through its id, claude-code:<session id>. A Claude Code session that ends without a prompt leaves no rentfree session behind. A session resumed after it ended continues in claude-code:<session id>:2, since an ended session takes no more events.
Options
| Flag | Effect |
|---|---|
--scope project | The default: .claude/settings.json, which is usually committed, so everyone on the project gets the hooks. |
--scope local | .claude/settings.local.json: this project, for you alone. |
--scope user | ~/.claude/settings.json: every project you open. Each writes to its own rf.json collection, or your default. |
--recall | Also fetches a context pack for every prompt, searched by the prompt itself. Better answers on long sessions; about half a second and up to the budget in tokens per prompt. |
--tools | Also logs every tool call and its result, cut to 4 KB each, so recap can learn from what Claude did as well as what it said. |
--budget <n> | Most tokens a context pack may use; 2000 by default. |
See what was captured
rf session list # the sessions, newest first
rf session events <session> # what was logged
rf recap runs # what recap made of them, and what it cost
rf memories list # the memories
rf context # what the next session will start withWhen something goes wrong
A hook never blocks Claude Code. When one fails, because you are logged out, the API cannot be reached, or the project has no collection, it writes one line to stderr and lets the session carry on. Claude Code shows hook output in its verbose transcript view; each line starts with rf hooks and the hook's name. The usual causes:
rfnot on thePATHof the shell Claude Code starts: install it globally withnpm install -g @rentfree/cli.- Not logged in on this machine:
rf init, or setRF_API_KEY. - An agent key without the collection:
RF_AGENT=1 rf whoamishows what the key the hooks use can see, andrf agents editchanges it. Plainrf whoamiin your own terminal shows your login, which you keep in the project.
Turn it off
rf hooks uninstallRemoves rentfree's hooks and nothing else; pass the same --scope you installed with. rf hooks status shows what is installed in each scope. What was already captured stays; see the CLI reference to remove it.