Feature: built-in syntax validation before script execution
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Claude Code frequently writes bash and python scripts, then asks the user for permission to execute them. Too often, the user approves and the script fails with a basic syntax error. This wastes the user's attention and erodes trust in the tool.
Proposed Solution
Integrate syntax validation as a built-in step in the Bash tool itself. Before executing a command, the tool should detect the language and run the appropriate checker:
| Language | Check |
|----------|-------|
| Bash/Shell | bash -n (and ideally shellcheck) |
| Python | python -c "import ast; ast.parse(open('file').read())" |
| Node/JS | node --check |
| PHP | php -l |
If the check fails, the error is returned to the model to fix before the user is ever prompted. The user should never have to approve a script that has a syntax error.
This belongs in the tool implementation, not in user configuration. Linting is a property of correct script execution, like quoting paths or handling exit codes. Every user benefits, with no setup required.
Not Duplicates
- #20701 (pre-execution hooks / tool restrictions): That issue is about user-defined hooks to block or redirect tool calls as a guardrail mechanism. This is about the tool itself validating its own output — no user configuration involved.
- #21537 (BeforeToolSelection hook): That issue is about filtering which tools the model sees before selection to avoid wasted inference. This is about the Bash tool catching syntax errors in scripts the model has already written.
Alternative Solutions
- CLAUDE.md instructions ("always lint before running"): The model skips this under task focus often enough that it can't be relied on.
- PreToolUse hooks: Users could write a hook, but linting should be a consistent part of the tool itself, not something each user independently configures. It's like expecting users to write a hook to check that files exist before reading them.
Priority
Medium - Significant quality-of-life improvement
Feature Category
Core product
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗