braintracker 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +60 -0
- package/bin/braintracker.js +100 -0
- package/braintracker/hooks/post_skill.js +45 -0
- package/braintracker/hooks/pre_skill.js +35 -0
- package/package.json +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Salad Arena for Researching, Insight and Prototyping
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# braintracker
|
|
2
|
+
|
|
3
|
+
A Claude Code plugin that automatically logs every skill invocation — name, duration, and the prompt that triggered it — using Claude Code hooks.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx braintracker
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
That's it. The command copies the hook files to `~/.claude/plugins/braintracker/hooks/` and registers them in `~/.claude/settings.json`.
|
|
12
|
+
|
|
13
|
+
**Requirements:** [Claude Code](https://claude.ai/code) and Node.js (already bundled with Claude Code).
|
|
14
|
+
|
|
15
|
+
## Disable / Enable
|
|
16
|
+
|
|
17
|
+
Pause logging without uninstalling:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx braintracker disable # removes hooks from settings.json, keeps files
|
|
21
|
+
npx braintracker enable # re-registers the hooks
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Uninstall
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx braintracker uninstall
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Removes the hook files and cleans up `~/.claude/settings.json`.
|
|
31
|
+
|
|
32
|
+
## Verify
|
|
33
|
+
|
|
34
|
+
Invoke any skill inside Claude Code (e.g. `/review`), then:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cat ~/.claude/plugin/cache/cctracking/<project>/<session_id>.jsonl
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Each line is a JSON object:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"type": "skill_invocation",
|
|
45
|
+
"session_id": "abc123",
|
|
46
|
+
"skill": "review",
|
|
47
|
+
"triggered_by": "review this PR",
|
|
48
|
+
"started_at": "2026-05-25T10:00:00Z",
|
|
49
|
+
"duration_seconds": 4.2
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## How It Works
|
|
54
|
+
|
|
55
|
+
| Hook | Script | Action |
|
|
56
|
+
|------|--------|--------|
|
|
57
|
+
| `PreToolUse` (Skill) | `pre_skill.js` | Writes a timing snapshot to `<session>.pre.json` |
|
|
58
|
+
| `PostToolUse` (Skill) | `post_skill.js` | Reads the snapshot, computes duration, appends a log entry to `<session>.jsonl`, deletes the snapshot |
|
|
59
|
+
|
|
60
|
+
Logs live at `~/.claude/plugin/cache/cctracking/<project>/` — one JSONL file per session, grouped by project name.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
|
|
6
|
+
const DEST_HOOKS = path.join(os.homedir(), '.claude', 'plugins', 'braintracker', 'hooks');
|
|
7
|
+
const SETTINGS = path.join(os.homedir(), '.claude', 'settings.json');
|
|
8
|
+
|
|
9
|
+
const PRE_CMD = `node ${path.join(DEST_HOOKS, 'pre_skill.js')}`;
|
|
10
|
+
const POST_CMD = `node ${path.join(DEST_HOOKS, 'post_skill.js')}`;
|
|
11
|
+
|
|
12
|
+
function readSettings() {
|
|
13
|
+
try { return JSON.parse(fs.readFileSync(SETTINGS, 'utf8')); } catch { return {}; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function writeSettings(settings) {
|
|
17
|
+
fs.mkdirSync(path.dirname(SETTINGS), { recursive: true });
|
|
18
|
+
fs.writeFileSync(SETTINGS, JSON.stringify(settings, null, 2) + '\n');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function addHook(arr, matcher, command) {
|
|
22
|
+
let group = arr.find(h => h.matcher === matcher);
|
|
23
|
+
if (!group) { group = { matcher, hooks: [] }; arr.push(group); }
|
|
24
|
+
group.hooks = group.hooks || [];
|
|
25
|
+
if (!group.hooks.some(h => h.command === command)) {
|
|
26
|
+
group.hooks.push({ type: 'command', command });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function removeHook(arr, command) {
|
|
31
|
+
if (!arr) return arr;
|
|
32
|
+
return arr
|
|
33
|
+
.map(group => ({ ...group, hooks: (group.hooks || []).filter(h => h.command !== command) }))
|
|
34
|
+
.filter(group => group.hooks.length > 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function install() {
|
|
38
|
+
const SRC_HOOKS = path.join(__dirname, '..', 'braintracker', 'hooks');
|
|
39
|
+
fs.mkdirSync(DEST_HOOKS, { recursive: true });
|
|
40
|
+
for (const file of ['pre_skill.js', 'post_skill.js']) {
|
|
41
|
+
fs.copyFileSync(path.join(SRC_HOOKS, file), path.join(DEST_HOOKS, file));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const settings = readSettings();
|
|
45
|
+
settings.hooks = settings.hooks || {};
|
|
46
|
+
settings.hooks.PreToolUse = settings.hooks.PreToolUse || [];
|
|
47
|
+
settings.hooks.PostToolUse = settings.hooks.PostToolUse || [];
|
|
48
|
+
addHook(settings.hooks.PreToolUse, 'Skill', PRE_CMD);
|
|
49
|
+
addHook(settings.hooks.PostToolUse, 'Skill', POST_CMD);
|
|
50
|
+
writeSettings(settings);
|
|
51
|
+
|
|
52
|
+
console.log('braintracker installed.');
|
|
53
|
+
console.log('Logs → ~/.claude/plugin/cache/cctracking/<project>/<session>.jsonl');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function uninstall() {
|
|
57
|
+
fs.rmSync(path.join(os.homedir(), '.claude', 'plugins', 'braintracker'), { recursive: true, force: true });
|
|
58
|
+
|
|
59
|
+
const settings = readSettings();
|
|
60
|
+
if (settings.hooks) {
|
|
61
|
+
settings.hooks.PreToolUse = removeHook(settings.hooks.PreToolUse, PRE_CMD);
|
|
62
|
+
settings.hooks.PostToolUse = removeHook(settings.hooks.PostToolUse, POST_CMD);
|
|
63
|
+
}
|
|
64
|
+
writeSettings(settings);
|
|
65
|
+
|
|
66
|
+
console.log('braintracker uninstalled.');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function disable() {
|
|
70
|
+
const settings = readSettings();
|
|
71
|
+
if (settings.hooks) {
|
|
72
|
+
settings.hooks.PreToolUse = removeHook(settings.hooks.PreToolUse, PRE_CMD);
|
|
73
|
+
settings.hooks.PostToolUse = removeHook(settings.hooks.PostToolUse, POST_CMD);
|
|
74
|
+
}
|
|
75
|
+
writeSettings(settings);
|
|
76
|
+
console.log('braintracker disabled. Hook files kept. Run "npx braintracker enable" to re-enable.');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function enable() {
|
|
80
|
+
if (!fs.existsSync(path.join(DEST_HOOKS, 'pre_skill.js'))) {
|
|
81
|
+
console.error('braintracker is not installed. Run "npx braintracker" to install first.');
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const settings = readSettings();
|
|
86
|
+
settings.hooks = settings.hooks || {};
|
|
87
|
+
settings.hooks.PreToolUse = settings.hooks.PreToolUse || [];
|
|
88
|
+
settings.hooks.PostToolUse = settings.hooks.PostToolUse || [];
|
|
89
|
+
addHook(settings.hooks.PreToolUse, 'Skill', PRE_CMD);
|
|
90
|
+
addHook(settings.hooks.PostToolUse, 'Skill', POST_CMD);
|
|
91
|
+
writeSettings(settings);
|
|
92
|
+
|
|
93
|
+
console.log('braintracker enabled.');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const cmd = process.argv[2];
|
|
97
|
+
if (cmd === 'uninstall') uninstall();
|
|
98
|
+
else if (cmd === 'disable') disable();
|
|
99
|
+
else if (cmd === 'enable') enable();
|
|
100
|
+
else install();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
|
|
6
|
+
let raw = '';
|
|
7
|
+
process.stdin.on('data', chunk => (raw += chunk));
|
|
8
|
+
process.stdin.on('end', () => {
|
|
9
|
+
let payload;
|
|
10
|
+
try {
|
|
11
|
+
payload = JSON.parse(raw);
|
|
12
|
+
} catch {
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (payload.tool_name !== 'Skill') process.exit(0);
|
|
17
|
+
|
|
18
|
+
const sessionId = payload.session_id;
|
|
19
|
+
const prj = path.basename(process.cwd());
|
|
20
|
+
const cacheDir = path.join(os.homedir(), '.claude', 'plugin', 'cache', 'cctracking', prj);
|
|
21
|
+
const preFile = path.join(cacheDir, `${sessionId}.pre.json`);
|
|
22
|
+
|
|
23
|
+
let preData;
|
|
24
|
+
try {
|
|
25
|
+
preData = JSON.parse(fs.readFileSync(preFile, 'utf8'));
|
|
26
|
+
} catch {
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const durationSeconds = (Date.now() - preData.start_time) / 1000;
|
|
31
|
+
const entry = {
|
|
32
|
+
type: 'skill_invocation',
|
|
33
|
+
session_id: sessionId,
|
|
34
|
+
skill: preData.skill,
|
|
35
|
+
triggered_by: preData.triggered_by,
|
|
36
|
+
started_at: new Date(preData.start_time).toISOString(),
|
|
37
|
+
duration_seconds: durationSeconds,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const logFile = path.join(cacheDir, `${sessionId}.jsonl`);
|
|
41
|
+
fs.appendFileSync(logFile, JSON.stringify(entry) + '\n');
|
|
42
|
+
fs.unlinkSync(preFile);
|
|
43
|
+
|
|
44
|
+
process.exit(0);
|
|
45
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
|
|
6
|
+
let raw = '';
|
|
7
|
+
process.stdin.on('data', chunk => (raw += chunk));
|
|
8
|
+
process.stdin.on('end', () => {
|
|
9
|
+
let payload;
|
|
10
|
+
try {
|
|
11
|
+
payload = JSON.parse(raw);
|
|
12
|
+
} catch {
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (payload.tool_name !== 'Skill') process.exit(0);
|
|
17
|
+
|
|
18
|
+
const sessionId = payload.session_id;
|
|
19
|
+
const skill = (payload.tool_input && payload.tool_input.skill) || 'unknown';
|
|
20
|
+
const triggeredBy = (payload.tool_input && payload.tool_input.args) || '';
|
|
21
|
+
const prj = path.basename(process.cwd());
|
|
22
|
+
const cacheDir = path.join(os.homedir(), '.claude', 'plugin', 'cache', 'cctracking', prj);
|
|
23
|
+
|
|
24
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
25
|
+
|
|
26
|
+
const preFile = path.join(cacheDir, `${sessionId}.pre.json`);
|
|
27
|
+
fs.writeFileSync(preFile, JSON.stringify({
|
|
28
|
+
session_id: sessionId,
|
|
29
|
+
skill,
|
|
30
|
+
triggered_by: triggeredBy,
|
|
31
|
+
start_time: Date.now(),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
process.exit(0);
|
|
35
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "braintracker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Claude Code plugin that logs every skill invocation with duration and triggering prompt",
|
|
5
|
+
"bin": {
|
|
6
|
+
"braintracker": "bin/braintracker.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/",
|
|
10
|
+
"braintracker/hooks/"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
}
|
|
16
|
+
}
|