# tinker_cookbook.utils.code_state ### [**tinker_cookbook.utils.code_state**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/utils/code_state.py#L11)(*modules*) Capture the current code state for one or more Python modules as a diff string. For each module this function locates its filesystem path, discovers the enclosing Git repository, records the current commit hash (HEAD), and includes combined staged+unstaged changes (`git diff HEAD`) for the entire repository. The output is suitable for storage alongside experiment metadata to reproduce the exact code state later. **Parameters:** - [**modules**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/utils/code_state.py#L11) (*Sequence[str | ModuleType]*) – Module import names (e.g. `"tinker_cookbook.rl"`) or already-imported module objects. **Returns:** *str* – Concatenated sections, one per repository, each beginning with a header of the form `### repo: @ ` followed by the repo-wide diff. Modules not in a Git repository get a short note instead. ```python state = code_state(["tinker_cookbook", "tinker"]) with open("code.diff", "w") as f: f.write(state) ```