claude-code-handoff 2.0.0 → 2.0.1
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/cli.js +2 -2
- package/hooks/context-monitor.sh +14 -7
- package/install.sh +2 -2
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -105,8 +105,8 @@ fs.chmodSync(path.join(CLAUDE_DIR, 'hooks', 'session-cleanup.sh'), 0o755);
|
|
|
105
105
|
|
|
106
106
|
if (isReinstall) {
|
|
107
107
|
let content = fs.readFileSync(monitorPath, 'utf-8');
|
|
108
|
-
if (savedThreshold && savedThreshold !== '
|
|
109
|
-
content = content.replace('CLAUDE_CONTEXT_THRESHOLD:-
|
|
108
|
+
if (savedThreshold && savedThreshold !== '80') {
|
|
109
|
+
content = content.replace('CLAUDE_CONTEXT_THRESHOLD:-80', `CLAUDE_CONTEXT_THRESHOLD:-${savedThreshold}`);
|
|
110
110
|
ok(`Preserved threshold: ${CYAN}${savedThreshold}%${NC}`);
|
|
111
111
|
}
|
|
112
112
|
if (savedMaxContext && savedMaxContext !== '200000') {
|
package/hooks/context-monitor.sh
CHANGED
|
@@ -12,8 +12,11 @@ fi
|
|
|
12
12
|
# Contexto máximo do Claude Code (tokens). Varia por plano:
|
|
13
13
|
# Pro/Max/Team: 200000 | Enterprise: 500000 | Custom: qualquer valor
|
|
14
14
|
MAX_CONTEXT_TOKENS=${CLAUDE_MAX_CONTEXT:-200000}
|
|
15
|
-
# Threshold configurável (% do
|
|
16
|
-
|
|
15
|
+
# Threshold configurável (% do input_tokens medido).
|
|
16
|
+
# 80% é o padrão seguro — o contexto real (input + output + overhead)
|
|
17
|
+
# é ~10-15% maior do que o input_tokens reportado na API.
|
|
18
|
+
# Com 80%, o hook dispara quando o contexto real está ~90-95%.
|
|
19
|
+
THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-80}
|
|
17
20
|
THRESHOLD_TOKENS=$((MAX_CONTEXT_TOKENS * THRESHOLD_PERCENT / 100))
|
|
18
21
|
|
|
19
22
|
INPUT=$(cat)
|
|
@@ -29,9 +32,9 @@ if [ -z "$SESSION_ID" ]; then
|
|
|
29
32
|
exit 0
|
|
30
33
|
fi
|
|
31
34
|
|
|
32
|
-
# Extrai o
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
+
# Extrai o total de tokens da última mensagem do assistente no JSONL.
|
|
36
|
+
# input_tokens + cache_read_input_tokens + cache_creation_input_tokens = total input medido
|
|
37
|
+
# output_tokens = tokens gerados nessa resposta (somados para melhor estimativa)
|
|
35
38
|
CURRENT_TOKENS=0
|
|
36
39
|
if command -v python3 &>/dev/null; then
|
|
37
40
|
CURRENT_TOKENS=$(python3 -c "
|
|
@@ -43,7 +46,9 @@ with open('$TRANSCRIPT_PATH') as f:
|
|
|
43
46
|
e = json.loads(line)
|
|
44
47
|
if e.get('type') == 'assistant':
|
|
45
48
|
u = e.get('message', {}).get('usage', {})
|
|
46
|
-
|
|
49
|
+
inp = u.get('input_tokens', 0) + u.get('cache_read_input_tokens', 0) + u.get('cache_creation_input_tokens', 0)
|
|
50
|
+
out = u.get('output_tokens', 0)
|
|
51
|
+
t = inp + out
|
|
47
52
|
if t > 0:
|
|
48
53
|
last = t
|
|
49
54
|
except:
|
|
@@ -60,7 +65,9 @@ for (const line of lines) {
|
|
|
60
65
|
const e = JSON.parse(line);
|
|
61
66
|
if (e.type === 'assistant' && e.message?.usage) {
|
|
62
67
|
const u = e.message.usage;
|
|
63
|
-
const
|
|
68
|
+
const inp = (u.input_tokens || 0) + (u.cache_read_input_tokens || 0) + (u.cache_creation_input_tokens || 0);
|
|
69
|
+
const out = (u.output_tokens || 0);
|
|
70
|
+
const t = inp + out;
|
|
64
71
|
if (t > 0) last = t;
|
|
65
72
|
}
|
|
66
73
|
} catch {}
|
package/install.sh
CHANGED
|
@@ -105,8 +105,8 @@ chmod +x "$CLAUDE_DIR/hooks/context-monitor.sh"
|
|
|
105
105
|
chmod +x "$CLAUDE_DIR/hooks/session-cleanup.sh"
|
|
106
106
|
|
|
107
107
|
if [ "$IS_REINSTALL" = true ]; then
|
|
108
|
-
if [ -n "$SAVED_THRESHOLD" ] && [ "$SAVED_THRESHOLD" != "
|
|
109
|
-
sed -i.bak "s/CLAUDE_CONTEXT_THRESHOLD:-
|
|
108
|
+
if [ -n "$SAVED_THRESHOLD" ] && [ "$SAVED_THRESHOLD" != "80" ]; then
|
|
109
|
+
sed -i.bak "s/CLAUDE_CONTEXT_THRESHOLD:-80/CLAUDE_CONTEXT_THRESHOLD:-${SAVED_THRESHOLD}/" "$CLAUDE_DIR/hooks/context-monitor.sh"
|
|
110
110
|
rm -f "$CLAUDE_DIR/hooks/context-monitor.sh.bak"
|
|
111
111
|
ok "Preserved threshold: ${CYAN}${SAVED_THRESHOLD}%${RESET}"
|
|
112
112
|
fi
|
package/package.json
CHANGED