claude-code-handoff 1.7.0 → 1.8.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/README.md +42 -19
- package/commands/auto-handoff.md +42 -15
- package/hooks/context-monitor.sh +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -178,19 +178,34 @@ flowchart TD
|
|
|
178
178
|
H --> I["User: /clear → /resume"]
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
+
### Plan Selection
|
|
182
|
+
|
|
183
|
+
The context window varies by Claude plan. The hook adapts automatically based on your plan configuration:
|
|
184
|
+
|
|
185
|
+
| Plan | Context Window | Value |
|
|
186
|
+
|------|---------------|-------|
|
|
187
|
+
| **Pro / Max / Team** | 200K tokens | `MAX_CONTEXT_TOKENS=200000` (default) |
|
|
188
|
+
| **Enterprise** | 500K tokens | `MAX_CONTEXT_TOKENS=500000` |
|
|
189
|
+
| **Custom** | Any value | Set via `/auto-handoff` or env var |
|
|
190
|
+
|
|
191
|
+
Configure your plan via the `/auto-handoff` wizard or set the environment variable:
|
|
192
|
+
```bash
|
|
193
|
+
export CLAUDE_MAX_CONTEXT=500000 # Enterprise
|
|
194
|
+
```
|
|
195
|
+
|
|
181
196
|
### Threshold Configuration
|
|
182
197
|
|
|
183
|
-
The threshold is configured as a **percentage of
|
|
198
|
+
The threshold is configured as a **percentage of your plan's context window**. The hook reads the **actual token count** from Claude's API usage data in the transcript — no guesswork, no byte-to-token estimation.
|
|
184
199
|
|
|
185
|
-
| Preset | Value | Triggers at | Best for |
|
|
186
|
-
|
|
187
|
-
| **90% (default)** | `THRESHOLD_PERCENT=90` | 180K tokens | Maximizing context usage |
|
|
188
|
-
| **80%** | `THRESHOLD_PERCENT=80` | 160K tokens | Balance between space and safety |
|
|
189
|
-
| **75%** | `THRESHOLD_PERCENT=75` | 150K tokens | Short sessions, early handoff |
|
|
200
|
+
| Preset | Value | Triggers at (200K) | Triggers at (500K) | Best for |
|
|
201
|
+
|--------|-------|---------------------|---------------------|----------|
|
|
202
|
+
| **90% (default)** | `THRESHOLD_PERCENT=90` | 180K tokens | 450K tokens | Maximizing context usage |
|
|
203
|
+
| **80%** | `THRESHOLD_PERCENT=80` | 160K tokens | 400K tokens | Balance between space and safety |
|
|
204
|
+
| **75%** | `THRESHOLD_PERCENT=75` | 150K tokens | 375K tokens | Short sessions, early handoff |
|
|
190
205
|
|
|
191
206
|
The calculation uses real data:
|
|
192
207
|
```
|
|
193
|
-
MAX_CONTEXT_TOKENS = 200000
|
|
208
|
+
MAX_CONTEXT_TOKENS = 200000 (or 500000 for Enterprise, or custom)
|
|
194
209
|
THRESHOLD = MAX_CONTEXT_TOKENS × THRESHOLD_PERCENT / 100
|
|
195
210
|
|
|
196
211
|
# The hook reads input_tokens from the last assistant message in the JSONL
|
|
@@ -199,31 +214,39 @@ THRESHOLD = MAX_CONTEXT_TOKENS × THRESHOLD_PERCENT / 100
|
|
|
199
214
|
|
|
200
215
|
### Three Ways to Configure
|
|
201
216
|
|
|
202
|
-
**1. Environment
|
|
217
|
+
**1. Environment variables** (per-session override):
|
|
203
218
|
```bash
|
|
204
|
-
#
|
|
205
|
-
export CLAUDE_CONTEXT_THRESHOLD=80
|
|
219
|
+
export CLAUDE_MAX_CONTEXT=500000 # Enterprise plan (500K)
|
|
220
|
+
export CLAUDE_CONTEXT_THRESHOLD=80 # Trigger at 80%
|
|
206
221
|
```
|
|
207
222
|
|
|
208
223
|
**2. Interactive wizard** (`/auto-handoff` command):
|
|
209
224
|
```
|
|
210
225
|
you: /auto-handoff
|
|
211
|
-
claude: Auto-handoff is
|
|
212
|
-
|
|
213
|
-
|
|
226
|
+
claude: Auto-handoff is DISABLED (plan: Pro/Max/Team, threshold: 90%).
|
|
227
|
+
What would you like to do?
|
|
228
|
+
1. Enable
|
|
229
|
+
2. Enable with custom configuration
|
|
214
230
|
|
|
215
|
-
you: [selects "
|
|
231
|
+
you: [selects "Enable with custom configuration"]
|
|
232
|
+
claude: Which is your Claude plan?
|
|
233
|
+
1. Pro / Max / Team — 200K tokens
|
|
234
|
+
2. Enterprise — 500K tokens
|
|
235
|
+
3. Other — Type a custom value
|
|
236
|
+
|
|
237
|
+
you: [selects plan]
|
|
216
238
|
claude: Which threshold do you want?
|
|
217
|
-
1. 90% (Recommended)
|
|
218
|
-
2. 80%
|
|
219
|
-
3. 75%
|
|
239
|
+
1. 90% (Recommended)
|
|
240
|
+
2. 80%
|
|
241
|
+
3. 75%
|
|
220
242
|
4. Other — Type a custom value
|
|
221
243
|
```
|
|
222
244
|
|
|
223
245
|
**3. Edit the script directly**:
|
|
224
246
|
```bash
|
|
225
|
-
# In .claude/hooks/context-monitor.sh, change the
|
|
226
|
-
|
|
247
|
+
# In .claude/hooks/context-monitor.sh, change the defaults:
|
|
248
|
+
MAX_CONTEXT_TOKENS=${CLAUDE_MAX_CONTEXT:-200000} # change 200000 to your value
|
|
249
|
+
THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-90} # change 90 to your value
|
|
227
250
|
```
|
|
228
251
|
|
|
229
252
|
### Safety Mechanisms
|
package/commands/auto-handoff.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Auto-Handoff
|
|
2
2
|
|
|
3
|
-
Toggle the automatic handoff context monitor on/off and
|
|
3
|
+
Toggle the automatic handoff context monitor on/off, configure threshold, and select your Claude plan.
|
|
4
4
|
|
|
5
5
|
## Instructions
|
|
6
6
|
|
|
@@ -10,28 +10,55 @@ Check if `.claude/hooks/.auto-handoff-disabled` exists:
|
|
|
10
10
|
- If exists → currently DISABLED
|
|
11
11
|
- If not exists → currently ENABLED
|
|
12
12
|
|
|
13
|
-
Also read
|
|
13
|
+
Also read from `.claude/hooks/context-monitor.sh`:
|
|
14
|
+
- `THRESHOLD_PERCENT` value (the default in `THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-XX}`)
|
|
15
|
+
- `MAX_CONTEXT_TOKENS` value (the default in `MAX_CONTEXT_TOKENS=${CLAUDE_MAX_CONTEXT:-XXXXXX}`)
|
|
16
|
+
|
|
17
|
+
Derive the plan name from MAX_CONTEXT_TOKENS:
|
|
18
|
+
- 200000 → "Pro/Max/Team"
|
|
19
|
+
- 500000 → "Enterprise"
|
|
20
|
+
- other → "Custom (XXXk)"
|
|
14
21
|
|
|
15
22
|
### Step 2: Present wizard
|
|
16
23
|
|
|
17
24
|
Use AskUserQuestion:
|
|
18
|
-
- Question: "Auto-handoff está [ATIVADO/DESATIVADO] (threshold: [XX]%). O que deseja fazer?"
|
|
25
|
+
- Question: "Auto-handoff está [ATIVADO/DESATIVADO] (plano: [PLAN], threshold: [XX]%). O que deseja fazer?"
|
|
19
26
|
- Options based on current state:
|
|
20
|
-
- If enabled: "Desativar" / "Ajustar threshold"
|
|
21
|
-
- If disabled: "Ativar" / "Ativar com
|
|
27
|
+
- If enabled: "Desativar" / "Ajustar threshold" / "Alterar plano"
|
|
28
|
+
- If disabled: "Ativar" / "Ativar com configuração customizada"
|
|
22
29
|
|
|
23
30
|
### Step 3: Execute
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
32
|
+
#### Toggle (Ativar/Desativar):
|
|
33
|
+
- Create or delete `.claude/hooks/.auto-handoff-disabled`
|
|
34
|
+
|
|
35
|
+
#### Ajustar threshold:
|
|
36
|
+
Ask with AskUserQuestion:
|
|
37
|
+
- Question: "Qual threshold deseja usar?"
|
|
38
|
+
- Options:
|
|
39
|
+
- "90% (Recomendado)" — Padrão, maximiza o uso do contexto
|
|
40
|
+
- "80%" — Equilíbrio entre espaço e segurança
|
|
41
|
+
- "75%" — Para sessões curtas, salva handoff mais cedo
|
|
42
|
+
- The user can also type a custom value via "Other"
|
|
43
|
+
- Update the `THRESHOLD_PERCENT` default value in `context-monitor.sh` by changing `THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-XX}` to the chosen value
|
|
44
|
+
|
|
45
|
+
#### Alterar plano:
|
|
46
|
+
Ask with AskUserQuestion:
|
|
47
|
+
- Question: "Qual seu plano do Claude?"
|
|
48
|
+
- Options:
|
|
49
|
+
- "Pro / Max / Team" — 200K tokens de contexto
|
|
50
|
+
- "Enterprise" — 500K tokens de contexto (Sonnet 4.5)
|
|
51
|
+
- The user can also type a custom value via "Other" (e.g., "1000000" for 1M API context)
|
|
52
|
+
- Update the `MAX_CONTEXT_TOKENS` default value in `context-monitor.sh` by changing `MAX_CONTEXT_TOKENS=${CLAUDE_MAX_CONTEXT:-XXXXXX}` to the chosen value
|
|
53
|
+
|
|
54
|
+
#### Ativar com configuração customizada:
|
|
55
|
+
Run both "Alterar plano" and "Ajustar threshold" flows above, then delete `.claude/hooks/.auto-handoff-disabled`
|
|
34
56
|
|
|
35
57
|
### Step 4: Confirm
|
|
36
58
|
|
|
37
|
-
Show current state after change
|
|
59
|
+
Show current state after change:
|
|
60
|
+
```
|
|
61
|
+
Auto-handoff: [ATIVADO/DESATIVADO]
|
|
62
|
+
Plano: [plan name] ([MAX_CONTEXT_TOKENS] tokens)
|
|
63
|
+
Threshold: [XX]% (triggers at [calculated tokens] tokens)
|
|
64
|
+
```
|
package/hooks/context-monitor.sh
CHANGED
|
@@ -9,8 +9,9 @@ if [ -f "$SCRIPT_DIR/.auto-handoff-disabled" ]; then
|
|
|
9
9
|
exit 0
|
|
10
10
|
fi
|
|
11
11
|
|
|
12
|
-
# Contexto máximo do Claude Code (tokens)
|
|
13
|
-
|
|
12
|
+
# Contexto máximo do Claude Code (tokens). Varia por plano:
|
|
13
|
+
# Pro/Max/Team: 200000 | Enterprise: 500000 | Custom: qualquer valor
|
|
14
|
+
MAX_CONTEXT_TOKENS=${CLAUDE_MAX_CONTEXT:-200000}
|
|
14
15
|
# Threshold configurável (% do contexto). 90% padrão — maximiza uso do contexto
|
|
15
16
|
THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-90}
|
|
16
17
|
THRESHOLD_TOKENS=$((MAX_CONTEXT_TOKENS * THRESHOLD_PERCENT / 100))
|
package/package.json
CHANGED