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 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 !== '90') {
109
- content = content.replace('CLAUDE_CONTEXT_THRESHOLD:-90', `CLAUDE_CONTEXT_THRESHOLD:-${savedThreshold}`);
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') {
@@ -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 contexto). 90% padrão — maximiza uso do contexto
16
- THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-90}
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 input_tokens da última mensagem do assistente no JSONL.
33
- # Isso reflete o tamanho REAL do contexto que o Claude está usando.
34
- # Campos: input_tokens + cache_read_input_tokens + cache_creation_input_tokens = total input
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
- t = u.get('input_tokens', 0) + u.get('cache_read_input_tokens', 0) + u.get('cache_creation_input_tokens', 0)
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 t = (u.input_tokens || 0) + (u.cache_read_input_tokens || 0) + (u.cache_creation_input_tokens || 0);
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" != "90" ]; then
109
- sed -i.bak "s/CLAUDE_CONTEXT_THRESHOLD:-90/CLAUDE_CONTEXT_THRESHOLD:-${SAVED_THRESHOLD}/" "$CLAUDE_DIR/hooks/context-monitor.sh"
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-handoff",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Session continuity for Claude Code — 6 slash commands to save, resume, delete, and switch workstreams across /clear",
5
5
  "bin": {
6
6
  "claude-code-handoff": "./cli.js"