Getting it into your agent
It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.
git clone --depth 1 https://github.com/ArkaAiAdmin/Agentic-Memorynpx agentmods add skills/arkaaiadmin/agentic-memory/add-a-claude-code-hookWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/arkaaiadmin/agentic-memory/add-a-claude-code-hook)<a href="https://agentmods.dev/skills/arkaaiadmin/agentic-memory/add-a-claude-code-hook"><img src="https://agentmods.dev/badge/skills/arkaaiadmin/agentic-memory/add-a-claude-code-hook/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/arkaaiadmin/agentic-memory/add-a-claude-code-hook"><img src="https://agentmods.dev/badge/skills/arkaaiadmin/agentic-memory/add-a-claude-code-hook.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00071 | $0.02471 |
| Opus 5.5 | $0.00028 | $0.00988 |
| Sonnet 5.5 | $0.00014 | $0.00494 |
| Haiku 4.5 | $0.00007 | $0.00247 |
Grade B, and why
add-a-claude-code-hook scanned grade B with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Reads agent configuration directoriesmediumAgent snooping
.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.
2. Wire it into the user's Claude Code config (typically `~/.claude/settings.json` or opencode config). Runs shell commandslowCapability
Expected in a hook, worth knowing in a rule or an instructions file.
result = subprocess.run( How it starts
The opening of the file, as written. The whole thing — 268 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Add a Claude Code Hook
How to add a new lifecycle hook to the agentic-memory system. There are 4 lifecycle hooks today (PreToolUse, SessionStart, Stop/PostToolUse, plus a 5th log redirect helper); this is how to add a 6th.
The 60-second version
- Create
hooks/memory_your_event.pyat the repo root. - Wire it into the user's Claude Code config (typically
~/.claude/settings.jsonor opencode config). - The hook receives JSON on stdin, prints to stdout (NOT stderr — that was a 2-day bug).
- Test with a manual JSON invocation:
echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | python hooks/memory_your_event.py
Total: ~30 minutes for a read-only hook, ~2 hours for one that mutates state.
Lifecycle event types
| Event | When it fires | What you get | What you can do |
|---|---|---|---|
SessionStart |
New session begins | session_id, cwd, hook_event_name | Inject context, load memory |
UserPromptSubmit |
User types a message | prompt, session_id, cwd | Pre-process prompt, inject context |
PreToolUse |
Before any tool call | tool_name, tool_input, session_id | Modify tool_input, inject context, deny |
PostToolUse |
After any tool call | tool_name, tool_input, tool_output, session_id | React to result, save, validate |
Stop |
Agent stops responding | session_id, last_user_message, last_assistant_message | Save snapshot, ping user |
SessionEnd |
Session deleted | session_id, reason, duration_seconds | Final save, cleanup |
The current lifecycle hooks: memory-proactive-context.py (PreToolUse), memory-session-start.py (SessionStart), memory-session-end.py (Stop/PostToolUse, enforces Rule #7), and the log redirect _log_error.py. The auto-save flow runs on PostToolUse via auto_save.py.
Step 1: write the hook
#!/usr/bin/env python3
"""Hook: <event> — what this does in one line.
Triggered by: <where in claude config>
Input: JSON on stdin with <list of fields>
Output: <what to print, where>
"""
import sys
import json
import os
# Use the user's Python (M8 fix)
sys.path.insert(0, os.path.expanduser("~/.config/agentic-memory"))
def main():
try:
# Read input
raw = sys.stdin.read()
data = json.loads(raw) if raw else {}
except Exception as e:
# NEVER crash a hook silently. Print to stderr, return.
print(f"hook: failed to parse stdin: {e}", file=sys.stderr)
return
# Extract what you need
event = data.get("hook_event_name", "unknown")
session_id = data.get("session_id", "unknown")
tool_name = data.get("tool_name", "")
tool_input = data.get("tool_input", {})
# Do your work
result = your_logic(event, session_id, tool_name, tool_input)
# Print to STDOUT — this is what Claude Code injects
print(result)
if __name__ == "__main__":
main()
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 268 lines · 71 tokens per session scan B 8a36bba73471
add-a-claude-code-hook is a skill published in the GitHub repository ArkaAiAdmin/Agentic-Memory (0 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 71 tokens to every session and 2,471 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it B with 2 findings (reads agent configuration directories, runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
local-ai-agents
Build local-first AI agents that run entirely on a developer workstation with Microsoft Foundry Local and Qwen function-calling models. Covers Small Language Models (SLMs), the OpenAI-compatible local endpoint, sandboxed local tools, local RAG with Chroma, local MCP servers, hybrid cloud/local routing, and the…
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.
next-cache-components-adoption
Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…
chat-pet-sprite-creation
Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.
cpu-profile-analysis
Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…
insight-error-page
Write or audit an insight-kind error page for the Next.js dev overlay. Use when creating a new errors/ .mdx page, auditing an existing one, or checking that a page matches the framework fix cards. Covers page structure, title alignment, FixCard cards with Copy prompt button, code snippets, terminology verification…