I manage my Git repos with gitjoin together with other small tools such as firstupdotenv and grrep, each doing one thing very well. What I missed was a simple way to keep contextual information per repository and branch. The tools I've seen that do this look like sledgehammers for my nails, so I wrote mycontext.
In my setup, mymonorepo/bep/gocode/libs is a gitjoin virtual monorepo with Git repos such as debounce, gitmap and lazycache. The context for the mybranch branch in debounce lives in libs/_mycontext/debounce/mybranch/.
What goes into a context is up to you. Some examples:
- The current Claude Code session ID, to resume the session when picking up work on a branch (see below).
- Reports from security researchers describing an issue to be fixed.
- Notes and design documents for a feature.
mycontext does not depend on gitjoin; it works with any Git repository. All commands are run from inside the repository and operate on that repository only.
- The context for a branch lives in
<repo>/../_mycontext/<repo dir name>/<branch>/. - Branch names with slashes nest as directories, e.g.
feature/foolives in_mycontext/myrepo/feature/foo/. - A context directory is marked by an empty
.mycontext-branchfile. This is howmycontexttells a context apart from a sub directory inside one. _mycontextis meant to be committed (e.g. into the parentgitjoinrepository). Files that only make sense on one machine go into the context's.local/sub directory, which is ignored by_mycontext/.gitignore, created bymycontextthe first time it creates a context.mycontextnever commits anything, and does not touch your Git branches.
go install github.com/bep/mycontext@latestmycontext path [--local] # Print the context directory for the current branch, creating it if needed.
mycontext ls # List this repository's contexts; contexts without a local branch are marked (gone).
mycontext rm [branch] # Remove a context (defaults to the current branch).
mycontext mv <old> <new> # Rename a context, e.g. after renaming the branch.
mycontext prune [--dry-run] # Remove contexts for local branches that no longer exist.mycontext path is the integration point for other tools, e.g. cd $(mycontext path).
Store the session ID for the current branch with a SessionStart hook in .claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "jq -r .session_id > \"$(mycontext path --local)/claude-session\""
}
]
}
]
}
}And resume it with:
claude --resume $(cat $(mycontext path --local)/claude-session)