{"id":20739438,"url":"https://github.com/egormkn/run-in-subdirectory","last_synced_at":"2026-04-17T04:34:09.623Z","repository":{"id":224317351,"uuid":"762991708","full_name":"egormkn/run-in-subdirectory","owner":"egormkn","description":"📁 A command-line utility for running commands in subdirectories (e.g. in a monorepo) with a set of pre-commit hooks","archived":false,"fork":false,"pushed_at":"2024-04-02T18:10:29.000Z","size":110,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T09:23:38.302Z","etag":null,"topics":["git","git-hooks","hooks","monorepo","pre-commit","pre-commit-hook","pre-commit-hooks","subdirectory","utilities"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/egormkn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-25T09:09:27.000Z","updated_at":"2025-07-05T16:35:21.000Z","dependencies_parsed_at":"2024-02-25T09:32:54.723Z","dependency_job_id":"7ccde599-ac4e-409f-b04f-190306817c36","html_url":"https://github.com/egormkn/run-in-subdirectory","commit_stats":null,"previous_names":["egormkn/run-in-subdirectory","egormkn/pre-commit-subdirectory"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/egormkn/run-in-subdirectory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egormkn%2Frun-in-subdirectory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egormkn%2Frun-in-subdirectory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egormkn%2Frun-in-subdirectory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egormkn%2Frun-in-subdirectory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egormkn","download_url":"https://codeload.github.com/egormkn/run-in-subdirectory/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egormkn%2Frun-in-subdirectory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31915341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","git-hooks","hooks","monorepo","pre-commit","pre-commit-hook","pre-commit-hooks","subdirectory","utilities"],"created_at":"2024-11-17T06:24:56.330Z","updated_at":"2026-04-17T04:34:09.607Z","avatar_url":"https://github.com/egormkn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://img.shields.io/github/actions/workflow/status/egormkn/run-in-subdirectory/workflow.yml)](https://github.com/egormkn/run-in-subdirectory/actions/workflows/workflow.yml)\n[![Coverage](https://img.shields.io/codecov/c/github/egormkn/run-in-subdirectory?token=4GI2X9GPTC)](https://codecov.io/gh/egormkn/run-in-subdirectory)\n[![PyPI - Version](https://img.shields.io/pypi/v/run-in-subdirectory.svg)](https://pypi.org/project/run-in-subdirectory/)\n[![PyPI - License](https://img.shields.io/pypi/l/run-in-subdirectory)](https://github.com/egormkn/run-in-subdirectory/blob/main/LICENSE)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/run-in-subdirectory)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat\u0026labelColor=ef8336)](https://github.com/PyCQA/isort)\n[![Linting: ruff](https://img.shields.io/badge/linting-ruff-261230)](https://github.com/astral-sh/ruff)\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"100\" alt=\"run pre-commit in subdirectory\" src=\"https://raw.githubusercontent.com/egormkn/run-in-subdirectory/main/assets/logo.png\"\u003e\n\n  # run-in-subdirectory\n\n  A command-line utility for running commands in subdirectories (e.g. in a monorepo) with a set of pre-commit hooks\n\n\u003c/div\u003e\n\n\n## Usage\n\n### As a pre-commit hook\n\n- Use [`run-in-subdirectory`](.pre-commit-hooks.yaml) hook to run command in a subdirectory passed as the first argument.\n  \n  In this example, pre-commit will run the command `npx --no -- prettier -w -u` in `client` subdirectory, and the command `poetry run black` in `server` subdirectory:\n\n  ```yaml\n  repos:\n    - repo: https://github.com/egormkn/run-in-subdirectory\n      rev: 1.0.1\n      hooks:\n        - id: run-in-subdirectory\n          alias: prettier\n          name: Format client code with Prettier\n          args: [\"client\", \"npx --no -- prettier -w -u\"]\n          types: [ text ]\n          files: ^client/\n        - id: run-in-subdirectory\n          alias: black\n          name: Format server code with Black\n          args: [\"server\", \"poetry run black\"]\n          types: [ python ]\n          files: ^client/\n  ```\n\n- Use one of [`run-in-...-level-subdirectory`](.pre-commit-hooks.yaml) hooks to automatically extract `first`, `second` or `third`-level subdirectory from the last file path, that was passed to the hook by pre-commit.\n  \n  Note that you should set `files`, `types` and/or `exclude` properties so that the hook only runs for files in that subdirectory.\n\n  ```yaml\n  repos:\n    - repo: https://github.com/egormkn/run-in-subdirectory\n      rev: 1.0.1\n      hooks:\n        - id: run-in-first-level-subdirectory\n          alias: prettier\n          name: Format client code with Prettier\n          args: [\"npx --no -- prettier -w -u\"]\n          types: [ text ]\n          files: ^client/\n        - id: run-in-first-level-subdirectory\n          alias: black\n          name: Format server code with Black\n          args: [\"poetry run black\"]\n          types: [ python ]\n          files: ^client/\n  ```\n  \n- If the available hooks are not enough for your task, use a custom Python hook and execute `run-in-subdirectory` as a command-line utility). Also, please [open an issue](https://github.com/egormkn/run-in-subdirectory/issues) to report such cases.\n\n  ```yaml\n  repos:\n    - repo: local\n      hooks:\n        - id: prettier\n          name: Format client code with Prettier\n          language: python\n          additional_dependencies:\n            - \"run-in-subdirectory==1.0.1\"\n          entry: run-in-subdirectory -d client npx --no -- prettier -w -u\n          types: [ text ]\n          files: ^client/\n  ```\n\n### As a command-line utility\n\n`run-in-subdirectory` can also be used as a command-line utility:\n\n```bash\npip install run-in-subdirectory\n```\n\n```\nusage: run-in-subdirectory [-h] [-v] (-l LEVEL | -d DIRECTORY) executable [args ...]\n\nRuns the command in a subdirectory and fixes paths in arguments.\n\npositional arguments:\n  executable            Executable to run\n  args                  Sequence of program arguments\n\noptions:\n  -h, --help            show this help message and exit\n  -v, --verbose         Print information about a command to be called\n  -l LEVEL, --level LEVEL\n                        Subdirectory level (0 for top-level directory)\n  -d DIRECTORY, --directory DIRECTORY\n                        Subdirectory within which the subprocess will be executed\n\nexample:\n  When this program is executed with the following command:\n    run-in-subdirectory -d client npx --no prettier client/src/index.ts\n  Then the command will be executed:\n    npx --no prettier src/index.ts\n  with the current working directory set to `client`.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegormkn%2Frun-in-subdirectory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegormkn%2Frun-in-subdirectory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegormkn%2Frun-in-subdirectory/lists"}