Skip to content

Back2Basics/claude_context_reduction_hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

claude context reduction hooks

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.

important caveat at the bottom of this readme.

When working with non-modified CSS files and html files you can do:

python .claude/hooks/get_css_class.py h1 navbar yet-another-class

which 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;
        }

When working with python classes in files you can do:

python .claude/hooks/get_python_class.py MyClassName

the 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

Important Caveat

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) ************

Time Savers

  • CRITICAL: Always find python classes using the .claude/hooks/get_python_class hook
    • 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.py hook
    • 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

About

Claude does 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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages