Skip to content

Commit 1f9ef66

Browse files
committed
feat: make into GitHub plugin
1 parent f838651 commit 1f9ef66

File tree

6 files changed

+156
-67
lines changed

6 files changed

+156
-67
lines changed

.claude-plugin/plugin.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "python-claude",
3+
"version": "0.3.2",
4+
"description": "Python hooks for Claude Code - automatically runs ruff, mypy, and pytest",
5+
"author": {
6+
"name": "CVector",
7+
"email": "support@cvector.com"
8+
},
9+
"license": "MIT",
10+
"keywords": ["python", "poetry", "ruff", "mypy", "pytest", "linting", "type-checking", "testing"],
11+
"hooks": "./hooks/hooks.json"
12+
}

README.md

Lines changed: 81 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,92 @@ When Claude is ready to stop:
1818
- Run the tests with `pytest`
1919

2020
Note: We defer `ruff format` and `ruff check` until Claude stops to avoid changing files while Claude is working. Changing files during editing would spoil Claude's edits and force it to reread files.
21+
2122
## Installation
2223

23-
```bash
24-
poetry add python-claude
25-
```
24+
### Option 1: Plugin Installation (Recommended)
25+
26+
Install as a Claude Code plugin for automatic hook configuration:
27+
28+
1. First, add this package to your project:
29+
```bash
30+
poetry add python-claude
31+
```
32+
33+
2. Install as a Claude Code plugin:
34+
```bash
35+
claude plugin install /path/to/python-claude
36+
```
2637

27-
## Usage
38+
3. Restart Claude Code to activate the hooks
2839

29-
This package provides hooks that can be used with Claude Code's hook system.
40+
The plugin automatically configures all necessary hooks - no manual settings.json configuration needed!
3041

31-
### Available Commands
42+
### Option 2: Manual Installation
43+
44+
If you prefer manual configuration:
45+
46+
1. Add to your project:
47+
```bash
48+
poetry add python-claude
49+
```
50+
51+
2. Add hooks to your Claude Code settings.json:
52+
```json
53+
{
54+
"hooks": {
55+
"SessionStart": [
56+
{
57+
"hooks": [
58+
{
59+
"type": "command",
60+
"command": "poetry run python-claude session start"
61+
},
62+
{
63+
"type": "command",
64+
"command": "poetry run python-claude git status"
65+
}
66+
]
67+
}
68+
],
69+
"Stop": [
70+
{
71+
"hooks": [
72+
{
73+
"type": "command",
74+
"command": "poetry run python-claude ruff format"
75+
},
76+
{
77+
"type": "command",
78+
"command": "poetry run python-claude ruff check"
79+
},
80+
{
81+
"type": "command",
82+
"command": "poetry run python-claude mypy"
83+
},
84+
{
85+
"type": "command",
86+
"command": "poetry run python-claude pytest"
87+
}
88+
]
89+
}
90+
],
91+
"PostToolUse": [
92+
{
93+
"matcher": "Write|Edit",
94+
"hooks": [
95+
{
96+
"type": "command",
97+
"command": "poetry run python-claude edited"
98+
}
99+
]
100+
}
101+
]
102+
}
103+
}
104+
```
105+
106+
## Available Commands
32107

33108
- `edited` - Tracks edited Python files for deferred processing (used in PostToolUse hook)
34109
- `git status` - Shows git status
@@ -38,64 +113,6 @@ This package provides hooks that can be used with Claude Code's hook system.
38113
- `ruff format` - Runs ruff format on collected files (used in Stop hook)
39114
- `session start` - Prints introductory message about automatic hooks
40115

41-
### Claude Code Settings
42-
43-
Add hooks to your Claude Code settings.json:
44-
45-
```json
46-
{
47-
"hooks": {
48-
"SessionStart": [
49-
{
50-
"hooks": [
51-
{
52-
"type": "command",
53-
"command": "poetry run python-claude session start"
54-
},
55-
{
56-
"type": "command",
57-
"command": "poetry run python-claude git status"
58-
}
59-
]
60-
}
61-
],
62-
"Stop": [
63-
{
64-
"hooks": [
65-
{
66-
"type": "command",
67-
"command": "poetry run python-claude ruff format"
68-
},
69-
{
70-
"type": "command",
71-
"command": "poetry run python-claude ruff check"
72-
},
73-
{
74-
"type": "command",
75-
"command": "poetry run python-claude mypy"
76-
},
77-
{
78-
"type": "command",
79-
"command": "poetry run python-claude pytest"
80-
}
81-
]
82-
}
83-
],
84-
"PostToolUse": [
85-
{
86-
"matcher": "Write|Edit",
87-
"hooks": [
88-
{
89-
"type": "command",
90-
"command": "poetry run python-claude edited"
91-
}
92-
]
93-
}
94-
]
95-
}
96-
}
97-
```
98-
99116
## Development
100117

101118
```bash

hooks/hooks.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"hooks": {
3+
"SessionStart": [
4+
{
5+
"hooks": [
6+
{
7+
"type": "command",
8+
"command": "poetry run python-claude session start"
9+
},
10+
{
11+
"type": "command",
12+
"command": "poetry run python-claude git status"
13+
}
14+
]
15+
}
16+
],
17+
"Stop": [
18+
{
19+
"hooks": [
20+
{
21+
"type": "command",
22+
"command": "poetry run python-claude ruff format"
23+
},
24+
{
25+
"type": "command",
26+
"command": "poetry run python-claude ruff check"
27+
},
28+
{
29+
"type": "command",
30+
"command": "poetry run python-claude mypy"
31+
},
32+
{
33+
"type": "command",
34+
"command": "poetry run python-claude pytest"
35+
}
36+
]
37+
}
38+
],
39+
"PostToolUse": [
40+
{
41+
"matcher": "Write|Edit",
42+
"hooks": [
43+
{
44+
"type": "command",
45+
"command": "poetry run python-claude edited"
46+
}
47+
]
48+
}
49+
]
50+
}
51+
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "python-claude"
3-
version = "0.3.2"
3+
version = "0.4.0"
44
description = "Python hooks for Claude Code"
55
authors = [{name = "CVector", email = "support@cvector.com"}]
66
readme = "README.md"

src/python_claude/hooks/mypy_hook.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def run(self) -> int:
5050
exit_code = result.returncode
5151
self.log(f"exit {exit_code}")
5252

53+
# Clean up tracking file on success
54+
if exit_code == 0:
55+
self.track_file.unlink(missing_ok=True)
56+
5357
# Map mypy exit code 1 (type errors) to exit code 2 for Claude Code correction
5458
if exit_code == 1:
5559
return 2

src/python_claude/hooks/pytest_hook.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ def run(self) -> int:
2929
)
3030

3131
exit_code = result.returncode
32+
self.log(f"exit {exit_code}")
33+
34+
# Clean up tracking file on success
35+
if exit_code == 0:
36+
self.track_file.unlink(missing_ok=True)
37+
3238
# Transform pytest exit code 1 (test failures) to exit code 2
3339
# for Claude Code to properly understand test failures
3440
if exit_code == 1:
35-
exit_code = 2
36-
self.log(f"exit {exit_code}")
41+
return 2
3742
return exit_code

0 commit comments

Comments
 (0)