Sentinel Console Guard
Battle-tested hook for warns, about, console, statements. Includes structured workflows, validation checks, and reusable patterns for pre tool.
Sentinel Console Guard
Intercepts and blocks console.log, console.debug, and other debugging statements from being committed to production code files.
When to Use This Hook
Attach this hook when you need to:
- Prevent debug logging statements from reaching production code in JavaScript/TypeScript projects
- Enforce a clean logging discipline where only structured logger calls are permitted
- Catch accidental console statements that Claude might introduce during development sessions
Consider alternatives when:
- Your project intentionally uses console methods for user-facing output (CLI tools, Node.js scripts)
- You have ESLint's
no-consolerule already enforced with auto-fix in your pipeline
Quick Start
Configuration
name: sentinel-console-guard type: hook trigger: PreToolUse category: pre-tool
Example Trigger
# Hook triggers before Claude writes code containing console statements claude> Edit src/services/paymentService.ts # Guard checks if the new content contains console.log or similar
Example Output
Sentinel Console Guard: Scanning edit content...
BLOCKED: console.log() detected on line 47
BLOCKED: console.debug() detected on line 83
Suggestion: Use logger.info() or logger.debug() instead
Edit blocked. Remove console statements and retry.
Core Concepts
Detection Scope Overview
| Aspect | Details |
|---|---|
| console.log | Blocked in all production source files |
| console.debug | Blocked, should use structured logger |
| console.warn | Optionally blocked (configurable) |
| console.error | Optionally allowed for error boundaries |
| console.trace | Blocked, reserved for development debugging only |
Guard Workflow
Edit Requested
|
Is JS/TS File?
/ \
No Yes
| |
Allow Scan Content
for console.*
|
┌────┴────┐
| |
Clean Detected
| |
Allow Check Allowlist
|
┌────┴────┐
| |
Allowed Blocked
| |
Allow Reject +
Suggest
Logger
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
blocked_methods | string[] | ["log","debug","trace"] | Console methods to block |
allowed_methods | string[] | ["error"] | Console methods to permit |
file_patterns | string[] | ["*.ts","*.js","*.tsx","*.jsx"] | File patterns to scan |
exclude_dirs | string[] | ["__tests__","scripts"] | Directories exempt from checking |
suggest_replacement | string | "logger" | Recommended alternative in error messages |
Best Practices
-
Allow console.error Selectively - Error boundaries and catch blocks legitimately use
console.error. Allow it by default but require a structured logger for informational and debug output. -
Exempt Test Files - Test files often use
console.logfor debugging andconsole.errorfor expected error testing. Exclude__tests__,*.test.ts, and*.spec.tsfrom the guard. -
Provide Clear Replacement Guidance - When the guard blocks a console statement, suggest the exact logger method to use (e.g.,
logger.info(),logger.debug()) so developers can fix the issue immediately. -
Scan Both Old and New Content - When checking edits, scan the new content being written rather than the existing file. This prevents blocking edits that are actually removing console statements.
-
Configure a Project Logger First - Before enabling this guard, ensure your project has a structured logging library configured. Blocking console without an alternative frustrates the development workflow.
Common Issues
-
False Positives in String Literals - Code containing the string
"console.log"in documentation or error messages triggers false positives. Use AST-level parsing or regex that excludes quoted strings. -
Blocking Intentional CLI Output - Node.js CLI tools and build scripts legitimately use console for output. Add these files to
exclude_dirsor use a file-level// sentinel-ignorecomment. -
Incomplete Pattern Matching - Simple regex may miss
console["log"]orconst {log} = consolepatterns. For thorough detection, consider using a JavaScript parser instead of string matching.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.