MoonshotAI / MoonshotAI/kimi-cli
feat(subagents): complete work_dir override for Shell cwd and AGENTS.md context
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__.pyusesself._runtime.session.work_dirfor background runs- Foreground runs inherit the process cwd set from
session.work_dirinsrc/kimi_cli/app.py - Only
builtin_args.KIMI_WORK_DIRis overridden, not the session'swork_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_rootdetection 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_dirshould also be overridden (or Shell should read frombuiltin_args.KIMI_WORK_DIR) - Add optional AGENTS.md reload in
build_builtin_instancewhenwork_dir_overrideis set - Add tests for Shell cwd behavior with overridden
work_dir
Related: #1931, #1933
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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