Specialized guidance for creating, modifying, and debugging cc-sessions hooks that enforce DAIC discipline, write-gating, and framework integrity
Type: WRITE-CAPABLE DAIC Modes: IMPLEMENT only Priority: High
This skill activates on:
sessions/hooks/**/*.jsFrom: skill-rules.json - cc-sessions-hooks configuration
Specialized guidance for creating, modifying, and debugging cc-sessions hooks. Hooks are the enforcement layer that ensures DAIC discipline, write-gating, and framework integrity.
When activated in IMPLEMENT mode with an active cc-sessions task:
Hook Types & Purposes
UserPromptSubmit Hook:
PreToolUse Hook:
PostToolUse Hook:
SessionStart Hook:
Hook Development Patterns
Basic Hook Structure:
// sessions/hooks/example_hook.js
module.exports = {
name: 'example_hook',
description: 'Brief description of what this hook does',
async execute(context) {
// Hook logic here
// Return { success: true } or { success: false, error: 'message' }
}
};
Enforcement Hook Pattern:
async execute(context) {
const { toolName, toolParams, sessionState } = context;
// Check conditions
if (shouldBlock(toolName, sessionState)) {
return {
success: false,
error: 'Tool blocked: [reason]',
additionalContext: '[guidance for user]'
};
}
return { success: true };
}
Write-Gating Enforcement
The sessions_enforce.js hook is CRITICAL for framework integrity:
What it enforces:
How to extend:
WRITE_TOOLS arraycheckWriteGating()Shared State Access
Hooks can read/modify shared state:
const state = require('../sessions-state.json');
const fs = require('fs');
// Read state
const currentMode = state.mode;
const activeTask = state.task;
// Modify state (carefully!)
state.flags.contextWarning85 = true;
fs.writeFileSync(
path.join(__dirname, '../sessions-state.json'),
JSON.stringify(state, null, 2)
);
Hook Execution Order
Understand execution flow:
Hooks execute synchronously within their phase.
CRITICAL WRITE-GATING RULES:
Hook-Specific Safety:
{ success: true/false } from execute()State Mutation Safety:
✓ "Add a hook to validate task manifest format" ✓ "Fix the sessions_enforce.js write-gating for MultiEdit tool" ✓ "Create a PostToolUse hook to log all file modifications" ✓ "Modify UserPromptSubmit to detect '/squish' command" ✓ "Debug why the IMPLEMENT mode transition isn't triggering"
✗ In DISCUSS/ALIGN/CHECK mode (hook development requires IMPLEMENT) ✗ No active cc-sessions task (violates write-gating) ✗ User wants to create non-hook cc-sessions code (use cc-sessions-core) ✗ Changes would weaken enforcement mechanisms
Before deploying a new or modified hook:
{ success, error? } structureif (invalidCondition) {
return {
success: false,
error: '[CATEGORY: Clear Error Message]',
additionalContext: 'What user should do instead'
};
}
if (warningCondition) {
console.warn('[Hook Warning]', message);
// Continue execution
}
return { success: true };
const state = loadState();
state.flags.someFlag = true;
saveState(state);
return { success: true };
if (context.toolName === 'Write' && context.sessionState.mode !== 'IMPLEMENT') {
return { success: false, error: 'Write only in IMPLEMENT mode' };
}
When creating or modifying hooks, log in context/decisions.md:
### Hook Change: [Date]
- **Hook:** sessions/hooks/sessions_enforce.js
- **Change:** Added MultiEdit to WRITE_TOOLS array
- **Rationale:** MultiEdit can write to multiple files, needs same gating as Write/Edit
- **Testing:** Verified blocks in DISCUSS, allows in IMPLEMENT
- **Risk:** Low (additive change, follows existing pattern)
Last Updated: 2025-11-15 Framework Version: 2.0