Skip to content

About

Claude Code plugin that blocks task switches mid-session — detects when a prompt starts a new task, enforces /clear, and auto-resubmits your prompt in the fresh session.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

task-switch-gate

A Claude Code plugin that stops developers from starting new tasks inside old sessions.

When a prompt clearly targets a different task than the ongoing conversation, the plugin blocks it and instructs the developer to run /clear. The blocked prompt is saved and automatically resubmitted as the first message of the fresh session — nothing is retyped.

Why

Claude Code sends the whole session history with every turn. Developers who keep working in one session across unrelated tasks waste context, trigger compaction, and — worse — get degraded answers because the model trusts stale file reads and dead assumptions from the previous task. /clear fixes it, but only if people actually run it. This plugin makes the lazy path impossible.

Install

/plugin marketplace add zdamir/task-switch-gate
/plugin install task-switch-gate@task-switch-gate

Requirements: python3 and the claude CLI on PATH (both already present for any Claude Code user). No API key — classification runs through claude -p using your existing auth.

How it works

  1. On every prompt, a UserPromptSubmit hook reads the session transcript.
  2. Young sessions (<3 user turns), slash commands, and trivial prompts ("continue", "yes") pass instantly — no model call, no latency.
  3. Otherwise a Haiku classifier compares the new prompt against the last 6 user prompts.
  4. It blocks only on high-confidence task switches. Ambiguity → allowed. Classifier error, timeout, or garbage output → allowed (fail-open). It can never lock you out.
  5. On block, the prompt is written to .claude/.pending-task-prompt in your project. A SessionStart hook (matcher: clear) picks it up and resubmits it in the fresh session. Pending prompts expire after 10 minutes.

Add .claude/.pending-task-prompt to your project .gitignore.

Tuning

Knobs at the top of hooks/task_switch_gate.py:

Setting Default Meaning
MIN_USER_TURNS 3 Skip classification for young sessions
MAX_HISTORY_PROMPTS 6 Recent prompts shown to the classifier
CLASSIFIER_MODEL claude-haiku-4-5 Model for the yes/no call
CLASSIFIER_TIMEOUT 25s Hard cap on the classifier call

The classifier prompt is deliberately biased toward "not a new task". If you see false positives, tighten the rules text in call_classifier before touching thresholds.

If your Claude Code version ignores initialUserMessage from SessionStart hooks, set USE_INITIAL_USER_MESSAGE = False in hooks/inject_handoff.py to fall back to context injection.

Local development

Test changes without installing:

claude --plugin-dir /path/to/task-switch-gate

Validate structure:

claude plugin validate .

License

MIT

About

Claude Code plugin that blocks task switches mid-session — detects when a prompt starts a new task, enforces /clear, and auto-resubmits your prompt in the fresh session.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages