LLM's do better with less context. Reading in full files when you only need 10 lines is annoying to work with and costly. These hooks make the context shorter. So far there is a program for css files and python files.
python .claude/hooks/get_css_class.py h1 navbar yet-another-classwhich get all three of these classes and selectors returning the output with the file that it found in lines that are affected, and whether or not it was in an HTML file style tags
# mockups/3.html lines:[22:29] (in <style> tag)
h1 {
font-size: 24px;
font-weight: bold;
margin: 16px 0;
border-bottom: 2px solid #000000;
padding-bottom: 8px;
}
python .claude/hooks/get_python_class.py MyClassNamethe output is
# my_python_file.py lines:[500:505]
class MyClassName(otherclass) --> int:
def fn(a:int, b:int)--> int:
... blah
... blah
... blah
return 10
Claude doesn't use the hooks alone. it will use the hook and THEN READ THE FILE, which is infuriating so... in order for it to just use the hooks info you need to add info to claude.md to tell it that.
I added: ******************** Claude.md (append to the end) ************
- CRITICAL: Always find python classes using the
.claude/hooks/get_python_classhook- The hook returns the COMPLETE class definition - DO NOT follow up with Read tool
- The hook output includes: file path, line numbers, full class code, methods, and documentation
- NEVER use Read tool after get_python_class - it's redundant and wasteful
- Trust the hook output - it gives you everything you need
- CRITICAL: Find CSS classes using the
.claude/hooks/get_css_class.pyhook- The hook returns the COMPLETE CSS definitions and locations
- DO NOT follow up with Read, Grep, or Bash commands
- Trust the hook output - it already searched all files for you