Git-powered state awareness - track file changes, session context, decisions, and work history. Query what happened in previous sessions and during current session. Auto-activates for state queries and before duplicating work.
/plugin marketplace add Shakes-tzd/contextune/plugin install contextune@ContextuneThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Purpose: Provide Claude with complete awareness of project state using git as source of truth, preventing stale mental models and redundant work.
What This System Tracks:
In-Session State (real-time)
Between-Session Context (differential)
Historical Decisions (queryable)
Token Overhead:
Auto-activates when you detect:
State Queries:
Before File Operations:
Before Duplicating Work:
Run the manual status script:
./scripts/session-status.sh
This shows:
Token cost: ~500 tokens for complete state summary
Trust the PreToolUse hook:
Don't manually check git status - hook does it automatically!
Query decisions.yaml first:
# Before research
uv run scripts/decision-query.py --topic "{topic}" --type research
# Before planning
uv run scripts/decision-query.py --topic "{topic}" --type plans
# Before deciding
uv run scripts/decision-query.py --topic "{topic}" --type decisions
If found: Load existing context (2-5K tokens) If not found: Proceed with new work
###If User Made External Changes
User says: "I made some changes" or "I committed something"
Your response:
# Check what changed
./scripts/session-status.sh
Then summarize what you found for the user.
PreToolUse Hook checks git state before file operations:
# Happens automatically when you try to Edit/Write
PreToolUse: Intercepts tool call
→ Runs: git status <file>
→ If changed: "⚠️ File modified externally - Re-read before editing"
→ Always continues (non-blocking)
What you see:
⚠️ File State Change Detected
File: hooks/user_prompt_submit.py
Status: MODIFIED
Git Says: File has uncommitted changes
Recommendation:
- Re-read file to see current state
- Use Read tool before Edit
Continuing with your Edit operation...
Token cost: ~300 tokens (only when file actually changed)
SessionStart Hook injects git context automatically:
Session starts:
→ SessionStart reads .contextune/last_session.yaml
→ Runs: git log <last_commit>..HEAD
→ Runs: git diff --stat <last_commit>..HEAD
→ Generates differential summary
→ Injects as additionalContext
What you see at session start:
📋 Git Context Since Last Session (2 hours ago)
**Git Activity:**
- 5 new commits
- 8 files changed (+250, -30)
- Branch: master
**Recent Commits:**
a95478f feat: add three-layer git enforcement
1e1a15a feat: add plan extraction support
... and 3 more
**Files Changed:**
Added (2):
- commands/ctx-git-commit.md
- hooks/pre_tool_use_git_advisor.py
Modified (6):
- hooks/user_prompt_submit.py
- hooks/hooks.json
... and 4 more
**Current Status:** 2 uncommitted changes
Ready to continue work!
Token cost: ~1-2K tokens (only NEW information since last session)
When user asks "what changed?" or you need to check state:
# Run the status script
./scripts/session-status.sh
Shows:
When to use:
Token cost: ~500 tokens
10:00 - You: Read hooks/user_prompt_submit.py
[File contents loaded into context]
10:15 - User edits file in VS Code
[Makes changes, saves]
10:20 - You: Edit hooks/user_prompt_submit.py
PreToolUse Hook: ⚠️ File State Change Detected
File: hooks/user_prompt_submit.py
Status: MODIFIED
Recommendation: Re-read before editing
You: "I see the file was modified externally. Let me re-read it first."
[Read hooks/user_prompt_submit.py]
[Now have current state]
[Proceed with Edit]
Token saved: Prevented edit conflict + re-work
Session 1 ends:
SessionEnd: Records metadata to .contextune/last_session.yaml
- session_id, timestamp, last_commit, branch, files_worked_on
[User works outside Claude]
- Commits via terminal: git commit -m "quick fix"
- Edits 3 files manually
- Switches to develop branch
Session 2 starts:
SessionStart: Loads .contextune/last_session.yaml
→ git log <last_commit>..HEAD
→ git diff --stat <last_commit>..HEAD
→ Generates summary
Claude sees:
📋 Git Context Since Last Session (3 hours ago)
**Git Activity:**
- 1 new commit: "quick fix"
- 3 files changed
- Branch: master → develop (switched)
**Current Status:** Clean ✅
Claude: "I see you made a commit and switched to develop branch.
The 3 files that changed are now in my context. Ready to continue!"
Token cost: ~1.5K (vs 50K+ full reload)
decisions.yaml - YAML database with 3 types of entries:
research:
entries:
- id: "res-001-authentication-libraries"
topic: "Authentication libraries for Node.js"
findings: "Compared Passport.js, Auth0, NextAuth..."
recommendation: "Use NextAuth for React apps"
created_at: "2025-10-28"
expires_at: "2026-04-28" # 6 months
tags: [authentication, libraries, nodejs]
plans:
entries:
- id: "plan-001-jwt-implementation"
title: "JWT Authentication Implementation"
summary: "5 tasks: AuthService, middleware, tokens..."
status: "completed"
created_at: "2025-10-28"
tags: [authentication, implementation]
decisions:
entries:
- id: "dec-001-dry-strategy"
title: "Unified DRY Strategy"
status: "accepted"
context: "CHANGELOG grows unbounded..."
alternatives_considered: [...]
decision: "Use scripts for git workflows"
consequences: {positive: [...], negative: [...]}
tags: [architecture, cost-optimization]
Query existing context:
# Check if we already researched a topic
uv run scripts/decision-query.py --topic "authentication" --type research
# Check for existing decisions
uv run scripts/decision-query.py --topic "DRY" --type decisions
# Check for active plans
uv run scripts/decision-query.py --type plans --status active
# Query by tags
uv run scripts/decision-query.py --tags architecture cost-optimization
Output format:
# Filtered entries matching your query
# Load only relevant context (2-5K tokens vs 150K full CHANGELOG)
ALWAYS query first:
# Check if we already researched this topic
uv run scripts/decision-query.py --topic "{research_topic}" --type research
If found:
If NOT found:
Savings:
ALWAYS query first:
# Check for existing decisions on this topic
uv run scripts/decision-query.py --topic "{decision_topic}" --type decisions
If found:
If NOT found:
Savings:
ALWAYS query first:
# Check for existing plans on this topic
uv run scripts/decision-query.py --topic "{feature_name}" --type plans
If found:
If NOT found:
decision-sync.py scans conversation history and auto-populates decisions.yaml:
# Scan all conversations for decisions (run once)
uv run scripts/decision-sync.py
# Result: Populates decisions.yaml with historical context
How it works:
~/.claude/projects/*/conversation/ for transcriptsAlready populated: Check current state:
# See what's already in decisions.yaml
uv run scripts/decision-query.py --all
Old approach (CHANGELOG.md):
Import entire CHANGELOG: 150K tokens
Problem: Loads everything, most irrelevant
Cost: High context usage
New approach (decisions.yaml with queries):
Query specific topic: 2-5K tokens (83-97% reduction!)
Example: decision-query.py --topic "authentication"
Loads: Only relevant 2-3 entries
Scenario 1: Starting authentication work
# Query for authentication context
uv run scripts/decision-query.py --topic "authentication"
# Loads:
- Research: Authentication libraries (if exists)
- Decisions: Auth approach decisions (if exists)
- Plans: Auth implementation plans (if exists)
# Total: ~3K tokens vs 150K full CHANGELOG
Scenario 2: User asks "why did we choose X?"
# Query for specific decision
uv run scripts/decision-query.py --topic "DRY strategy"
# Loads: Single decision with full context
# Total: ~1K tokens
session_end_extractor.py already extracts to decisions.yaml:
You don't need to do anything - it happens automatically at session end!
During conversation:
User: "Research best state management libraries for React"
You: Let me check if we already researched this.
[Run decision-query.py --topic "state management" --type research]
Result: Found existing research from 2 months ago
- Compared: Redux, Zustand, Jotai, Valtio
- Recommendation: Zustand for simple apps, Jotai for complex
- Tags: [react, state-management, libraries]
You: We already researched this! Here's what we found:
[Load 2K tokens vs spending $0.07 to research again]
User: "Should we use microservices or monolith?"
You: Let me check if we already decided on architecture approach.
[Run decision-query.py --topic "architecture" --type decisions]
Result: Found decision "dec-002-monolith-first"
- Decision: Start with modular monolith
- Rationale: Team size <5, single deployment simpler
- Status: accepted
- Date: 2025-09-15
You: We already decided this! Here's the context:
[Load 1K tokens vs re-discussing for 30 minutes]
User: "Plan implementation for user dashboard"
You: Let me check for existing plans.
[Run decision-query.py --topic "dashboard" --type plans]
Result: Found plan "plan-005-dashboard-v1"
- Status: completed
- Summary: "5 tasks implemented, merged to main"
- Created: 2025-10-01
You: We already implemented this! Let me load the existing plan.
[Load 3K tokens, reference existing work]
Research entries expire after 6 months:
Plans archive 90 days after completion:
Decisions never auto-expire:
Check lifecycle status:
# See active vs expired entries
uv run scripts/decision-query.py --show-expired
Annual savings (assuming 50 research sessions):
Old: 50 × $0.07 = $3.50 in redundant research
New: Query first (free), research only if needed
Savings: ~$3.00/year + avoid 25 hours of redundant work
Token savings per query:
Load full CHANGELOG: 150K tokens
Load specific query: 2-5K tokens
Savings: 97% reduction per lookup
Check before researching:
uv run scripts/decision-query.py --topic "{topic}" --type research
Check before deciding:
uv run scripts/decision-query.py --topic "{topic}" --type decisions
Check before planning:
uv run scripts/decision-query.py --topic "{topic}" --type plans
See all active context:
uv run scripts/decision-query.py --all
Key principle: Query before doing work that might already be done.
Benefits:
Remember: decisions.yaml is plugin-local, works for all users who install Contextune!
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.