dotCMS / dotCMS/core

chore(claude-code): add PostToolUse hook to enforce lint and prettier after file edits

Open
#35,425 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale Type : Test Automation
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Description

Add a Claude Code PostToolUse hook in .claude/settings.json (core-web) that automatically runs Prettier formatting and Nx lint checks every time Claude edits or writes a file. This ensures lint and style errors are caught and reported before Claude gives its final response — preventing back-and-forth correction cycles and keeping the codebase consistently formatted.

A companion Stop hook runs nx affected -t lint --fix on all modified files before Claude finishes a session, acting as a final safety net.

Why

When Claude edits multiple files in a session, lint or formatting violations can accumulate silently. Developers then discover errors only after reviewing Claude's output, requiring extra round-trips. Automating the check at the tool-use level shifts detection left and keeps code quality gates inside the AI-assisted workflow.

Current Implementation (core-web)

The following hooks are already configured in core-web/.claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "FILE=$(jq -r '.tool_input.file_path // empty'); [ -z \"$FILE\" ] || { yarn nx format:write --files=\"$FILE\" 2>/dev/null; LINT_OUT=$(yarn nx affected -t lint --files=\"$FILE\" 2>&1); LINT_EXIT=$?; if [ $LINT_EXIT -ne 0 ]; then jq -n --arg msg \"Lint errors in $FILE:\\n$LINT_OUT\" '{\"hookSpecificOutput\": {\"hookEventName\": \"PostToolUse\", \"additionalContext\": $msg}}'; fi; }"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "MODIFIED=$(git diff --name-only HEAD 2>/dev/null | grep -E '\\.(ts|html|scss|js)$'); [ -z \"$MODIFIED\" ] && exit 0; LINT_OUT=$(yarn nx affected -t lint --fix 2>&1); LINT_EXIT=$?; [ $LINT_EXIT -eq 0 ] && exit 0; jq -n --arg msg \"Lint errors that could not be auto-fixed. Please address before finishing:\\n$LINT_OUT\" '{\"continue\": false, \"stopReason\": $msg}'"
          }
        ]
      }
    ]
  }
}

PostToolUse (Edit | Write matcher):

  • Extracts the edited file path from the tool input
  • Runs yarn nx format:write --files=$FILE (Prettier)
  • Runs yarn nx affected -t lint --files=$FILE
  • If lint fails, injects the error output as additionalContext back into Claude's context so it can self-correct

Stop hook:

  • Collects all .ts|.html|.scss|.js files modified in the current session
  • Runs yarn nx affected -t lint --fix across them
  • If unfixable errors remain, blocks Claude from stopping and surfaces the details

Acceptance Criteria

  • PostToolUse hook is present in core-web/.claude/settings.json with matcher: "Edit|Write"
  • Hook runs yarn nx format:write --files=$FILE (Prettier) on every edited file
  • Hook runs yarn nx affected -t lint --files=$FILE on every edited file
  • Lint failures are fed back as additionalContext so Claude self-corrects before responding
  • Stop hook runs nx affected -t lint --fix on all session-modified files before Claude finishes
  • Stop hook blocks session completion when unfixable lint errors remain and surfaces the error output
  • Hook configuration is documented in core-web/CLAUDE.md under a Hooks section

Additional Context

  • Tooling: Nx monorepo, Yarn, Angular 19+
  • Affected files: .ts, .html, .scss, .js
  • Claude Code hooks docs: https://docs.anthropic.com/en/docs/claude-code/hooks
  • PostToolUse hookSpecificOutput.additionalContext injects text back into Claude's next prompt turn, enabling self-correction without user intervention

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with core-web/.claude/settings.json and core-web/CLAUDE.md, then consult the linked Claude Code hooks documentation and inspect the existing Nx commands. Verify the PostToolUse and Stop hooks against the listed acceptance criteria, including formatting, lint feedback, session-wide lint fixing, and documentation; the work is done when those behaviors are reproducible for the affected file types.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
documentation, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.