agentihooks 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentihooks-0.1.0/LICENSE +21 -0
- agentihooks-0.1.0/PKG-INFO +260 -0
- agentihooks-0.1.0/README.md +219 -0
- agentihooks-0.1.0/agentihooks.egg-info/PKG-INFO +260 -0
- agentihooks-0.1.0/agentihooks.egg-info/SOURCES.txt +104 -0
- agentihooks-0.1.0/agentihooks.egg-info/dependency_links.txt +1 -0
- agentihooks-0.1.0/agentihooks.egg-info/entry_points.txt +2 -0
- agentihooks-0.1.0/agentihooks.egg-info/requires.txt +24 -0
- agentihooks-0.1.0/agentihooks.egg-info/top_level.txt +3 -0
- agentihooks-0.1.0/hooks/__init__.py +43 -0
- agentihooks-0.1.0/hooks/__main__.py +12 -0
- agentihooks-0.1.0/hooks/_redis.py +68 -0
- agentihooks-0.1.0/hooks/common.py +432 -0
- agentihooks-0.1.0/hooks/config.py +144 -0
- agentihooks-0.1.0/hooks/context/__init__.py +1 -0
- agentihooks-0.1.0/hooks/context/bash_output_filter.py +199 -0
- agentihooks-0.1.0/hooks/context/file_read_cache.py +138 -0
- agentihooks-0.1.0/hooks/hook_manager.py +721 -0
- agentihooks-0.1.0/hooks/integrations/__init__.py +258 -0
- agentihooks-0.1.0/hooks/integrations/aws.py +356 -0
- agentihooks-0.1.0/hooks/integrations/base.py +416 -0
- agentihooks-0.1.0/hooks/integrations/completions.py +277 -0
- agentihooks-0.1.0/hooks/integrations/confluence.py +1551 -0
- agentihooks-0.1.0/hooks/integrations/dynamodb.py +990 -0
- agentihooks-0.1.0/hooks/integrations/file_system.py +523 -0
- agentihooks-0.1.0/hooks/integrations/git_diff.py +42 -0
- agentihooks-0.1.0/hooks/integrations/github.py +696 -0
- agentihooks-0.1.0/hooks/integrations/lambda_invoke.py +604 -0
- agentihooks-0.1.0/hooks/integrations/mailer.py +1270 -0
- agentihooks-0.1.0/hooks/integrations/mermaid_validator.py +938 -0
- agentihooks-0.1.0/hooks/integrations/postgres.py +792 -0
- agentihooks-0.1.0/hooks/integrations/session_state.py +372 -0
- agentihooks-0.1.0/hooks/integrations/sqs.py +545 -0
- agentihooks-0.1.0/hooks/integrations/storage.py +885 -0
- agentihooks-0.1.0/hooks/integrations/webhook.py +594 -0
- agentihooks-0.1.0/hooks/mcp/__init__.py +74 -0
- agentihooks-0.1.0/hooks/mcp/__main__.py +6 -0
- agentihooks-0.1.0/hooks/mcp/_registry.py +18 -0
- agentihooks-0.1.0/hooks/mcp/agent.py +63 -0
- agentihooks-0.1.0/hooks/mcp/aws.py +188 -0
- agentihooks-0.1.0/hooks/mcp/compute.py +58 -0
- agentihooks-0.1.0/hooks/mcp/confluence.py +386 -0
- agentihooks-0.1.0/hooks/mcp/database.py +153 -0
- agentihooks-0.1.0/hooks/mcp/email.py +110 -0
- agentihooks-0.1.0/hooks/mcp/github.py +226 -0
- agentihooks-0.1.0/hooks/mcp/messaging.py +130 -0
- agentihooks-0.1.0/hooks/mcp/observability.py +289 -0
- agentihooks-0.1.0/hooks/mcp/smith.py +253 -0
- agentihooks-0.1.0/hooks/mcp/storage.py +103 -0
- agentihooks-0.1.0/hooks/mcp/utilities.py +264 -0
- agentihooks-0.1.0/hooks/memory/__init__.py +1 -0
- agentihooks-0.1.0/hooks/memory/__main__.py +5 -0
- agentihooks-0.1.0/hooks/memory/auto_save.py +156 -0
- agentihooks-0.1.0/hooks/memory/server.py +339 -0
- agentihooks-0.1.0/hooks/memory/store.py +379 -0
- agentihooks-0.1.0/hooks/memory/transcript_reader.py +140 -0
- agentihooks-0.1.0/hooks/observability/__init__.py +42 -0
- agentihooks-0.1.0/hooks/observability/agent_log_stream.py +146 -0
- agentihooks-0.1.0/hooks/observability/container_logs.py +270 -0
- agentihooks-0.1.0/hooks/observability/metrics.py +579 -0
- agentihooks-0.1.0/hooks/observability/token_monitor.py +169 -0
- agentihooks-0.1.0/hooks/observability/transcript.py +128 -0
- agentihooks-0.1.0/hooks/quota.py +104 -0
- agentihooks-0.1.0/hooks/secrets.py +128 -0
- agentihooks-0.1.0/hooks/statusline.py +309 -0
- agentihooks-0.1.0/hooks/tool_memory.py +490 -0
- agentihooks-0.1.0/profiles/__init__.py +0 -0
- agentihooks-0.1.0/profiles/_base/__init__.py +0 -0
- agentihooks-0.1.0/profiles/_base/settings.base.json +36 -0
- agentihooks-0.1.0/profiles/admin/.claude/CLAUDE.md +13 -0
- agentihooks-0.1.0/profiles/admin/__init__.py +0 -0
- agentihooks-0.1.0/profiles/admin/profile.yml +17 -0
- agentihooks-0.1.0/profiles/admin/settings.overrides.json +5 -0
- agentihooks-0.1.0/profiles/coding/.claude/CLAUDE.md +13 -0
- agentihooks-0.1.0/profiles/coding/__init__.py +0 -0
- agentihooks-0.1.0/profiles/coding/profile.yml +17 -0
- agentihooks-0.1.0/profiles/coding/settings.overrides.json +5 -0
- agentihooks-0.1.0/profiles/default/.claude/CLAUDE.md +13 -0
- agentihooks-0.1.0/profiles/default/__init__.py +0 -0
- agentihooks-0.1.0/profiles/default/profile.yml +17 -0
- agentihooks-0.1.0/profiles/default/settings.overrides.json +5 -0
- agentihooks-0.1.0/pyproject.toml +82 -0
- agentihooks-0.1.0/scripts/__init__.py +0 -0
- agentihooks-0.1.0/scripts/claude_usage_watcher.py +405 -0
- agentihooks-0.1.0/scripts/install.py +1890 -0
- agentihooks-0.1.0/setup.cfg +4 -0
- agentihooks-0.1.0/tests/test_common.py +89 -0
- agentihooks-0.1.0/tests/test_common_extended.py +382 -0
- agentihooks-0.1.0/tests/test_config.py +125 -0
- agentihooks-0.1.0/tests/test_container_logs.py +310 -0
- agentihooks-0.1.0/tests/test_file_system.py +348 -0
- agentihooks-0.1.0/tests/test_hook_manager.py +189 -0
- agentihooks-0.1.0/tests/test_install.py +461 -0
- agentihooks-0.1.0/tests/test_integrations_base.py +33 -0
- agentihooks-0.1.0/tests/test_mcp_registry.py +30 -0
- agentihooks-0.1.0/tests/test_mcp_utilities.py +208 -0
- agentihooks-0.1.0/tests/test_memory_store.py +59 -0
- agentihooks-0.1.0/tests/test_memory_store_extended.py +333 -0
- agentihooks-0.1.0/tests/test_mermaid_validator.py +35 -0
- agentihooks-0.1.0/tests/test_mermaid_validator_extended.py +436 -0
- agentihooks-0.1.0/tests/test_metrics_extended.py +473 -0
- agentihooks-0.1.0/tests/test_observability.py +54 -0
- agentihooks-0.1.0/tests/test_quota.py +82 -0
- agentihooks-0.1.0/tests/test_secrets.py +263 -0
- agentihooks-0.1.0/tests/test_tool_memory.py +42 -0
- agentihooks-0.1.0/tests/test_transcript_reader.py +313 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Cloud Clock Work
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentihooks
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Hook system and MCP tool server for Claude Code agents
|
|
5
|
+
Author: The Cloud Clock Work
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/The-Cloud-Clock-Work/agentihooks
|
|
8
|
+
Project-URL: Repository, https://github.com/The-Cloud-Clock-Work/agentihooks
|
|
9
|
+
Project-URL: Issues, https://github.com/The-Cloud-Clock-Work/agentihooks/issues
|
|
10
|
+
Keywords: claude-code,mcp,hooks,agents,agenticore
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: mcp[cli]>=1.0.0
|
|
21
|
+
Requires-Dist: PyJWT>=2.8.0
|
|
22
|
+
Requires-Dist: requests>=2.31.0
|
|
23
|
+
Requires-Dist: httpx>=0.27.0
|
|
24
|
+
Provides-Extra: postgres
|
|
25
|
+
Requires-Dist: psycopg2-binary>=2.9.9; extra == "postgres"
|
|
26
|
+
Provides-Extra: all
|
|
27
|
+
Requires-Dist: psycopg2-binary>=2.9.9; extra == "all"
|
|
28
|
+
Requires-Dist: pyyaml>=6.0; extra == "all"
|
|
29
|
+
Requires-Dist: redis>=5.0.0; extra == "all"
|
|
30
|
+
Requires-Dist: boto3>=1.34.0; extra == "all"
|
|
31
|
+
Requires-Dist: playwright>=1.44.0; extra == "all"
|
|
32
|
+
Provides-Extra: quota
|
|
33
|
+
Requires-Dist: playwright>=1.44.0; extra == "quota"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
39
|
+
Requires-Dist: boto3>=1.34.0; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# agentihooks
|
|
43
|
+
|
|
44
|
+
[](https://the-cloud-clock-work.github.io/agentihooks/)
|
|
45
|
+
[](https://github.com/The-Cloud-Clock-Work/agentihooks/blob/main/LICENSE)
|
|
46
|
+
[](https://github.com/The-Cloud-Clock-Work/agentihooks/actions/workflows/ci.yml)
|
|
47
|
+
[](https://python.org)
|
|
48
|
+
[](https://the-cloud-clock-work.github.io/agentihooks/)
|
|
49
|
+
|
|
50
|
+
Hook system and MCP tool server for [Claude Code](https://docs.anthropic.com/en/docs/claude-code) agents. Designed to work with [agenticore](https://github.com/The-Cloud-Clock-Work/agenticore) and meant to be forked and extended for custom workflows.
|
|
51
|
+
|
|
52
|
+
**agentihooks** intercepts every Claude Code lifecycle event (session start/end, tool use, prompts, stops) and provides 45 MCP tools across 12 categories for interacting with external services. A built-in **Token Control Layer** monitors context window usage, truncates verbose command output, deduplicates file reads, and warns before quota exhaustion — targeting 30–50% token reduction in agentic sessions.
|
|
53
|
+
|
|
54
|
+
> **Full documentation:** [the-cloud-clock-work.github.io/agentihooks](https://the-cloud-clock-work.github.io/agentihooks/)
|
|
55
|
+
|
|
56
|
+
## Architecture
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
Claude Code
|
|
60
|
+
│
|
|
61
|
+
├── Hook Events (stdin JSON) ──► python -m hooks ──► hook_manager.py
|
|
62
|
+
│ SessionStart, PreToolUse, │
|
|
63
|
+
│ PostToolUse, Stop, ... ├── transcript logging
|
|
64
|
+
│ (10 events total) ├── tool error memory
|
|
65
|
+
│ ├── token control layer
|
|
66
|
+
│ ├── metrics parsing
|
|
67
|
+
│ └── email notifications
|
|
68
|
+
│
|
|
69
|
+
├── statusLine (native setting) ──► python -m hooks.statusline
|
|
70
|
+
│ pipes JSON on every turn └── 2-3 line status bar (ctx%, burn rate, cost, git)
|
|
71
|
+
│
|
|
72
|
+
└── MCP Tools ──► python -m hooks.mcp ──► 12 category modules
|
|
73
|
+
github, aws, confluence, │
|
|
74
|
+
email, database, ... └── hooks/integrations/*
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Quick Start
|
|
78
|
+
|
|
79
|
+
**Requirement:** [uv](https://docs.astral.sh/uv/getting-started/installation/) must be installed.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
git clone https://github.com/The-Cloud-Clock-Work/agentihooks
|
|
83
|
+
cd agentihooks
|
|
84
|
+
|
|
85
|
+
# 1. Create the dedicated venv at ~/.agentihooks/.venv and install everything
|
|
86
|
+
uv venv ~/.agentihooks/.venv
|
|
87
|
+
uv pip install --python ~/.agentihooks/.venv/bin/python -e ".[all]"
|
|
88
|
+
|
|
89
|
+
# 2. Install hooks + settings + MCP into ~/.claude
|
|
90
|
+
~/.agentihooks/.venv/bin/python scripts/install.py global
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`agentihooks global` wires hooks into `~/.claude/settings.json`, symlinks skills/agents, merges MCP servers into `~/.claude.json`, and installs the CLI globally. **Critically, every hook command in `settings.json` is written with the Python that ran the installer** — so by running the installer from `~/.agentihooks/.venv`, all hook subprocesses find the right packages regardless of which shell or virtual environment is active when Claude Code fires them.
|
|
94
|
+
|
|
95
|
+
Re-run any time — it's idempotent. See [Installation](https://the-cloud-clock-work.github.io/agentihooks/docs/getting-started/installation/) for the full step-by-step walkthrough including Redis setup and quota display.
|
|
96
|
+
|
|
97
|
+
## Hook Events
|
|
98
|
+
|
|
99
|
+
10 lifecycle events, all handled by `python -m hooks`:
|
|
100
|
+
|
|
101
|
+
| Event | What happens |
|
|
102
|
+
|-------|-------------|
|
|
103
|
+
| `SessionStart` | Creates session context directory, injects session awareness, MCP hygiene reminder |
|
|
104
|
+
| `PreToolUse` | Secret scan (blocks on detection), file read deduplication, injects tool error memory |
|
|
105
|
+
| `PostToolUse` | Truncates verbose bash output, marks files read, records tool errors |
|
|
106
|
+
| `Stop` | Scans transcript for errors, parses metrics, auto-saves memory |
|
|
107
|
+
| `SessionEnd` | Logs transcript, clears file read cache, cleans up session directory |
|
|
108
|
+
| `SubagentStop` | Logs subagent transcript |
|
|
109
|
+
| `UserPromptSubmit` | Warns on detected secrets |
|
|
110
|
+
| `Notification` | Logs notifications |
|
|
111
|
+
| `PreCompact` | Logs before context compaction |
|
|
112
|
+
| `PermissionRequest` | Logs permission requests |
|
|
113
|
+
|
|
114
|
+
**StatusLine** is not a hook event — it is a native Claude Code setting (`"statusLine"` key in `settings.json`) handled by `hooks/statusline.py`. It emits a 2–3 line terminal status bar with context fill %, burn rate, cost, cache ratio, and git branch on every turn. `used_pct` is recomputed from `total_input_tokens / context_window_size * 100` to avoid stale payload values.
|
|
115
|
+
|
|
116
|
+
Full payload schemas and handler details: [Hook Events](https://the-cloud-clock-work.github.io/agentihooks/docs/hooks/events/)
|
|
117
|
+
|
|
118
|
+
## MCP Tool Categories
|
|
119
|
+
|
|
120
|
+
45 tools across 12 categories, selectively loaded via `MCP_CATEGORIES`:
|
|
121
|
+
|
|
122
|
+
| Category | Tools | Description |
|
|
123
|
+
|----------|------:|-------------|
|
|
124
|
+
| `github` | 5 | Clone repos, create PRs, token management, git summary |
|
|
125
|
+
| `confluence` | 9 | CRUD pages, markdown docgen, validation |
|
|
126
|
+
| `aws` | 4 | Profile listing, account discovery |
|
|
127
|
+
| `email` | 2 | SMTP send with text / HTML / markdown |
|
|
128
|
+
| `messaging` | 3 | SQS + webhook with state enrichment |
|
|
129
|
+
| `storage` | 2 | S3 upload, `/tmp`-restricted filesystem delete |
|
|
130
|
+
| `database` | 3 | DynamoDB put, PostgreSQL insert + execute |
|
|
131
|
+
| `compute` | 1 | Lambda invocation (sync/async) |
|
|
132
|
+
| `observability` | 7 | Timers, metrics, structured logging, container log tailing |
|
|
133
|
+
| `smith` | 4 | Command builder: list, prompt, build, execute |
|
|
134
|
+
| `agent` | 1 | Remote agent completions with model presets |
|
|
135
|
+
| `utilities` | 4 | Mermaid validation, markdown writer, env vars, tool listing |
|
|
136
|
+
|
|
137
|
+
Per-tool signatures, parameters, and environment variables: [MCP Tools](https://the-cloud-clock-work.github.io/agentihooks/docs/mcp-tools/)
|
|
138
|
+
|
|
139
|
+
## CLI
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
agentihooks global [--profile <name>] # install/re-apply to ~/.claude
|
|
143
|
+
agentihooks project <path> # write .mcp.json into a project
|
|
144
|
+
agentihooks mcp # list MCP files in ~/.agentihooks/
|
|
145
|
+
agentihooks mcp install # two-stage: pick file → pick servers
|
|
146
|
+
agentihooks mcp uninstall # two-stage: pick file → pick servers to remove
|
|
147
|
+
agentihooks mcp add <path> # install a file directly by path
|
|
148
|
+
agentihooks mcp sync # re-apply all installed MCP files
|
|
149
|
+
agentihooks quota # start background quota watcher daemon
|
|
150
|
+
agentihooks quota auth # open browser, paste sessionKey, import cookie, start daemon
|
|
151
|
+
agentihooks quota import-cookies # paste sessionKey without opening browser
|
|
152
|
+
agentihooks quota status # print last known quota JSON
|
|
153
|
+
agentihooks quota logs # tail -f daemon log
|
|
154
|
+
agentihooks quota stop # kill daemon
|
|
155
|
+
agentihooks ignore [path] [--force] # create .claudeignore in cwd (or given path)
|
|
156
|
+
agentihooks uninstall # remove everything
|
|
157
|
+
agentihooks --loadenv # install agentienv shell function into ~/.bashrc
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Full reference: [CLI Commands](https://the-cloud-clock-work.github.io/agentihooks/docs/reference/cli-commands/)
|
|
161
|
+
|
|
162
|
+
## Configuration
|
|
163
|
+
|
|
164
|
+
All integrations are configured via environment variables. Key ones:
|
|
165
|
+
|
|
166
|
+
| Variable | Default | Description |
|
|
167
|
+
|----------|---------|-------------|
|
|
168
|
+
| `AGENTIHOOKS_HOME` | `~/.agentihooks` | Root for logs, memory, and state |
|
|
169
|
+
| `CLAUDE_CODE_HOME_DIR` | `$HOME` | Home-directory root override (`.claude` appended automatically) |
|
|
170
|
+
| `AGENTIHOOKS_CLAUDE_HOME` | `~/.claude` | Legacy: direct path to `.claude` directory |
|
|
171
|
+
| `AGENTIHOOKS_PROFILE` | `default` | Profile to use for `agentihooks global` / `project` (env alternative to `--profile`) |
|
|
172
|
+
| `AGENTIHOOKS_MCP_FILE` | — | Path to an MCP JSON file to auto-merge during `agentihooks global` |
|
|
173
|
+
| `MCP_CATEGORIES` | `all` | Comma-separated list of tool categories to load |
|
|
174
|
+
| `LOG_ENABLED` | `true` | Enable hook logging |
|
|
175
|
+
| `MEMORY_AUTO_SAVE` | `true` | Auto-save session digest on Stop |
|
|
176
|
+
| `REDIS_URL` | — | Redis connection string — format: `redis://:PASSWORD@host:port/db`. Used by token monitor (burn rate), file read cache (dedup), and warning edge-triggers. Graceful degradation when unavailable. |
|
|
177
|
+
| `TOKEN_CONTROL_ENABLED` | `true` | Master switch for the token control layer |
|
|
178
|
+
| `TOKEN_WARN_PCT` | `60` | Context fill % that triggers a warning injection |
|
|
179
|
+
| `TOKEN_CRITICAL_PCT` | `80` | Context fill % that triggers a critical banner |
|
|
180
|
+
| `BASH_FILTER_ENABLED` | `true` | Truncate verbose bash output (docker logs, git log, etc.) |
|
|
181
|
+
| `FILE_READ_CACHE_ENABLED` | `true` | Block redundant file re-reads within a session |
|
|
182
|
+
| `MCP_HYGIENE_ENABLED` | `true` | Inject MCP server usage reminder at session start |
|
|
183
|
+
| `ENABLE_TOOL_SEARCH` | `true` | Make all MCP tools lazy-loaded on demand (set in `env` block of `settings.json`); eliminates ~79K token upfront cost from MCP tool schemas |
|
|
184
|
+
| `CLAUDE_USAGE_FILE` | — | Path to quota JSON file (e.g. `~/.agentihooks/claude_usage.json`). Must be set to enable statusline line 3 quota display. |
|
|
185
|
+
| `CLAUDE_USAGE_STALE_SEC` | `300` | Quota data older than this (seconds) shows "stale" on statusline |
|
|
186
|
+
| `CLAUDE_USAGE_POLL_SEC` | `60` | Quota watcher daemon poll interval (seconds) |
|
|
187
|
+
|
|
188
|
+
Complete table covering all 50+ variables across every integration: [Configuration Reference](https://the-cloud-clock-work.github.io/agentihooks/docs/reference/configuration/)
|
|
189
|
+
|
|
190
|
+
## Profiles
|
|
191
|
+
|
|
192
|
+
Profiles bundle a system prompt (`CLAUDE.md`), MCP category selection, and model settings. Switch with `agentihooks global --profile <name>`.
|
|
193
|
+
|
|
194
|
+
## Portability
|
|
195
|
+
|
|
196
|
+
Everything user-specific lives in `~/.agentihooks/`:
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
~/.agentihooks/
|
|
200
|
+
├── .venv/ # Canonical Python venv — all hook subprocesses run from here
|
|
201
|
+
├── .env # Main credentials (seeded from .env.example, loaded first)
|
|
202
|
+
├── *.env # Companion env files (auto-sourced after .env)
|
|
203
|
+
├── *.json # Drop MCP server files here → agentihooks mcp install
|
|
204
|
+
├── state.json # Tracked MCP files and other state
|
|
205
|
+
├── logs/ # Hook + MCP logs
|
|
206
|
+
│ └── quota-watcher.log # Quota watcher daemon log
|
|
207
|
+
├── memory/ # Cross-session agent memory
|
|
208
|
+
├── claude_auth_state.json # Playwright storage state (sessionKey cookie for quota watcher)
|
|
209
|
+
├── claude_usage.json # Written by quota watcher daemon; read by statusline (optional)
|
|
210
|
+
└── quota-watcher.pid # Daemon PID file
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
To move to a new machine: clone the repo, copy `~/.agentihooks/.env`, recreate the venv, run the installer. Done:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
uv venv ~/.agentihooks/.venv
|
|
217
|
+
uv pip install --python ~/.agentihooks/.venv/bin/python -e ".[all]"
|
|
218
|
+
~/.agentihooks/.venv/bin/python scripts/install.py global
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Install the `agentienv` shell function** (sources `.env` into any shell on demand — also auto-called on every new shell):
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
agentihooks --loadenv # writes managed block to ~/.bashrc
|
|
225
|
+
source ~/.bashrc
|
|
226
|
+
agentienv # load vars into current shell before launching claude
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Manage MCP server files** — drop `.json` files into `~/.agentihooks/`:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
agentihooks mcp # list available MCP files
|
|
233
|
+
agentihooks mcp install # interactive: pick one to install
|
|
234
|
+
agentihooks mcp uninstall # interactive: pick one to remove
|
|
235
|
+
agentihooks mcp add <path> # install directly by path
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Details: [Portability & Reusability](https://the-cloud-clock-work.github.io/agentihooks/docs/getting-started/portability/)
|
|
239
|
+
|
|
240
|
+
## Extending
|
|
241
|
+
|
|
242
|
+
Add a new MCP tool category with a `register(server)` function + one line in `_registry.py`. Add a new hook handler with one function + one entry in the dispatcher dict.
|
|
243
|
+
|
|
244
|
+
Guide: [Extending AgentiHooks](https://the-cloud-clock-work.github.io/agentihooks/docs/extending/)
|
|
245
|
+
|
|
246
|
+
## Code Quality
|
|
247
|
+
|
|
248
|
+
Continuously analyzed by [SonarQube](https://sonar.homeofanton.com/dashboard?id=agentihooks).
|
|
249
|
+
|
|
250
|
+
## Related Projects
|
|
251
|
+
|
|
252
|
+
| Project | Description |
|
|
253
|
+
|---------|-------------|
|
|
254
|
+
| [agenticore](https://github.com/The-Cloud-Clock-Work/agenticore) | Claude Code runner and orchestrator |
|
|
255
|
+
| [agentibridge](https://github.com/The-Cloud-Clock-Work/agentibridge) | MCP server for session persistence and remote control |
|
|
256
|
+
| [agentihub](https://github.com/The-Cloud-Clock-Work/agentihub) (private) | Agent identities — CLAUDE.md, workflows, evaluation. Provisioned directly by agenticore. |
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# agentihooks
|
|
2
|
+
|
|
3
|
+
[](https://the-cloud-clock-work.github.io/agentihooks/)
|
|
4
|
+
[](https://github.com/The-Cloud-Clock-Work/agentihooks/blob/main/LICENSE)
|
|
5
|
+
[](https://github.com/The-Cloud-Clock-Work/agentihooks/actions/workflows/ci.yml)
|
|
6
|
+
[](https://python.org)
|
|
7
|
+
[](https://the-cloud-clock-work.github.io/agentihooks/)
|
|
8
|
+
|
|
9
|
+
Hook system and MCP tool server for [Claude Code](https://docs.anthropic.com/en/docs/claude-code) agents. Designed to work with [agenticore](https://github.com/The-Cloud-Clock-Work/agenticore) and meant to be forked and extended for custom workflows.
|
|
10
|
+
|
|
11
|
+
**agentihooks** intercepts every Claude Code lifecycle event (session start/end, tool use, prompts, stops) and provides 45 MCP tools across 12 categories for interacting with external services. A built-in **Token Control Layer** monitors context window usage, truncates verbose command output, deduplicates file reads, and warns before quota exhaustion — targeting 30–50% token reduction in agentic sessions.
|
|
12
|
+
|
|
13
|
+
> **Full documentation:** [the-cloud-clock-work.github.io/agentihooks](https://the-cloud-clock-work.github.io/agentihooks/)
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Claude Code
|
|
19
|
+
│
|
|
20
|
+
├── Hook Events (stdin JSON) ──► python -m hooks ──► hook_manager.py
|
|
21
|
+
│ SessionStart, PreToolUse, │
|
|
22
|
+
│ PostToolUse, Stop, ... ├── transcript logging
|
|
23
|
+
│ (10 events total) ├── tool error memory
|
|
24
|
+
│ ├── token control layer
|
|
25
|
+
│ ├── metrics parsing
|
|
26
|
+
│ └── email notifications
|
|
27
|
+
│
|
|
28
|
+
├── statusLine (native setting) ──► python -m hooks.statusline
|
|
29
|
+
│ pipes JSON on every turn └── 2-3 line status bar (ctx%, burn rate, cost, git)
|
|
30
|
+
│
|
|
31
|
+
└── MCP Tools ──► python -m hooks.mcp ──► 12 category modules
|
|
32
|
+
github, aws, confluence, │
|
|
33
|
+
email, database, ... └── hooks/integrations/*
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
**Requirement:** [uv](https://docs.astral.sh/uv/getting-started/installation/) must be installed.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
git clone https://github.com/The-Cloud-Clock-Work/agentihooks
|
|
42
|
+
cd agentihooks
|
|
43
|
+
|
|
44
|
+
# 1. Create the dedicated venv at ~/.agentihooks/.venv and install everything
|
|
45
|
+
uv venv ~/.agentihooks/.venv
|
|
46
|
+
uv pip install --python ~/.agentihooks/.venv/bin/python -e ".[all]"
|
|
47
|
+
|
|
48
|
+
# 2. Install hooks + settings + MCP into ~/.claude
|
|
49
|
+
~/.agentihooks/.venv/bin/python scripts/install.py global
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`agentihooks global` wires hooks into `~/.claude/settings.json`, symlinks skills/agents, merges MCP servers into `~/.claude.json`, and installs the CLI globally. **Critically, every hook command in `settings.json` is written with the Python that ran the installer** — so by running the installer from `~/.agentihooks/.venv`, all hook subprocesses find the right packages regardless of which shell or virtual environment is active when Claude Code fires them.
|
|
53
|
+
|
|
54
|
+
Re-run any time — it's idempotent. See [Installation](https://the-cloud-clock-work.github.io/agentihooks/docs/getting-started/installation/) for the full step-by-step walkthrough including Redis setup and quota display.
|
|
55
|
+
|
|
56
|
+
## Hook Events
|
|
57
|
+
|
|
58
|
+
10 lifecycle events, all handled by `python -m hooks`:
|
|
59
|
+
|
|
60
|
+
| Event | What happens |
|
|
61
|
+
|-------|-------------|
|
|
62
|
+
| `SessionStart` | Creates session context directory, injects session awareness, MCP hygiene reminder |
|
|
63
|
+
| `PreToolUse` | Secret scan (blocks on detection), file read deduplication, injects tool error memory |
|
|
64
|
+
| `PostToolUse` | Truncates verbose bash output, marks files read, records tool errors |
|
|
65
|
+
| `Stop` | Scans transcript for errors, parses metrics, auto-saves memory |
|
|
66
|
+
| `SessionEnd` | Logs transcript, clears file read cache, cleans up session directory |
|
|
67
|
+
| `SubagentStop` | Logs subagent transcript |
|
|
68
|
+
| `UserPromptSubmit` | Warns on detected secrets |
|
|
69
|
+
| `Notification` | Logs notifications |
|
|
70
|
+
| `PreCompact` | Logs before context compaction |
|
|
71
|
+
| `PermissionRequest` | Logs permission requests |
|
|
72
|
+
|
|
73
|
+
**StatusLine** is not a hook event — it is a native Claude Code setting (`"statusLine"` key in `settings.json`) handled by `hooks/statusline.py`. It emits a 2–3 line terminal status bar with context fill %, burn rate, cost, cache ratio, and git branch on every turn. `used_pct` is recomputed from `total_input_tokens / context_window_size * 100` to avoid stale payload values.
|
|
74
|
+
|
|
75
|
+
Full payload schemas and handler details: [Hook Events](https://the-cloud-clock-work.github.io/agentihooks/docs/hooks/events/)
|
|
76
|
+
|
|
77
|
+
## MCP Tool Categories
|
|
78
|
+
|
|
79
|
+
45 tools across 12 categories, selectively loaded via `MCP_CATEGORIES`:
|
|
80
|
+
|
|
81
|
+
| Category | Tools | Description |
|
|
82
|
+
|----------|------:|-------------|
|
|
83
|
+
| `github` | 5 | Clone repos, create PRs, token management, git summary |
|
|
84
|
+
| `confluence` | 9 | CRUD pages, markdown docgen, validation |
|
|
85
|
+
| `aws` | 4 | Profile listing, account discovery |
|
|
86
|
+
| `email` | 2 | SMTP send with text / HTML / markdown |
|
|
87
|
+
| `messaging` | 3 | SQS + webhook with state enrichment |
|
|
88
|
+
| `storage` | 2 | S3 upload, `/tmp`-restricted filesystem delete |
|
|
89
|
+
| `database` | 3 | DynamoDB put, PostgreSQL insert + execute |
|
|
90
|
+
| `compute` | 1 | Lambda invocation (sync/async) |
|
|
91
|
+
| `observability` | 7 | Timers, metrics, structured logging, container log tailing |
|
|
92
|
+
| `smith` | 4 | Command builder: list, prompt, build, execute |
|
|
93
|
+
| `agent` | 1 | Remote agent completions with model presets |
|
|
94
|
+
| `utilities` | 4 | Mermaid validation, markdown writer, env vars, tool listing |
|
|
95
|
+
|
|
96
|
+
Per-tool signatures, parameters, and environment variables: [MCP Tools](https://the-cloud-clock-work.github.io/agentihooks/docs/mcp-tools/)
|
|
97
|
+
|
|
98
|
+
## CLI
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
agentihooks global [--profile <name>] # install/re-apply to ~/.claude
|
|
102
|
+
agentihooks project <path> # write .mcp.json into a project
|
|
103
|
+
agentihooks mcp # list MCP files in ~/.agentihooks/
|
|
104
|
+
agentihooks mcp install # two-stage: pick file → pick servers
|
|
105
|
+
agentihooks mcp uninstall # two-stage: pick file → pick servers to remove
|
|
106
|
+
agentihooks mcp add <path> # install a file directly by path
|
|
107
|
+
agentihooks mcp sync # re-apply all installed MCP files
|
|
108
|
+
agentihooks quota # start background quota watcher daemon
|
|
109
|
+
agentihooks quota auth # open browser, paste sessionKey, import cookie, start daemon
|
|
110
|
+
agentihooks quota import-cookies # paste sessionKey without opening browser
|
|
111
|
+
agentihooks quota status # print last known quota JSON
|
|
112
|
+
agentihooks quota logs # tail -f daemon log
|
|
113
|
+
agentihooks quota stop # kill daemon
|
|
114
|
+
agentihooks ignore [path] [--force] # create .claudeignore in cwd (or given path)
|
|
115
|
+
agentihooks uninstall # remove everything
|
|
116
|
+
agentihooks --loadenv # install agentienv shell function into ~/.bashrc
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Full reference: [CLI Commands](https://the-cloud-clock-work.github.io/agentihooks/docs/reference/cli-commands/)
|
|
120
|
+
|
|
121
|
+
## Configuration
|
|
122
|
+
|
|
123
|
+
All integrations are configured via environment variables. Key ones:
|
|
124
|
+
|
|
125
|
+
| Variable | Default | Description |
|
|
126
|
+
|----------|---------|-------------|
|
|
127
|
+
| `AGENTIHOOKS_HOME` | `~/.agentihooks` | Root for logs, memory, and state |
|
|
128
|
+
| `CLAUDE_CODE_HOME_DIR` | `$HOME` | Home-directory root override (`.claude` appended automatically) |
|
|
129
|
+
| `AGENTIHOOKS_CLAUDE_HOME` | `~/.claude` | Legacy: direct path to `.claude` directory |
|
|
130
|
+
| `AGENTIHOOKS_PROFILE` | `default` | Profile to use for `agentihooks global` / `project` (env alternative to `--profile`) |
|
|
131
|
+
| `AGENTIHOOKS_MCP_FILE` | — | Path to an MCP JSON file to auto-merge during `agentihooks global` |
|
|
132
|
+
| `MCP_CATEGORIES` | `all` | Comma-separated list of tool categories to load |
|
|
133
|
+
| `LOG_ENABLED` | `true` | Enable hook logging |
|
|
134
|
+
| `MEMORY_AUTO_SAVE` | `true` | Auto-save session digest on Stop |
|
|
135
|
+
| `REDIS_URL` | — | Redis connection string — format: `redis://:PASSWORD@host:port/db`. Used by token monitor (burn rate), file read cache (dedup), and warning edge-triggers. Graceful degradation when unavailable. |
|
|
136
|
+
| `TOKEN_CONTROL_ENABLED` | `true` | Master switch for the token control layer |
|
|
137
|
+
| `TOKEN_WARN_PCT` | `60` | Context fill % that triggers a warning injection |
|
|
138
|
+
| `TOKEN_CRITICAL_PCT` | `80` | Context fill % that triggers a critical banner |
|
|
139
|
+
| `BASH_FILTER_ENABLED` | `true` | Truncate verbose bash output (docker logs, git log, etc.) |
|
|
140
|
+
| `FILE_READ_CACHE_ENABLED` | `true` | Block redundant file re-reads within a session |
|
|
141
|
+
| `MCP_HYGIENE_ENABLED` | `true` | Inject MCP server usage reminder at session start |
|
|
142
|
+
| `ENABLE_TOOL_SEARCH` | `true` | Make all MCP tools lazy-loaded on demand (set in `env` block of `settings.json`); eliminates ~79K token upfront cost from MCP tool schemas |
|
|
143
|
+
| `CLAUDE_USAGE_FILE` | — | Path to quota JSON file (e.g. `~/.agentihooks/claude_usage.json`). Must be set to enable statusline line 3 quota display. |
|
|
144
|
+
| `CLAUDE_USAGE_STALE_SEC` | `300` | Quota data older than this (seconds) shows "stale" on statusline |
|
|
145
|
+
| `CLAUDE_USAGE_POLL_SEC` | `60` | Quota watcher daemon poll interval (seconds) |
|
|
146
|
+
|
|
147
|
+
Complete table covering all 50+ variables across every integration: [Configuration Reference](https://the-cloud-clock-work.github.io/agentihooks/docs/reference/configuration/)
|
|
148
|
+
|
|
149
|
+
## Profiles
|
|
150
|
+
|
|
151
|
+
Profiles bundle a system prompt (`CLAUDE.md`), MCP category selection, and model settings. Switch with `agentihooks global --profile <name>`.
|
|
152
|
+
|
|
153
|
+
## Portability
|
|
154
|
+
|
|
155
|
+
Everything user-specific lives in `~/.agentihooks/`:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
~/.agentihooks/
|
|
159
|
+
├── .venv/ # Canonical Python venv — all hook subprocesses run from here
|
|
160
|
+
├── .env # Main credentials (seeded from .env.example, loaded first)
|
|
161
|
+
├── *.env # Companion env files (auto-sourced after .env)
|
|
162
|
+
├── *.json # Drop MCP server files here → agentihooks mcp install
|
|
163
|
+
├── state.json # Tracked MCP files and other state
|
|
164
|
+
├── logs/ # Hook + MCP logs
|
|
165
|
+
│ └── quota-watcher.log # Quota watcher daemon log
|
|
166
|
+
├── memory/ # Cross-session agent memory
|
|
167
|
+
├── claude_auth_state.json # Playwright storage state (sessionKey cookie for quota watcher)
|
|
168
|
+
├── claude_usage.json # Written by quota watcher daemon; read by statusline (optional)
|
|
169
|
+
└── quota-watcher.pid # Daemon PID file
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
To move to a new machine: clone the repo, copy `~/.agentihooks/.env`, recreate the venv, run the installer. Done:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
uv venv ~/.agentihooks/.venv
|
|
176
|
+
uv pip install --python ~/.agentihooks/.venv/bin/python -e ".[all]"
|
|
177
|
+
~/.agentihooks/.venv/bin/python scripts/install.py global
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Install the `agentienv` shell function** (sources `.env` into any shell on demand — also auto-called on every new shell):
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
agentihooks --loadenv # writes managed block to ~/.bashrc
|
|
184
|
+
source ~/.bashrc
|
|
185
|
+
agentienv # load vars into current shell before launching claude
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Manage MCP server files** — drop `.json` files into `~/.agentihooks/`:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
agentihooks mcp # list available MCP files
|
|
192
|
+
agentihooks mcp install # interactive: pick one to install
|
|
193
|
+
agentihooks mcp uninstall # interactive: pick one to remove
|
|
194
|
+
agentihooks mcp add <path> # install directly by path
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Details: [Portability & Reusability](https://the-cloud-clock-work.github.io/agentihooks/docs/getting-started/portability/)
|
|
198
|
+
|
|
199
|
+
## Extending
|
|
200
|
+
|
|
201
|
+
Add a new MCP tool category with a `register(server)` function + one line in `_registry.py`. Add a new hook handler with one function + one entry in the dispatcher dict.
|
|
202
|
+
|
|
203
|
+
Guide: [Extending AgentiHooks](https://the-cloud-clock-work.github.io/agentihooks/docs/extending/)
|
|
204
|
+
|
|
205
|
+
## Code Quality
|
|
206
|
+
|
|
207
|
+
Continuously analyzed by [SonarQube](https://sonar.homeofanton.com/dashboard?id=agentihooks).
|
|
208
|
+
|
|
209
|
+
## Related Projects
|
|
210
|
+
|
|
211
|
+
| Project | Description |
|
|
212
|
+
|---------|-------------|
|
|
213
|
+
| [agenticore](https://github.com/The-Cloud-Clock-Work/agenticore) | Claude Code runner and orchestrator |
|
|
214
|
+
| [agentibridge](https://github.com/The-Cloud-Clock-Work/agentibridge) | MCP server for session persistence and remote control |
|
|
215
|
+
| [agentihub](https://github.com/The-Cloud-Clock-Work/agentihub) (private) | Agent identities — CLAUDE.md, workflows, evaluation. Provisioned directly by agenticore. |
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
See [LICENSE](LICENSE) for details.
|