gsd-workflow-guard.js
PreToolUse hook that warns when file edits happen outside a GSD workflow or subagent.
- Kind
- Hook
- Works with
- Claude Code, Gemini / Antigravity
- Languages
- TypeScript / JavaScript
- Source
- gsd-build/get-shit-done @ bdcaab2c752d
- Path
- hooks/gsd-workflow-guard.js
- License
- MIT
- Jobs
- Guardrails
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
#!/usr/bin/env node
// gsd-hook-version: {{GSD_VERSION}}
// GSD Workflow Guard — PreToolUse hook
// Detects when Claude attempts file edits outside a GSD workflow context
// (no active /gsd- skill or Task subagent) and injects an advisory warning.
//
// This is a SOFT guard — it advises, not blocks. The edit still proceeds.
// The warning nudges Claude to use /gsd:quick or /gsd:fast instead of
// making direct edits that bypass state tracking.
//
// Enable via config: hooks.workflow_guard: true (default: false)
// Only triggers on Write/Edit tool calls to non-.planning/ files.
const fs = require('fs');
const path = require('path');
let input = '';
const stdinTimeout = setTimeout(() => process.exit(0), 3000);
process.stdin.setEncoding('utf8');
process.stdin.on('data', chunk => input += chunk);
process.stdin.on('end', () => {
clearTimeout(stdinTimeout);
try {
const data = JSON.parse(input);
const toolName = data.tool_name;
// Only guard Write and Edit tool calls
if (toolName !== 'Write' && toolName !== 'Edit') {
process.exit(0);
}
// Check if we're inside a GSD workflow (Task subagent or /gsd- skill)
…