MoonshotAI / MoonshotAI/kimi-cli

feat(subagents): complete work_dir override for Shell cwd and AGENTS.md context

Open
#1,936 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

Background

PR #1933 added work_dir override for subagents, fixing #1931. Two related concerns were identified during code review but intentionally deferred to keep the initial PR scope manageable.

Issue 1: Shell tool uses session.work_dir instead of overridden work_dir

The Shell tool resolves its cwd from session.work_dir, which is never overridden when work_dir is set on a subagent. This means git and build commands run by subagents with a custom work_dir may execute in the parent's working directory instead of the intended one.

  • src/kimi_cli/tools/shell/__init__.py uses self._runtime.session.work_dir for background runs
  • Foreground runs inherit the process cwd set from session.work_dir in src/kimi_cli/app.py
  • Only builtin_args.KIMI_WORK_DIR is overridden, not the session's work_dir

Why deferred: Changing Shell cwd resolution affects all agents and is out of scope for the initial work_dir feature. The parameter currently targets file tools (Read, Write, Glob) and system prompt context.

Issue 2: KIMI_AGENTS_MD not reloaded for overridden work_dir

When work_dir_override is set, KIMI_AGENTS_MD is not refreshed from the new directory. The subagent retains the parent's AGENTS.md content in its system prompt.

  • Reloading AGENTS.md requires _find_project_root detection and filesystem scanning
  • The subagent can discover AGENTS.md through its own tool usage
  • Only KIMI_WORK_DIR_LS (directory listing) is cheap to refresh and provides immediate value

Why deferred: Cost/benefit tradeoff — directory listing refresh is cheap and high-value; AGENTS.md reload adds complexity for marginal gain since the subagent discovers it naturally.

Scope

  • Investigate whether session.work_dir should also be overridden (or Shell should read from builtin_args.KIMI_WORK_DIR)
  • Add optional AGENTS.md reload in build_builtin_instance when work_dir_override is set
  • Add tests for Shell cwd behavior with overridden work_dir

Related: #1931, #1933

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/kimi_cli/tools/shell/init.py and src/kimi_cli/app.py to trace foreground and background cwd handling, then locate build_builtin_instance and the existing work_dir tests. Verify behavior for a subagent override, decide how AGENTS.md should be refreshed, and add tests covering the intended Shell cwd and context.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.