[Feature Request] Pre- and Post callbacks
Resolved 💬 4 comments Opened Mar 23, 2025 by rogerheykoop Closed Jan 7, 2026
Feature Request: Pre & Post Invocation Callbacks for Claude Code
Problem Statement
Currently, Claude Code lacks the ability to consistently execute pre-defined actions before and after invocation. While some of this functionality can be implemented through rules, a more reliable and systematic approach is needed to ensure these operations occur consistently during the workflow.
Proposed Solution
Add support for configurable pre-invocation and post-invocation callbacks in Claude Code. These callbacks would execute designated scripts or commands at specific stages of the Claude Code execution lifecycle, for instance when Claude Code has changed files.
Use Cases
- Pre-invocation callbacks:
- Clear log files before starting a new task
- Check current code version into git before modifications
- Set up test environments or dependencies
- Create backup snapshots
- Post-invocation callbacks:
- Validate generated code against quality standards
- Run automated tests on the changes
- Generate documentation based on changes
- Notify team members of completed tasks
- Commit changes to version control
Technical Details
The callbacks should:
- Be configurable in the Claude Code configuration file
- Support both simple shell commands and more complex scripts
- Provide execution status feedback
- Allow for conditional execution
- Pass context information between Claude Code and the callbacks
- Optionally allow Claude to interpret the output of post-invocation callbacks
Example Configuration
callbacks:
pre_invocation:
- name: "Clear logs"
command: "./scripts/clear_logs.sh"
fail_behavior: "warn" # Options: abort, warn, ignore
- name: "Git snapshot"
command: "git add . && git commit -m 'Auto-snapshot before Claude Code task'"
working_directory: "$PROJECT_ROOT"
post_invocation:
- name: "Run tests"
command: "./scripts/run_tests.sh"
report_to_claude: true # Send output back to Claude for interpretation
- name: "Validate code"
command: "./scripts/validate.js"
if: "exit_code == 0" # Only run if Claude Code task succeeded
Benefits
- Enhanced workflow reliability - callbacks will "absolutely always be called"
- Better integration with existing development tools and processes
- Improved quality control through automated validation
- Streamlined developer experience with less manual intervention
Alternatives Considered
- Rule-based approaches (less reliable as mentioned in request)
- Event-driven architecture (more complex, overkill for this use case)
- Manual execution of scripts (defeats purpose of automation)
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗