Metadata-Version: 2.5
Name: hooklens
Version: 0.1.4
Summary: See what your coding agents do: tool calls, commands, files, and tokens from Claude Code, Codex, and Cursor, stored on your machine.
Project-URL: Homepage, https://github.com/Kunal-5402/hooklens
Project-URL: Issues, https://github.com/Kunal-5402/hooklens/issues
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: ai-agents,claude-code,codex,cursor,hooks,observability,telemetry
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.11
Description-Content-Type: text/markdown

<div align="center">

# hooklens

**See what your coding agent actually did.**

Every tool call, shell command, file change, MCP call, and token, from Claude Code, Codex, and Cursor.
As a trace of every turn, on your machine.

[![CI](https://github.com/Kunal-5402/hooklens/actions/workflows/ci.yml/badge.svg)](https://github.com/Kunal-5402/hooklens/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/hooklens?cacheSeconds=3600)](https://pypi.org/project/hooklens/)
[![Python](https://img.shields.io/badge/python-3.11%2B-blue)](pyproject.toml)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)

![Hooklens session trace: a turn with its tool calls, and the details of a failed test run](assets/trace.png)

</div>

## Why hooklens

Coding agents run commands, edit files, and call tools faster than you can read the transcript.
hooklens records what happened through the agents' own hooks, so you can answer questions like:

- Which files did the agent change, and which did it only read?
- What shell commands ran, and which ones failed?
- Which MCP servers and tools did it use?
- Where did the time go, and how many tokens did the session cost?

It is a single Python package with **no dependencies**. Data stays in a local SQLite file, and the
UI is a local web page. **Nothing leaves your machine.**

## Features

- **Trace** of each turn: the prompt, then every tool call on a time axis, with duration and status.
  Idle gaps are compressed, and active time is counted apart from idle time.
- **Details** of each call: the input, the error, a response excerpt, and the files it touched.
- **Tools and files**: time by activity, calls and p95 duration for each tool, every file changed
  or read, and the commands that ran.
- **Event log** with search, a category filter, and an errors-only filter.
- **Tokens and model** from the agent's transcript.
- **Live view** that updates while the agent works.
- **One view for three agents.** Claude Code, Codex, and Cursor events are normalized to one schema.
- **Policy webhook** (optional). Your policy engine can allow, deny, or ask before a tool call or a
  prompt, with 1 request format for all 3 agents. Every decision is stored and shown in the trace.

## Supported agents

| Agent | Tool calls | Prompts and turns | Tokens | Hooks file |
|---|:---:|:---:|:---:|---|
| Claude Code | ✅ | ✅ | ✅ | `~/.claude/settings.json` |
| Codex | ✅ | ✅ | ✅ | `~/.codex/hooks.json` |
| Cursor | ✅ | ✅ | — | `~/.cursor/hooks.json` |

## Quick start

```sh
uv tool install hooklens        # or: pipx install hooklens
hooklens install                # add hooks to every agent it finds
```

Start a **new** agent session (hooks load when a session starts), use the agent, then run:

```sh
hooklens show                   # opens http://127.0.0.1:7878
```

To install one agent at a time, use `hooklens claude install`, `hooklens codex install`, or
`hooklens cursor install`.

## Usage

| Command | What it does |
|---|---|
| `hooklens show [session]` | Open the UI for all sessions, or one session |
| `hooklens <agent> show` | Open the UI for one agent (`claude`, `codex`, `cursor`) |
| `hooklens sessions` | List recent sessions in the terminal |
| `hooklens doctor` | Check the hooks, the database, and recent events |
| `hooklens clear` | Delete all recorded data (the hooks stay) |
| `hooklens uninstall` | Remove the hooks (your other hooks and settings stay) |
| `hooklens uninstall --purge` | Remove the hooks, the data, the config backups, and the policy |
| `hooklens policy set <url>` | Ask a policy webhook before tool calls and prompts ([details](design/policy.md)) |
| `hooklens policy test` | Send a test tool call to the webhook and show the decision |

Commands that delete data ask first. Add `--dry-run` to see what would be removed, or `--yes` to
skip the question.

<details>
<summary><b>More screenshots</b></summary>

Tools and files: where the time went, each tool's calls and durations, and the files that changed.

![Tools and files](https://raw.githubusercontent.com/Kunal-5402/hooklens/main/assets/tools.png)

</details>

## How it works

```
agent ──hook event (JSON)──> hooklens hook ──> SQLite (raw events)
                                                   │
                         hooklens show ──> normalize ──> sessions, events, files ──> local UI
```

1. **Capture.** The agent runs `hooklens <agent> hook` on each event. The hook stores the raw
   event and exits in about 30 ms. Without a policy webhook, it never blocks or changes what the agent does.
2. **Normalize.** When you open the UI, hooklens maps each agent's events to one schema, pairs tool
   starts with their results, and reads token usage from the agent's transcript.
3. **View.** A small server on `127.0.0.1` serves the UI and a JSON API.

Without a policy, hooklens never changes what the agent does. Read
[design/architecture.md](design/architecture.md) for the details and
[design/sequence.md](design/sequence.md) for the full call flow.

## Policy webhook

A policy engine can allow, deny, or ask before an agent runs a tool or sends a prompt. hooklens
sends 1 JSON request with the same fields for every agent, and gives each agent the decision in the
form that it expects.

```sh
python examples/policy_server.py                  # a small example engine on 127.0.0.1:8787
hooklens policy set http://127.0.0.1:8787/check   # --fail-closed, --timeout, --header 'Authorization: Bearer ${TOKEN}'
hooklens policy test --command "rm -rf ~"         # Decision: deny (5 ms)
```

The engine answers `{"decision": "allow" | "deny" | "ask", "reason": "..."}`. `allow` means "no
objection", so the agent's own permission rules still apply. Denied calls show as "Blocked" in the
trace. Read [design/policy.md](design/policy.md) for the request format and for how each agent
handles each decision.

## Privacy and safety

- All data is in `~/.hooklens/hooklens.db`. Nothing is sent over the network, unless you set a
  policy webhook: then each checked tool call or prompt goes to that URL.
- Each string is trimmed to 4096 characters before it is stored, so full file contents and long
  outputs are not kept. Set `HOOKLENS_MAX_FIELD` to change the limit (`0` keeps everything).
- Cursor sends your account email with each event. hooklens removes it before storage.
- hooklens backs up an agent config file before it changes it, and only ever edits its own entries.
- `hooklens uninstall --purge` removes everything hooklens created, and nothing else.

## Configuration

| Variable | Default | Purpose |
|---|---|---|
| `HOOKLENS_HOME` | `~/.hooklens` | Where the database and error log live |
| `HOOKLENS_MAX_FIELD` | `4096` | Max characters stored per string (`0` = no limit) |
| `HOOKLENS_CLAUDE_SETTINGS` | `~/.claude/settings.json` | Claude Code settings file |
| `CODEX_HOME` | `~/.codex` | Codex config folder |
| `HOOKLENS_CURSOR_HOME` | `~/.cursor` | Cursor config folder |

## Roadmap

See the [milestones](https://github.com/Kunal-5402/hooklens/milestones): the first PyPI release,
importing past sessions, cost estimates, OpenTelemetry and SIEM export, and a local daemon for
faster policy checks.

## Contributing

Contributions are welcome. Read [CONTRIBUTING.md](CONTRIBUTING.md) to get started.

```sh
make setup     # create .venv with the dev dependencies (needs uv)
make check     # lint, format check, and tests: the same checks as CI
```

<details>
<summary><b>Releasing (maintainers)</b></summary>

1. Set `__version__` in `src/hooklens/__init__.py` (the only place with the version), and merge to `main`.
2. Publish a GitHub release with a SemVer tag: `v1.2.3`, or `v1.2.3-alpha.1`, `-beta.1`, `-rc.1`.
3. Approve the `pypi` deployment. The release workflow checks the tag, runs the tests, builds the
   package, and publishes it to PyPI.

</details>

## License

[Apache License 2.0](LICENSE). Copyright 2026 Kunal.
