Skip to content

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Dec 13, 2025

Summary

This PR adds a Claude Code PostToolUse hook that automatically lints and typechecks files after Claude modifies them using the Write or Edit tools. This provides immediate feedback to Claude about any issues introduced by its changes.

Changes

  • .github/scripts/lint-and-typecheck-hook.ts: New TypeScript script that:

    • Runs ESLint on modified files (for .ts, .tsx, .js, .jsx, .mts, .cts, .mjs, .cjs files)
    • Runs TypeScript typecheck via the affected Nx project (for TypeScript files)
    • Parses stdin for hook input (tool_name, tool_input with file_path)
    • Returns exit code 2 with error details to stderr if issues found
    • Returns exit code 0 on success (no blocking)
  • .claude/settings.json: Configuration for the PostToolUse hook to trigger on Write|Edit tool usage

  • .github/scripts/tsconfig.json: TypeScript configuration for the scripts directory

  • eslint.config.js: Updated to support linting .github/scripts with a separate tsconfig

  • CLAUDE.md: Documented the hook with:

    • How it works
    • Configuration details
    • Benefits
    • Troubleshooting guide

How It Works

  1. When Claude uses the Write or Edit tool to modify a file, the PostToolUse hook is triggered
  2. The hook script runs:
    • ESLint on the modified file (for supported JS/TS extensions)
    • TypeScript typecheck via Nx for the affected project
  3. If issues are found, the hook exits with code 2 and provides error details to Claude
  4. Claude receives this feedback and can fix the issues before continuing

Testing

  • The hook can be tested manually:
    echo '{"tool_name":"Write","tool_input":{"file_path":"path/to/file.ts"}}' | \
      npx tsx .github/scripts/lint-and-typecheck-hook.ts
  • All lint and typecheck targets pass for affected projects
  • Markdown files pass linting

Linear Issue

Closes: https://linear.app/uniswap/issue/DEV-49/add-claude-code-hook-for-linting-and-typechecking-only-the-files-it

Autonomous implementation using claude-opus-4-5-20251101


✨ Claude-Generated Content

Summary

Adds a Claude Code PostToolUse hook that automatically lints and typechecks files after Claude modifies them using the Write or Edit tools, providing immediate feedback about any issues introduced by changes.

Changes

  • .github/scripts/lint-and-typecheck-hook.ts: New TypeScript script that:
    • Runs ESLint on modified files (.ts, .tsx, .js, .jsx, .mts, .cts, .mjs, .cjs)
    • Runs TypeScript typecheck via the affected Nx project
    • Parses stdin for hook input (tool_name, tool_input with file_path)
    • Returns exit code 2 with error details to stderr if issues found
    • Returns exit code 0 on success (non-blocking)
  • .claude/settings.json: Configuration for the PostToolUse hook to trigger on Write|Edit tool usage
  • .github/scripts/tsconfig.json: TypeScript configuration for the scripts directory
  • eslint.config.js: Updated to support linting .github/scripts with a separate tsconfig
  • tsconfig.json: Added .github/scripts as a project reference
  • CLAUDE.md: Documented the hook with usage, configuration, benefits, and troubleshooting guide

Technical Details

The workflow operates as follows:

  1. When Claude uses the Write or Edit tool to modify a file, the PostToolUse hook is triggered
  2. The hook script runs:
    • ESLint on the modified file (for supported JS/TS extensions)
    • TypeScript typecheck via Nx for the affected project
  3. If issues are found, the hook exits with code 2 and provides error details to Claude
  4. Claude receives this feedback and can fix the issues before continuing
    The hook can be tested manually:
echo '{"tool_name":"Write","tool_input":{"file_path":"path/to/file.ts"}}' | \
  npx tsx .github/scripts/lint-and-typecheck-hook.ts

Closes: https://linear.app/uniswap/issue/DEV-49

…cking

- Add lint-and-typecheck-hook.ts script that runs ESLint and TypeScript
  typecheck on files after Claude modifies them using Write or Edit tools
- Configure PostToolUse hook in .claude/settings.json to trigger on Write|Edit
- Add TypeScript configuration for .github/scripts directory
- Update eslint.config.js to support .github/scripts with separate tsconfig
- Document the hook in root CLAUDE.md with usage, configuration, and troubleshooting

The hook provides immediate feedback to Claude about lint errors and type
issues introduced by its changes, enabling faster iteration and cleaner code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@linear
Copy link

linear bot commented Dec 13, 2025

@vercel
Copy link

vercel bot commented Dec 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
ai-toolkit-slack-oauth-backend Ready Ready Preview, Comment Dec 13, 2025 10:14am

@github-actions
Copy link
Contributor

👋 Hi!

I'm Claude, an AI assistant here to help with code reviews and answer questions about your PR. You can tag me anytime with @claude followed by your request.

💡 Tip: Ask me to explain code, suggest improvements, review specific changes, or help with AI Toolkit development patterns.

This repository contains the AI Toolkit - standardized, one-shot setup for Claude Code AI workflows. When working on changes, make sure to follow the Nx monorepo patterns and update relevant CLAUDE.md files.

Learn how to use Claude in ai-toolkit PRs

@github-actions
Copy link
Contributor

github-actions bot commented Dec 13, 2025

🤖 Claude Code Review

Review complete

Summary

This PR adds a Claude Code PostToolUse hook that automatically lints and typechecks files after Claude modifies them using the Write or Edit tools. The implementation includes:

  1. A new TypeScript hook script at .github/scripts/lint-and-typecheck-hook.ts
  2. Claude settings configuration in .claude/settings.json
  3. ESLint configuration updates to handle .github/scripts with its own tsconfig
  4. TypeScript project references updated to include the new scripts directory
  5. Documentation in CLAUDE.md explaining the hook

Analysis

Code Quality

The hook script is well-structured with clear separation of concerns:

  • Types are properly defined
  • Functions are focused and single-purpose
  • Error handling is comprehensive with graceful degradation (exit 0 on unexpected errors)
  • Good documentation with JSDoc header

Configuration

The ESLint and TypeScript configurations are properly set up:

  • .github/scripts has its own tsconfig.json with appropriate settings
  • ESLint is configured to use the scripts-specific tsconfig for files in that directory
  • The main tsconfig.json references the scripts directory for project-wide builds

Potential Issue

There's a configuration inconsistency in .github/scripts/tsconfig.json:

{
  "composite": true,
  "noEmit": true
}

Having both composite: true and noEmit: true is contradictory. Composite projects are designed to emit .d.ts files and .tsbuildinfo for incremental builds. With noEmit: true, the composite behavior is effectively disabled, which may cause issues with TypeScript project references.

Since the script is executed via npx tsx (which handles transpilation on-the-fly), noEmit: true makes sense for this use case. However, having composite: true is then unnecessary and could be confusing.

Minor Observations

  1. The findProjectRoot function traverses up from the file path but stops at /, which works on Unix but could be improved for cross-platform support. Given this is a monorepo typically run on Linux/macOS CI, this is acceptable.

  2. The shebang #!/usr/bin/env npx tsx is non-standard but correct for tsx execution.

  3. The CLAUDE.md documentation addition is thorough and well-written.

Verdict

The implementation is solid and follows the project's conventions. The composite/noEmit inconsistency is a minor configuration oddity that doesn't affect functionality since tsx handles execution. The code is well-tested through error handling patterns and graceful degradation.


💡 Want a fresh review? Add a comment containing @request-claude-review to trigger a new review at any time.

@github-actions github-actions bot changed the title [DEV-49] Add Claude Code hook for linting and typechecking modified files feat(hooks): add Claude Code PostToolUse hook for linting and typechecking Dec 13, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only. 1 inline comment(s) are attached below.

"outDir": "../../dist/.github/scripts",
"rootDir": ".",
"types": ["node"],
"noEmit": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having both composite: true and noEmit: true is contradictory. Composite projects are designed to emit declaration files for project references, but noEmit prevents any output.

Since this script runs via npx tsx (no build step needed), consider either:

  1. Remove composite: true since you're not using project references features, OR
  2. Remove noEmit: true if you want proper integration with the monorepo's build system

This doesn't break anything currently since tsx handles transpilation, but the config is misleading.

Suggested change
"noEmit": true
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/.github/scripts",
"rootDir": ".",
"types": ["node"],
"noEmit": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules"]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant