Skip to content

Commit 416698d

Browse files
committed
Add an astral-dev plugin
1 parent 513f2c7 commit 416698d

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

.claude-plugin/marketplace.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
"name": "astral",
1010
"source": "./plugins/astral",
1111
"description": "Skills for working with Python using Astral tools."
12+
},
13+
{
14+
"name": "astral-dev",
15+
"source": "./plugins/astral-dev",
16+
"description": "Plugin for development of Astral tools (uv, ruff, ty)."
1217
}
1318
]
1419
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = []
4+
# ///
5+
6+
"""Post-edit hook to auto-format files after Claude edits."""
7+
8+
import json
9+
import subprocess
10+
import sys
11+
from pathlib import Path
12+
13+
14+
def format_rust(file_path: str, cwd: str) -> None:
15+
"""Format Rust files with cargo fmt."""
16+
try:
17+
subprocess.run(
18+
["cargo", "fmt", "--", file_path],
19+
cwd=cwd,
20+
capture_output=True,
21+
)
22+
except FileNotFoundError:
23+
pass
24+
25+
26+
def format_python(file_path: str, cwd: str) -> None:
27+
"""Format Python files with ruff."""
28+
try:
29+
subprocess.run(
30+
["uvx", "ruff", "format", file_path],
31+
cwd=cwd,
32+
capture_output=True,
33+
)
34+
except FileNotFoundError:
35+
pass
36+
37+
38+
def format_prettier(file_path: str, cwd: str) -> None:
39+
"""Format files with prettier."""
40+
try:
41+
subprocess.run(
42+
["npx", "prettier", "--write", file_path], cwd=cwd, capture_output=True
43+
)
44+
except FileNotFoundError:
45+
pass
46+
47+
48+
def main() -> None:
49+
import os
50+
51+
input_data = json.load(sys.stdin)
52+
53+
tool_name = input_data.get("tool_name")
54+
tool_input = input_data.get("tool_input", {})
55+
file_path = tool_input.get("file_path")
56+
57+
# Only process Write, Edit, and MultiEdit tools
58+
if tool_name not in ("Write", "Edit", "MultiEdit"):
59+
return
60+
61+
if not file_path:
62+
return
63+
64+
cwd = os.environ.get("CLAUDE_PROJECT_DIR", os.getcwd())
65+
path = Path(file_path)
66+
ext = path.suffix
67+
68+
if ext == ".rs":
69+
format_rust(file_path, cwd)
70+
elif ext in (".py", ".pyi"):
71+
format_python(file_path, cwd)
72+
elif ext in (".json5", ".yaml", ".yml", ".md"):
73+
format_prettier(file_path, cwd)
74+
75+
76+
if __name__ == "__main__":
77+
main()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "astral-dev",
3+
"description": "Plugin for development of Astral tools (uv, ruff, ty). Provides auto-formatting hooks for Rust, Python, and other files.",
4+
"version": "0.1.0",
5+
"author": {
6+
"name": "Astral",
7+
"url": "https://astral.sh"
8+
},
9+
"homepage": "https://astral.sh",
10+
"repository": "https://github.com/astral-sh/claude-code-plugins",
11+
"license": "MIT",
12+
"keywords": [
13+
"astral",
14+
"development",
15+
"formatting",
16+
"rust",
17+
"python",
18+
"uv",
19+
"ruff",
20+
"ty"
21+
],
22+
"hooks": [
23+
{
24+
"type": "PostToolUse",
25+
"command": "python",
26+
"args": [".claude-plugin/hooks/post-edit-format.py"]
27+
}
28+
]
29+
}

0 commit comments

Comments
 (0)