Skip to main content

Enforce file size constraints

Project description

loq

CI codecov PyPI Crates.io License: MIT

An electric fence for LLMs (and humans too).

Why file size matters

Big files mean more tokens. More tokens mean:

  • Slower responses - LLMs take longer to process what they don't need
  • Higher costs - you pay per token
  • Context rot - large files become dumping grounds that overwhelm both LLMs and humans

loq stops the sprawl before it starts.

Why loq?

LLMs are great at generating code, but sometimes they go off the rails. You can tell an LLM what to do, but the only way to guarantee it listens is with feedback loops and hard constraints. loq provides that constraint: a fast, dead-simple way to enforce file size limits.

Linters like Ruff and ESLint check correctness. loq checks size. It does one thing: enforce line counts (wc -l style). No parsers, no plugins, language agnostic. One tool for your entire polyglot monorepo.

Getting started

Installation

# With uv (recommended)
uv tool install loq

# With pip
pip install loq

# With cargo
cargo install loq

Usage

loq                                        # Check current directory (zero-config, 500 line default)
loq check src/ lib/                        # Check specific paths
git diff --name-only | loq check -         # Check files from stdin

Pre-commit

repos:
  - repo: https://github.com/jakekaplan/loq
    rev: v0.1.0a4
    hooks:
      - id: loq

LLM-friendly output

Output is designed to be token-efficient:

✖  1_427 > 500   src/components/Dashboard.tsx
✖    892 > 500   src/utils/helpers.py
2 violations (14ms)

Use loq -v for additional context:

✖  1_427 > 500   src/components/Dashboard.tsx
                  └─ rule: max-lines=500 (match: **/*.tsx)

Configuration

loq works zero-config. Run loq init to customize:

default_max_lines = 500       # files not matching any rule
respect_gitignore = true      # skip .gitignore'd files
exclude = [".git/**", "**/generated/**", "*.lock"]

[[rules]]                     # last match wins, ** matches any path
path = "**/*.tsx"
max_lines = 300

[[rules]]
path = "tests/**"
max_lines = 600

Custom guidance

Add fix_guidance to display instructions when violations occur:

default_max_lines = 500
fix_guidance = """
Split this file following our conventions:
- Extract helper functions to src/utils/
- Move types to src/types/
- Keep components under 300 lines
"""

Output:

✖    892 > 500   src/utils/helpers.py
1 violation (8ms)

Split this file following our conventions:
- Extract helper functions to src/utils/
- Move types to src/types/
- Keep components under 300 lines

This is especially useful when piping to LLMs—include project-specific refactoring patterns and the LLM gets actionable context alongside the violations.

Baseline

Have a codebase with existing large files? Baseline them:

loq init       # Create loq.toml first
loq baseline   # Add rules for files over the limit

Run loq baseline periodically to ratchet down. It automatically:

  • Adds rules for new violations
  • Updates rules when files shrink (tightens the limit)
  • Removes rules when files drop below the threshold

Files that grow beyond their baseline are left unchanged by default—increasing limits defeats the purpose of the fence. If you must, use --allow-growth:

loq baseline --allow-growth   # Also update limits for files that grew

Use --threshold to override the default limit:

loq baseline --threshold 300

Contributing

Contributions are welcome! See CONTRIBUTING.md for development setup and guidelines.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loq-0.1.0a4.tar.gz (55.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

loq-0.1.0a4-py3-none-win_amd64.whl (1.3 MB view details)

Uploaded Python 3Windows x86-64

loq-0.1.0a4-py3-none-musllinux_1_2_x86_64.whl (1.4 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

loq-0.1.0a4-py3-none-musllinux_1_2_aarch64.whl (1.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

loq-0.1.0a4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

loq-0.1.0a4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

loq-0.1.0a4-py3-none-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

loq-0.1.0a4-py3-none-macosx_10_12_x86_64.whl (1.3 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file loq-0.1.0a4.tar.gz.

File metadata

  • Download URL: loq-0.1.0a4.tar.gz
  • Upload date:
  • Size: 55.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 09b5243011228ad4a24f143c1d8c80221c8d0786b977405e1ab424aaad00127d
MD5 1d0d4d9d51b7a760b6801a10a0d2d8c4
BLAKE2b-256 e07a727f5a1bfb4709ad9818aabf612dc4309aa4e709e2ecd469bbeb4e5038ed

See more details on using hashes here.

File details

Details for the file loq-0.1.0a4-py3-none-win_amd64.whl.

File metadata

  • Download URL: loq-0.1.0a4-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ef5f3e4cf00d0238d6eaa8ced4f14c6d9c93095274bc0941fade06ca2a9f4564
MD5 11fc3f95e777073dcc5cdff387ede3fd
BLAKE2b-256 e1e7592b6e418a44212d8f645bdda4d225a6ce4f2037f13a4af9fd518ef8f2c3

See more details on using hashes here.

File details

Details for the file loq-0.1.0a4-py3-none-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: loq-0.1.0a4-py3-none-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 56943e7697ed2b7c2bc11cab689cc726acaf91bc244f7146450c098571d06b40
MD5 bfad00b570cde4537afc6e90ca7e4c61
BLAKE2b-256 56c19ca265d6f6a5965142a560b5dec30ddd9f371257bef9f62986d1e0a74c0e

See more details on using hashes here.

File details

Details for the file loq-0.1.0a4-py3-none-musllinux_1_2_aarch64.whl.

File metadata

  • Download URL: loq-0.1.0a4-py3-none-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a285a16c9015142c8a61596337f4f1ef819ccf8099a3db70a46e0f1ef0e44f98
MD5 4d55994cc690938b9ae8e03e3d6899ef
BLAKE2b-256 43832b208e0380a530b8e0995a56d8585fc238107edaf97f60cd379cbdec3f9b

See more details on using hashes here.

File details

Details for the file loq-0.1.0a4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: loq-0.1.0a4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55f09685260325a2cd5160e60911a4fc99c61fabb1f1b9525d840cea3085063b
MD5 a1b877ca09726fd450c1e2269d32a019
BLAKE2b-256 9322234be3b57dfabb309764ad7bad6ae94d58145bfcdfafeb9b5d2b5582c11e

See more details on using hashes here.

File details

Details for the file loq-0.1.0a4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: loq-0.1.0a4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 020abe67a8297e91b2ea60f6182ba98718f23ea6323c7f91c8b3a600df9cc8c4
MD5 e1f9719c44b00ca66544b86d3350f14c
BLAKE2b-256 b45095920605aba320de36e133203133ddb384a30dc6bc1984c05d94f5523a3e

See more details on using hashes here.

File details

Details for the file loq-0.1.0a4-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: loq-0.1.0a4-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 363ffc03f1d62585168ebcd116ee8aa51c82b4c061adf464ae4a32d91ba7ab75
MD5 5ebfc3a7be0fc19de730ad92abce139a
BLAKE2b-256 054ebf3500dff265431931c944242a26d4d2bbd8b6ed209820076af4ec2d6d7c

See more details on using hashes here.

File details

Details for the file loq-0.1.0a4-py3-none-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: loq-0.1.0a4-py3-none-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for loq-0.1.0a4-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0423d857c1b8470d478c6720e6e9fd568218f9313f970dd13d49d51043d4c83c
MD5 6c3861eb98bdae77dbcff18c2f2c2d0f
BLAKE2b-256 be39c37ef29ddebcd087f70fc04e29da35f7f9a26cb708c6c1f55b87db2bf8ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page