Install command
Provided
Automatically sorts and optimizes Python imports using isort when Python files are modified.
Open the source and read safety notes before installing.
Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.
Decision playbook
Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.
0
78
—
No baseline selected
No major trust-signal divergence detected in the current selection.
Confirm ownership and provenance before trusting install instructions.
Source link availableRequired
Open the canonical repository and verify ownership.
Source provenance statusRequired
Marked as source-backed.
Metadata reviewed
Registry metadata indicates a reviewed listing.
Validate risk disclosures before installation or API wiring.
Safety notes presentRequired
Review the listed safety guidance before running commands.
Privacy notes presentRequired
Review data handling notes before connecting accounts or secrets.
Trust level risk gateRequired
Trust level does not block evaluation.
Check package metadata and artifact integrity signals.
Install payload available
Install or copy payload is available for review.
Package verification flag
No package verification flag provided.
Checksum metadata
No checksum provided for downloaded artifact.
Use compare context to validate trade-offs before adoption.
Compare tray has multiple entries
Add at least one more entry to compare trust differences.
Baseline comparison available
No baseline peer selected yet.
Diverging trust signals identified
No major trust-signal divergence found.
Setup at a glance
Copy-ready — paste the snippet to get started.
Install command
Provided
Config snippet
Provided
Copy snippet
Provided
Prerequisites
None
Platforms
1 listed
Difficulty
0/100
Adoption plan
Current risk score 16/100. Use staged verification before broader rollout.
Validate source and review signals before any execution.
Confirm source provenanceRequired
Source URL/provenance metadata is present.
Confirm metadata review state
Listing has review metadata.
Verify install payload
Install/config payload exists and can be inspected.
Confirm safety, privacy, and package integrity signals.
Review safety notesRequired
Safety notes are present.
Review privacy notesRequired
Privacy notes are present.
Verify package integrity metadata
No package verification/checksum metadata.
Adopt in controlled steps based on the selected plan.
Run in isolated sandbox firstRequired
Use a constrained sandbox and observe behavior across multiple tasks.
Roll out graduallyRequired
Roll out to a small cohort before wider usage.
Set monitoring and fallback
Define rollback path and monitor errors after adoption.
Evidence readiness
Required evidence gates are covered (5/6 signals complete).
Source repository/provenance is listed.
Required in this preset
Review metadata is present.
Required in this preset
Safety notes are present.
Required in this preset
Privacy notes are present.
Optional in this preset
Package integrity metadata is missing.
Optional in this preset
Install payload is available.
Required in this preset
Required evidence gates are covered for this preset.
Decision timeline
5/6 steps complete with no blocking gaps for this preset.
triage
Source/provenance metadata is available.
triage
Review metadata is available.
verify
Safety notes are available.
verify
Privacy notes are available.
verify
Package integrity metadata is missing.
rollout
Install payload is available.
No required blockers for this timeline preset.
Safety & privacy surface
1 safety and 1 privacy notes across 2 risk areas. Review closely: credentials & tokens, permissions & scopes.
#!/bin/bash
# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [ -z "$FILE_PATH" ]; then
exit 0
fi
# Check if this is a Python file
if [[ "$FILE_PATH" == *.py ]]; then
echo "🐍 Python Import Optimizer - Processing Python file..."
echo "📄 File: $FILE_PATH"
# Check if file exists
if [ ! -f "$FILE_PATH" ]; then
echo "⚠️ File not found: $FILE_PATH"
exit 1
fi
# Step 1: Sort imports with isort
echo "📋 Sorting imports with isort..."
if command -v isort >/dev/null 2>&1; then
if isort "$FILE_PATH" --profile black --line-length 88 --check-only --diff; then
echo "✅ Imports are already sorted"
else
echo "🔄 Sorting imports..."
isort "$FILE_PATH" --profile black --line-length 88
echo "✅ Imports sorted successfully"
fi
else
echo "⚠️ isort not found. Install with: pip install isort"
fi
# Step 2: Remove unused imports with autoflake (optional)
echo "🧹 Removing unused imports..."
if command -v autoflake >/dev/null 2>&1; then
# Check for unused imports first
if autoflake --check "$FILE_PATH" --remove-unused-variables --remove-all-unused-imports; then
echo "✅ No unused imports found"
else
echo "🔄 Removing unused imports..."
autoflake --in-place "$FILE_PATH" --remove-unused-variables --remove-all-unused-imports
echo "✅ Unused imports removed"
fi
else
echo "ℹ️ autoflake not found (optional). Install with: pip install autoflake"
fi
# Step 3: Additional import analysis
echo "🔍 Analyzing import structure..."
# Count different types of imports
STDLIB_IMPORTS=$(grep -c "^import \(os\|sys\|re\|json\|datetime\|collections\|itertools\|functools\|pathlib\)" "$FILE_PATH" 2>/dev/null || echo 0)
THIRD_PARTY_IMPORTS=$(grep -c "^\(import\|from\) \(numpy\|pandas\|requests\|flask\|django\|fastapi\)" "$FILE_PATH" 2>/dev/null || echo 0)
RELATIVE_IMPORTS=$(grep -c "^from \.[.]*" "$FILE_PATH" 2>/dev/null || echo 0)
echo "📊 Import Summary:"
echo " • Standard Library: $STDLIB_IMPORTS"
echo " • Third Party: $THIRD_PARTY_IMPORTS"
echo " • Relative: $RELATIVE_IMPORTS"
# Check for potential issues
if grep -q "^import \*" "$FILE_PATH" 2>/dev/null; then
echo "⚠️ Warning: Star imports detected (import *) - consider specific imports"
fi
if [ "$(grep -c '^import\|^from' "$FILE_PATH" 2>/dev/null || echo 0)" -gt 20 ]; then
echo "💡 Tip: Consider grouping related imports or using a package structure"
fi
echo ""
echo "💡 Python Import Tips:"
echo " • Use absolute imports when possible"
echo " • Group imports: stdlib, third-party, local"
echo " • Avoid star imports (import *)"
echo " • Use 'from module import specific_function' for clarity"
echo ""
echo "🎯 Python import optimization complete!"
else
echo "ℹ️ File is not a Python file: $FILE_PATH"
fi
exit 0{
"hooks": {
"postToolUse": {
"script": "./.claude/hooks/python-import-optimizer.sh",
"matchers": [
"write",
"edit"
]
}
}
}.claude/settings.local.json~/.claude/settings.json.claude/settings.json{
"hooks": {
"postToolUse": {
"script": "./.claude/hooks/python-import-optimizer.sh",
"matchers": ["write", "edit"]
}
}
}
#!/bin/bash
# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [ -z "$FILE_PATH" ]; then
exit 0
fi
# Check if this is a Python file
if [[ "$FILE_PATH" == *.py ]]; then
echo "🐍 Python Import Optimizer - Processing Python file..."
echo "📄 File: $FILE_PATH"
# Check if file exists
if [ ! -f "$FILE_PATH" ]; then
echo "⚠️ File not found: $FILE_PATH"
exit 1
fi
# Step 1: Sort imports with isort
echo "📋 Sorting imports with isort..."
if command -v isort >/dev/null 2>&1; then
if isort "$FILE_PATH" --profile black --line-length 88 --check-only --diff; then
echo "✅ Imports are already sorted"
else
echo "🔄 Sorting imports..."
isort "$FILE_PATH" --profile black --line-length 88
echo "✅ Imports sorted successfully"
fi
else
echo "⚠️ isort not found. Install with: pip install isort"
fi
# Step 2: Remove unused imports with autoflake (optional)
echo "🧹 Removing unused imports..."
if command -v autoflake >/dev/null 2>&1; then
# Check for unused imports first
if autoflake --check "$FILE_PATH" --remove-unused-variables --remove-all-unused-imports; then
echo "✅ No unused imports found"
else
echo "🔄 Removing unused imports..."
autoflake --in-place "$FILE_PATH" --remove-unused-variables --remove-all-unused-imports
echo "✅ Unused imports removed"
fi
else
echo "ℹ️ autoflake not found (optional). Install with: pip install autoflake"
fi
# Step 3: Additional import analysis
echo "🔍 Analyzing import structure..."
# Count different types of imports
STDLIB_IMPORTS=$(grep -c "^import \(os\|sys\|re\|json\|datetime\|collections\|itertools\|functools\|pathlib\)" "$FILE_PATH" 2>/dev/null || echo 0)
THIRD_PARTY_IMPORTS=$(grep -c "^\(import\|from\) \(numpy\|pandas\|requests\|flask\|django\|fastapi\)" "$FILE_PATH" 2>/dev/null || echo 0)
RELATIVE_IMPORTS=$(grep -c "^from \.[.]*" "$FILE_PATH" 2>/dev/null || echo 0)
echo "📊 Import Summary:"
echo " • Standard Library: $STDLIB_IMPORTS"
echo " • Third Party: $THIRD_PARTY_IMPORTS"
echo " • Relative: $RELATIVE_IMPORTS"
# Check for potential issues
if grep -q "^import \*" "$FILE_PATH" 2>/dev/null; then
echo "⚠️ Warning: Star imports detected (import *) - consider specific imports"
fi
if [ "$(grep -c '^import\|^from' "$FILE_PATH" 2>/dev/null || echo 0)" -gt 20 ]; then
echo "💡 Tip: Consider grouping related imports or using a package structure"
fi
echo ""
echo "💡 Python Import Tips:"
echo " • Use absolute imports when possible"
echo " • Group imports: stdlib, third-party, local"
echo " • Avoid star imports (import *)"
echo " • Use 'from module import specific_function' for clarity"
echo ""
echo "🎯 Python import optimization complete!"
else
echo "ℹ️ File is not a Python file: $FILE_PATH"
fi
exit 0
Complete hook script that performs Python import optimization
#!/bin/bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [ -z "$FILE_PATH" ]; then
exit 0
fi
if [[ "$FILE_PATH" == *.py ]]; then
echo "🐍 Python Import Optimizer - Processing Python file..."
if command -v isort >/dev/null 2>&1; then
echo "📋 Sorting imports with isort..."
isort "$FILE_PATH" --profile black --line-length 88
echo "✅ Imports sorted successfully"
else
echo "⚠️ isort not found. Install with: pip install isort"
fi
fi
exit 0
Complete hook configuration for .claude/settings.json to enable Python import optimization
{
"hooks": {
"postToolUse": {
"script": "./.claude/hooks/python-import-optimizer.sh",
"matchers": ["write", "edit"]
}
}
}
Enhanced hook script with isort sorting and autoflake unused import removal
#!/bin/bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *.py ]]; then
if command -v isort >/dev/null 2>&1; then
echo "📋 Sorting imports with isort..."
if isort "$FILE_PATH" --profile black --line-length 88 --check-only --diff; then
echo "✅ Imports are already sorted"
else
echo "🔄 Sorting imports..."
isort "$FILE_PATH" --profile black --line-length 88
echo "✅ Imports sorted successfully"
fi
fi
if command -v autoflake >/dev/null 2>&1; then
echo "🧹 Removing unused imports..."
if autoflake --check "$FILE_PATH" --remove-unused-variables --remove-all-unused-imports; then
echo "✅ No unused imports found"
else
echo "🔄 Removing unused imports..."
autoflake --in-place "$FILE_PATH" --remove-unused-variables --remove-all-unused-imports
echo "✅ Unused imports removed"
fi
fi
fi
exit 0
Enhanced hook script with import analysis and statistics reporting
#!/bin/bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *.py ]]; then
if command -v isort >/dev/null 2>&1; then
echo "📋 Sorting imports with isort..."
isort "$FILE_PATH" --profile black --line-length 88
echo "🔍 Analyzing import structure..."
STDLIB_IMPORTS=$(grep -c "^import \(os\|sys\|re\|json\|datetime\|collections\|itertools\|functools\|pathlib\)" "$FILE_PATH" 2>/dev/null || echo 0)
THIRD_PARTY_IMPORTS=$(grep -c "^\(import\|from\) \(numpy\|pandas\|requests\|flask\|django\|fastapi\)" "$FILE_PATH" 2>/dev/null || echo 0)
RELATIVE_IMPORTS=$(grep -c "^from \\." "$FILE_PATH" 2>/dev/null || echo 0)
echo "📊 Import Summary:"
echo " • Standard Library: $STDLIB_IMPORTS"
echo " • Third Party: $THIRD_PARTY_IMPORTS"
echo " • Relative: $RELATIVE_IMPORTS"
if grep -q "^import \\*" "$FILE_PATH" 2>/dev/null; then
echo "⚠️ Warning: Star imports detected (import *) - consider specific imports"
fi
fi
fi
exit 0
Example pyproject.toml configuration for isort and Black integration
[tool.isort]
profile = "black"
line_length = 88
known_first_party = ["myproject"]
skip_glob = ["*/migrations/*", "*/__pycache__/*"]
[tool.black]
line-length = 88
target-version = ["py312"]
include = '\.pyi?$'
Hook already uses --profile black flag for compatibility. Ensure Black and isort versions are current. Add .isort.cfg with profile = black and line_length = 88 for project-wide consistency. Verify pyproject.toml configuration. Test with various Black versions.
Add # noqa comments to imports that should be preserved. Configure autoflake to exclude specific files with --exclude in hook script, or use all exports to signal intentional module-level imports. Verify import usage. Test with various autoflake configurations.
Exclude init.py from autoflake processing by modifying hook to check filename. Add special handling for package files where import * is intentional for re-exporting. Verify package structure. Test with various package configurations.
Configure isort with known_first_party setting in setup.cfg or pyproject.toml. Use --src-path flag in hook to help isort determine project root for proper import classification. Verify project structure. Test with various project configurations.
Install isort with 'pip install isort' or 'pip install isort[black]' for Black profile support. Verify isort installation with 'isort --version'. Check Python environment and PATH. Test with various Python environments.
Review isort configuration and ensure --profile black is used for Black compatibility. Check for import side effects and verify import order doesn't affect functionality. Test with various import configurations.
Configure autoflake to preserve type hints with --remove-unused-variables but keep type annotations. Use --in-place flag carefully and review changes. Verify type hint preservation. Test with various type hint configurations.
Optimize hook script with timeout protection and file size checks. Consider excluding large files or using incremental processing. Verify file size limits. Test with various file sizes.
Python Import Optimizer - Hooks side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.
Next steps differ across entries — use the actions in the table below to copy install commands and source links per resource.
| Field | Automatically sorts and optimizes Python imports using isort when Python files are modified. Open dossier | Detects unused CSS selectors when stylesheets are modified to keep CSS lean using PurgeCSS, PostCSS, and content analysis. This hook runs on CSS/SCSS file write/edit operations and analyzes stylesheets to identify unused selectors, generate optimized output, and report before/after size metrics. Open dossier | A PostToolUse hook that reminds you to enable native query logging for PostgreSQL, Prisma, Sequelize, and TypeORM, and flags possible N+1 patterns when you edit SQL or data-access files. Open dossier | A Claude Code SessionEnd hook that scans a project for dead code and writes a report to .claude/reports. It runs available tools per language: ESLint and Knip for JS/TS, autoflake or pylint for Python, Knip for unused npm dependencies, ripgrep for unreferenced src files, and jq to flag zero-coverage files. Open dossier |
|---|---|---|---|---|
| Next stepsDiffers | ||||
| Trust | ||||
| Review status | ReviewedMaintainer reviewed | ReviewedMaintainer reviewed | ReviewedMaintainer reviewed | ReviewedMaintainer reviewed |
| Package trust | Package not verified | Package not verified | Package not verified | Package not verified |
| Source provenance | Source-backed | Source-backed | Source-backed | Source-backed |
| Submitter | — | — | — | — |
| Install risk | Review first | Review first | Review first | Review first |
| Notes | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ |
| Brand | — | — | — | — |
| Category | hooks | hooks | hooks | hooks |
| Source | source-backed | source-backed | source-backed | source-backed |
| Author | JSONbored | JSONbored | JSONbored | JSONbored |
| Added | 2025-09-19 | 2025-09-19 | 2025-10-19 | 2025-10-19 |
| Platforms | Claude Code | Claude Code | Claude Code | Claude Code |
| Source repo | — | — | — | — |
| Safety notes | ✓Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling. | ✓Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling. | ✓Runs automatically after bash, write, or edit activity and inspects files that look like query, model, repository, DAO, or SQL files. Creates .claude/logs/query-performance.log and appends database command or file-analysis events. Uses grep-based heuristics for query warnings and should not be treated as proof of a performance defect. | ✓Registered as a SessionEnd hook, so it runs automatically every time a Claude Code session ends. Invokes external tools via npx (ts-prune, Knip, eslint) and locally installed binaries (autoflake, pylint, vulture, jq, rg), which can trigger package downloads and execute project tooling. Defaults to DRY_RUN=true and only writes a report; setting DRY_RUN=false is intended to enable destructive cleanup, so review the report before changing it. Creates directories under .claude/backups and .claude/reports in the working tree. |
| Privacy notes | ✓Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output. | ✓Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output. | ✓Reads query-related source files and may print file paths, query patterns, and database command strings to local hook output. Stores analyzed file paths and database command text in .claude/logs/query-performance.log. Database command text may include connection names, database names, or other operational details if typed directly into the command. | ✓Writes a dead-code report containing file paths, export names, and dependency names from the project to .claude/reports/dead-code-report.txt and echoes it to stderr. Running tools via npx may fetch packages from the npm registry over the network. |
| Prerequisites | — none listed | — none listed | — none listed | — none listed |
| Install | | | — | |
| Config | | | | |
| Citations | ||||
| Claim | Unclaimed | Unclaimed | Unclaimed | Unclaimed |
Source-backed guides for putting this to work.
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.