layer-design
π―Skillfrom front-depiction/claude-setup
layer-design skill from front-depiction/claude-setup
Installation
npx skills add https://github.com/front-depiction/claude-setup --skill layer-designSkill Details
Overview
# .claude
Pattern-based suggestions and guardrails for Claude Code tool usage via PreToolUse/PostToolUse hooks.
Overview
The pattern-detector system hooks into Claude Code's PreToolUse and PostToolUse events to provide:
- Context-aware suggestions when patterns are detected in tool inputs
- Permission controls (ask/deny) for dangerous operations
- Automatic skill recommendations based on code patterns
Patterns
Patterns are markdown files in .claude/patterns/ with YAML frontmatter that match against tool inputs:
```markdown
---
name: prefer-option-over-null
description: Suggest Option type instead of null/undefined
event: PostToolUse
tool: Edit|Write
glob: "*/.ts"
pattern: "\bnull\b|\bundefined\b"
action: context
level: info
tag: code-smell
---
Use Option from Effect instead of null or undefined:
```typescript
// Avoid
const findUser = (id: string): User | null => ...
// Prefer
const findUser = (id: string): Option.Option
```
```
Pattern Schema
Frontmatter fields (from patterns/schema.ts):
name: Unique identifier for the patterndescription: Human-readable descriptionevent: "PreToolUse" | "PostToolUse" (default: PostToolUse)tool: Regex matching tool names (default: ".*")glob: Optional glob pattern for file paths (e.g., "*/.ts")pattern: Regex matching tool input content (command, new_string, content, etc.)action: "context" | "ask" | "deny" (default: context)level: "critical" | "high" | "medium" | "warning" | "info" (default: info)tag: Optional XML tag for context blocks (default: "pattern-suggestion")
Actions
context: Add suggestion to PostToolUse responseask: Prompt user for permission (PreToolUse only)deny: Block the operation with reason (PreToolUse only)
Content Matching
The pattern detector searches these fields in order:
command(Bash)new_string(Edit)content(Write)pattern(Grep)query(WebSearch)url(WebFetch)prompt(WebFetch)
Falls back to JSON.stringify(tool_input) if none match.
Testing
test/TestClaude.ts provides tool shape constructors for testing patterns:
```typescript
import * as TestClaude from "./.claude/test/TestClaude"
import { runPatternDetector } from "./.claude/hooks/pattern-detector"
// Create pre/post hook inputs
const bashHook = TestClaude.Bash({ command: "rm -rf /" })
const editHook = TestClaude.Edit({
file_path: "/foo.ts",
old_string: "old",
new_string: "null"
})
// Test against patterns
const output = await runPatternDetector(bashHook.pre)
// or
const output = await runPatternDetector(editHook.post)
```
Each tool constructor returns { pre, post } shapes with correct tool_name and hook_event_name.
Files
hooks/pattern-detector.ts: Main hook implementation (PreToolUse/PostToolUse)patterns/schema.ts: Pattern frontmatter Schema definitionspatterns/TEMPLATE.md: Template for new patternspatterns/dangerous-commands/: PreToolUse ask/deny patternspatterns/code-smells/: PostToolUse context suggestionstest/TestClaude.ts: Tool shape constructors for testingCLAUDE.md: Project guidelines referencing pattern system
More from this repository10
pattern-matching skill from front-depiction/claude-setup
effect-ai-streaming skill from front-depiction/claude-setup
domain-modeling skill from front-depiction/claude-setup
legal-review skill from front-depiction/claude-setup
domain-predicates skill from front-depiction/claude-setup
effect-ai-prompt skill from front-depiction/claude-setup
Provides pattern-based recommendations and best practices for React component composition, guiding developers towards more modular and reusable component design.
Explores and analyzes code patterns in parallel across multiple files or directories, providing context-aware suggestions and potential optimizations based on detected patterns.
wide-events skill from front-depiction/claude-setup
Provides pattern-based suggestions and guardrails for using Effect's functional programming language model constructs in TypeScript code, focusing on improving type safety and reducing null/undefin...