get_commit_context
Retrieves staged git changes and runs secret scanning to provide context for generating commit messages. Must be called before writing any commit.
Instructions
REQUIRED FIRST STEP: Get git diff and file changes to analyze before writing a commit message.
IMPORTANT: You MUST call this tool FIRST before generating any commit message. Never write a commit message without first seeing the actual git diff from this tool.
This tool ONLY shows STAGED changes. We intentionally do not support unstaged changes to ensure users have explicit control over what gets committed and prevent accidental commits.
CRITICAL: If the diff is empty and there are no files:
STOP immediately - do NOT proceed with generating a commit message
Tell the user: "No staged changes found. Please stage the files you want to commit first using: git add "
DO NOT attempt to stage files automatically
Wait for the user to stage their changes
Returns file changes and diff output with TOKEN-BASED pagination (MCP limit: 25k tokens). Large diffs are automatically paginated to stay under the token limit.
ANALYZING THE RESPONSE - follow these steps in order:
SECRET SCAN (automated): Check secret_scan.status FIRST.
If "warnings_found": STOP and warn the user about each finding. Show the file, line number, type, and redacted preview for each finding. Recommend removing the secret before committing. Do NOT proceed to generate a commit message until the user acknowledges or explicitly chooses to proceed despite the warnings.
If "clean": proceed to step 2.
SECRET SCAN (your review): Even if the automated scan is clean, briefly review the diff yourself for anything the regex-based scanner might miss:
Hardcoded credentials or secrets in unusual formats
Internal URLs, IP addresses, or hostnames that shouldn't be committed
Sensitive configuration values (database hosts, internal endpoints)
Comments containing passwords or access instructions If you spot anything suspicious, warn the user before proceeding.
COMMIT MESSAGE: After confirming no secrets (or user acknowledgment), generate a commit message following:
50/72 rule: 50 char subject line, 72 char body lines
Conventional commits format: type(scope): description
DO NOT include AI signatures, attribution, or "Generated with" footers
Args: cursor: Pagination cursor for large diffs (optional, returned as next_cursor) max_diff_tokens: Maximum tokens per response (default: 20000, safe under 25k limit) repo_path: Path to git repository (optional, defaults to Claude's working directory)
Returns: JSON string with: - has_changes: boolean - True if there are any staged changes to commit - files: list of changed files with status - secret_scan: results of secret detection on added lines - diff: the diff chunk (paginated) - next_cursor: pagination cursor for next chunk (if any) - pagination_info: token counts and chunk info - commit_format_guide: formatting rules for commit messages
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cursor | No | ||
| repo_path | No | ||
| max_diff_tokens | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |