langchain-ai/deepagents · warning · SystemExit

Error: Not in a project directory.

Error message

Error: Not in a project directory.

What it means

Raised by the /skills create command when --project is requested but the current environment has no project root (no .git directory at the project root). Project-level skills require a git repo to anchor the skills directory, so the command exits with SystemExit(1).

Source

Thrown at libs/code/deepagents_code/skills/commands.py:448

        console.print(
            "[dim]Per Agent Skills spec: names must be lowercase alphanumeric "
            "with hyphens only.\n"
            "Examples: web-research, code-review, data-analysis[/dim]",
            style=theme.MUTED,
        )
        raise SystemExit(1)

    # Determine target directory
    credentials = Credentials.from_environment()
    if project:
        if not credentials.project_root:
            console.print("[bold red]Error:[/bold red] Not in a project directory.")
            console.print(
                "[dim]Project skills require a .git directory "
                "in the project root.[/dim]",
                style=theme.MUTED,
            )
            raise SystemExit(1)
        skills_dir = ensure_project_skills_dir(credentials.project_root)
        if skills_dir is None:
            console.print(
                "[bold red]Error:[/bold red] Could not create project skills directory."
            )
            raise SystemExit(1)
    else:
        skills_dir = ensure_user_skills_dir(agent)

    skill_dir = skills_dir / skill_name

    # Validate the resolved path is within skills_dir
    is_valid_path, path_error = _validate_skill_path(skill_dir, skills_dir)
    if not is_valid_path:
        console.print(f"[bold red]Error:[/bold red] {path_error}")
        raise SystemExit(1)

    if skill_dir.exists():

View on GitHub (pinned to a1af029e6e)

Solutions

  1. cd into the git repository root (or a directory inside it) before running the command
  2. Run git init if the directory should be a project
  3. Drop the --project flag to create the skill in the user-level skills directory instead
  4. Verify detection: ensure a .git directory exists at the expected project root

Example fix

// before
$ cd ~/scratch && dcode skills create code-review --project
Error: Not in a project directory.

// after
$ cd ~/my-repo && dcode skills create code-review --project  # has .git
Defensive patterns

Strategy: fallback

Validate before calling

from pathlib import Path
if project_flag and not Path.cwd().joinpath(".git").exists() and not find_project_root(Path.cwd()):
    print("Not in a project; creating a user-level skill instead.")
    project_flag = False

Try / catch

try:
    run_skills_create(name=name, project=True)
except SystemExit:
    run_skills_create(name=name, project=False)  # fall back to user skills dir

Prevention

When it happens

Trigger: Running skills create --project outside a git repository, or in a repo whose project root cannot be located by Credentials.from_environment() / project_root is falsy.

Common situations: Running the command in a home directory or non-repo folder; being in a subdirectory of a repo where detection fails; invoking in CI from the wrong checkout directory; a repo initialized without .git (worktree/downloaded archive).

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/44e5ff00bbc693d8. Report an issue: GitHub.